/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5599.3.5 by John Arbash Meinel
Merge bzr.dev 5602 to, yet again, resolve a NEWS/bzr-2.3.txt conflict
1
# Copyright (C) 2006, 2009, 2011 Canonical Ltd
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
16
6379.6.7 by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear.
17
"""A generator which creates a python script from the current tree info"""
18
6379.6.3 by Jelmer Vernooij
Use absolute_import.
19
from __future__ import absolute_import
20
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
21
import pprint
22
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
23
from breezy import errors
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
24
from breezy.revision import (
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
25
    NULL_REVISION,
26
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
27
from breezy.version_info_formats import (
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
28
    create_date_str,
29
    VersionInfoBuilder,
30
    )
31
32
33
# Header and footer for the python format
34
_py_version_header = '''#!/usr/bin/env python
35
"""This file is automatically generated by generate_version_info
36
It uses the current working tree to determine the revision.
37
So don't edit it. :)
38
"""
39
40
'''
41
42
43
_py_version_footer = '''
44
if __name__ == '__main__':
7045.1.15 by Jelmer Vernooij
fix version info tests
45
    print('revision: %(revno)s' % version_info)
46
    print('nick: %(branch_nick)s' % version_info)
47
    print('revision id: %(revision_id)s' % version_info)
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
48
'''
49
50
51
class PythonVersionInfoBuilder(VersionInfoBuilder):
52
    """Create a version file which is a python source module."""
53
54
    def generate(self, to_file):
7078.3.1 by Jelmer Vernooij
Fix formatting.
55
        info = {'build_date': create_date_str(),
56
                'revno': None,
57
                'revision_id': None,
58
                'branch_nick': self._branch.nick,
59
                'clean': None,
60
                'date': None
7143.15.2 by Jelmer Vernooij
Run autopep8.
61
                }
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
62
        revisions = []
63
64
        revision_id = self._get_revision_id()
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
65
        if revision_id == NULL_REVISION:
5967.11.2 by Benoît Pierre
Update version-info formats to support dotted revnos.
66
            info['revno'] = '0'
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
67
        else:
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
68
            try:
69
                info['revno'] = self._get_revno_str(revision_id)
70
            except errors.GhostRevisionsHaveNoRevno:
71
                pass
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
72
            info['revision_id'] = revision_id
73
            rev = self._branch.repository.get_revision(revision_id)
74
            info['date'] = create_date_str(rev.timestamp, rev.timezone)
75
76
        if self._check or self._include_file_revs:
77
            self._extract_file_revisions()
78
79
        if self._check:
80
            if self._clean:
81
                info['clean'] = True
82
            else:
83
                info['clean'] = False
84
85
        info_str = pprint.pformat(info)
86
        to_file.write(_py_version_header)
87
        to_file.write('version_info = ')
88
        to_file.write(info_str)
89
        to_file.write('\n\n')
90
91
        if self._include_history:
6165.4.30 by Jelmer Vernooij
Fix remaining tests.
92
            history = list(self._iter_revision_history())
93
            revision_str = pprint.pformat(history)
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
94
            to_file.write('revisions = ')
95
            to_file.write(revision_str)
96
            to_file.write('\n\n')
97
        else:
98
            to_file.write('revisions = {}\n\n')
99
100
        if self._include_file_revs:
101
            file_rev_str = pprint.pformat(self._file_revisions)
102
            to_file.write('file_revisions = ')
103
            to_file.write(file_rev_str)
104
            to_file.write('\n\n')
105
        else:
106
            to_file.write('file_revisions = {}\n\n')
107
108
        to_file.write(_py_version_footer)