1
# Copyright (C) 2006 Canonical Ltd
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.
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.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""A generator which creates a python script from the current tree info"""
21
from bzrlib.version_info_formats import (
27
# Header and footer for the python format
28
_py_version_header = '''#!/usr/bin/env python
29
"""This file is automatically generated by generate_version_info
30
It uses the current working tree to determine the revision.
37
_py_version_footer = '''
39
if __name__ == '__main__':
40
print 'revision: %(revno)d' % version_info
41
print 'nick: %(branch_nick)s' % version_info
42
print 'revision id: %(revision_id)s' % version_info
46
class PythonVersionInfoBuilder(VersionInfoBuilder):
47
"""Create a version file which is a python source module."""
49
def generate(self, to_file):
50
info = {'build_date':create_date_str()
53
, 'branch_nick':self._branch.nick
59
revision_id = self._get_revision_id()
60
if revision_id is None:
63
info['revno'] = self._branch.revision_id_to_revno(revision_id)
64
info['revision_id'] = revision_id
65
rev = self._branch.repository.get_revision(revision_id)
66
info['date'] = create_date_str(rev.timestamp, rev.timezone)
68
if self._check or self._include_file_revs:
69
self._extract_file_revisions()
77
info_str = pprint.pformat(info)
78
to_file.write(_py_version_header)
79
to_file.write('version_info = ')
80
to_file.write(info_str)
83
if self._include_history:
84
self._extract_revision_history()
85
revision_str = pprint.pformat(self._revision_history_info)
86
to_file.write('revisions = ')
87
to_file.write(revision_str)
90
to_file.write('revisions = {}\n\n')
92
if self._include_file_revs:
93
file_rev_str = pprint.pformat(self._file_revisions)
94
to_file.write('file_revisions = ')
95
to_file.write(file_rev_str)
98
to_file.write('file_revisions = {}\n\n')
100
to_file.write(_py_version_footer)