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