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 |
||
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
19 |
import pprint |
20 |
||
6968.1.1
by Jelmer Vernooij
Support 'bzr version-info' in horizon branches. |
21 |
from breezy import errors |
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
22 |
from breezy.revision import ( |
4250.1.1
by Jelmer Vernooij
Fix version-info in empty branches. |
23 |
NULL_REVISION, |
24 |
)
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
25 |
from breezy.version_info_formats import ( |
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
26 |
create_date_str, |
27 |
VersionInfoBuilder, |
|
28 |
)
|
|
29 |
||
30 |
||
31 |
# Header and footer for the python format
|
|
7476.2.1
by Jelmer Vernooij
Default to running Python 3. |
32 |
_py_version_header = '''#!/usr/bin/env python3 |
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
33 |
"""This file is automatically generated by generate_version_info
|
34 |
It uses the current working tree to determine the revision.
|
|
35 |
So don't edit it. :)
|
|
36 |
"""
|
|
37 |
||
38 |
'''
|
|
39 |
||
40 |
||
41 |
_py_version_footer = ''' |
|
42 |
if __name__ == '__main__':
|
|
7045.1.15
by Jelmer Vernooij
fix version info tests |
43 |
print('revision: %(revno)s' % version_info) |
44 |
print('nick: %(branch_nick)s' % version_info) |
|
45 |
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. |
46 |
'''
|
47 |
||
48 |
||
49 |
class PythonVersionInfoBuilder(VersionInfoBuilder): |
|
50 |
"""Create a version file which is a python source module.""" |
|
51 |
||
52 |
def generate(self, to_file): |
|
7078.3.1
by Jelmer Vernooij
Fix formatting. |
53 |
info = {'build_date': create_date_str(), |
54 |
'revno': None, |
|
55 |
'revision_id': None, |
|
56 |
'branch_nick': self._branch.nick, |
|
57 |
'clean': None, |
|
58 |
'date': None |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
59 |
}
|
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
60 |
revisions = [] |
61 |
||
62 |
revision_id = self._get_revision_id() |
|
4250.1.1
by Jelmer Vernooij
Fix version-info in empty branches. |
63 |
if revision_id == NULL_REVISION: |
5967.11.2
by Benoît Pierre
Update version-info formats to support dotted revnos. |
64 |
info['revno'] = '0' |
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
65 |
else: |
6968.1.1
by Jelmer Vernooij
Support 'bzr version-info' in horizon branches. |
66 |
try: |
67 |
info['revno'] = self._get_revno_str(revision_id) |
|
68 |
except errors.GhostRevisionsHaveNoRevno: |
|
69 |
pass
|
|
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
70 |
info['revision_id'] = revision_id |
71 |
rev = self._branch.repository.get_revision(revision_id) |
|
72 |
info['date'] = create_date_str(rev.timestamp, rev.timezone) |
|
73 |
||
74 |
if self._check or self._include_file_revs: |
|
75 |
self._extract_file_revisions() |
|
76 |
||
77 |
if self._check: |
|
78 |
if self._clean: |
|
79 |
info['clean'] = True |
|
80 |
else: |
|
81 |
info['clean'] = False |
|
82 |
||
83 |
info_str = pprint.pformat(info) |
|
84 |
to_file.write(_py_version_header) |
|
85 |
to_file.write('version_info = ') |
|
86 |
to_file.write(info_str) |
|
87 |
to_file.write('\n\n') |
|
88 |
||
89 |
if self._include_history: |
|
6165.4.30
by Jelmer Vernooij
Fix remaining tests. |
90 |
history = list(self._iter_revision_history()) |
91 |
revision_str = pprint.pformat(history) |
|
0.8.21
by John Arbash Meinel
Splitting up the version info code into a lazy factory style. |
92 |
to_file.write('revisions = ') |
93 |
to_file.write(revision_str) |
|
94 |
to_file.write('\n\n') |
|
95 |
else: |
|
96 |
to_file.write('revisions = {}\n\n') |
|
97 |
||
98 |
if self._include_file_revs: |
|
99 |
file_rev_str = pprint.pformat(self._file_revisions) |
|
100 |
to_file.write('file_revisions = ') |
|
101 |
to_file.write(file_rev_str) |
|
102 |
to_file.write('\n\n') |
|
103 |
else: |
|
104 |
to_file.write('file_revisions = {}\n\n') |
|
105 |
||
106 |
to_file.write(_py_version_footer) |