2
# -*- encoding: utf-8 -*-
3
# Copyright (C) 2007 Guillermo Gonzalez
5
# The code taken from bzrlib is under: Copyright (C) 2005, 2006, 2007 Canonical Ltd
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24
# This code is a modified copy from bzrlib.version (see there for copyrights and licensing)
26
"""modified (and refactored) from bzrlib.version to generate xml output"""
36
from bzrlib.version import _get_bzr_source_tree
37
from bzrlib.xml_serializer import _escape_cdata
39
def show_version_xml(show_config=True, show_copyright=True, to_file=None):
42
to_file.write(u'<version>')
43
_show_bazaar_version(to_file=to_file)
44
_show_python_version(to_file=to_file)
46
to_file.write(u'</version>')
48
def _show_python_version(to_file):
49
to_file.write(u'<python>')
50
# show path to python interpreter
51
# (bzr.exe use python interpreter from pythonXY.dll
52
# but sys.executable point to bzr.exe itself)
53
if not hasattr(sys, u'frozen'): # check for bzr.exe
55
to_file.write(u'<executable>%s</executable>' % sys.executable)
58
basedir = os.path.dirname(sys.executable)
59
python_dll = u'python%d%d.dll' % sys.version_info[:2]
60
to_file.write(u'<dll>%s</dll>' % os.path.join(basedir, python_dll))
61
# and now version of python interpreter
62
to_file.write(u'<version>%s</version>' % '.'.join(map(str, sys.version_info)))
63
to_file.write(u'<standard_library>%s</standard_library>' % os.path.dirname(os.__file__))
64
to_file.write(u'</python>')
66
def _show_bazaar_version(show_config=True, show_copyright=True, to_file=None):
67
to_file.write('<bazaar>')
68
to_file.write('<version>%s</version>' % bzrlib.__version__)
69
# is bzrlib itself in a branch?
70
_show_source_tree(to_file)
71
to_file.write('<bzrlib>%s</bzrlib>' % _get_bzrlib_path())
73
_show_bzr_config(to_file)
75
to_file.write('<copyright>')
76
_show_copyright(to_file)
77
to_file.write('</copyright>')
78
to_file.write('</bazaar>')
80
def _get_bzrlib_path():
81
if len(bzrlib.__path__) > 1:
82
# print repr, which is a good enough way of making it clear it's
83
# more than one element (eg ['/foo/bar', '/foo/bzr'])
84
return repr(bzrlib.__path__)
86
return bzrlib.__path__[0]
89
def _show_source_tree(to_file):
90
src_tree = _get_bzr_source_tree()
92
src_revision_id = src_tree.last_revision()
93
revno = src_tree.branch.revision_id_to_revno(src_revision_id)
94
to_file.write(u'<source_tree>')
95
to_file.write(u'<checkout>%s</checkout>' % src_tree.basedir)
96
to_file.write(u'<revision>%s</revision>' % revno)
97
to_file.write(u'<revid>%s</revid>' % src_revision_id)
98
to_file.write(u'<branch_nick>%s</branch_nick>' % _escape_cdata(src_tree.branch.nick))
99
to_file.write(u'</source_tree>')
101
def _show_bzr_config(to_file):
102
config_dir = os.path.normpath(config.config_dir()) # use native slashes
103
if not isinstance(config_dir, unicode):
104
config_dir = config_dir.decode(bzrlib.user_encoding)
105
bzr_log_filename = trace._bzr_log_filename
106
if not isinstance(bzr_log_filename, unicode):
107
bzr_log_filename = trace._bzr_log_filename.decode(bzrlib.user_encoding)
108
to_file.write('<configuration>%s</configuration>' % config_dir)
109
to_file.write('<log_file>%s</log_file>' % bzr_log_filename)
111
def _show_copyright(to_file):
112
to_file.write(bzrlib.__copyright__)
113
to_file.write("http://bazaar-vcs.org/")
115
to_file.write("bzr comes with ABSOLUTELY NO WARRANTY. bzr is free software, and")
116
to_file.write("you may use, modify and redistribute it under the terms of the GNU")
117
to_file.write("General Public License version 2 or later.")