~ubuntu-branches/debian/stretch/bzr-xmloutput/stretch

« back to all changes in this revision

Viewing changes to versionxml.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2009-01-20 05:18:35 UTC
  • Revision ID: james.westby@ubuntu.com-20090120051835-r8ppbnuij6m2symv
Tags: upstream-0.8.1+bzr116
ImportĀ upstreamĀ versionĀ 0.8.1+bzr116

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- encoding: utf-8 -*-
 
3
# Copyright (C) 2007 Guillermo Gonzalez
 
4
#
 
5
# The code taken from bzrlib is under: Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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
 
20
#
 
21
# Contributors:
 
22
#               Radim Kolam
 
23
 
 
24
# This code is a modified copy from bzrlib.version (see there for copyrights and licensing)
 
25
 
 
26
"""modified (and refactored) from bzrlib.version to generate xml output"""
 
27
 
 
28
import os
 
29
import sys
 
30
 
 
31
import bzrlib
 
32
from bzrlib import (
 
33
    config,
 
34
    trace,
 
35
    )
 
36
from bzrlib.version import _get_bzr_source_tree
 
37
from bzrlib.xml_serializer import _escape_cdata
 
38
 
 
39
def show_version_xml(show_config=True, show_copyright=True, to_file=None):
 
40
    if to_file is None:
 
41
        to_file = sys.stdout
 
42
    to_file.write(u'<version>')
 
43
    _show_bazaar_version(to_file=to_file)
 
44
    _show_python_version(to_file=to_file)
 
45
    print >>to_file
 
46
    to_file.write(u'</version>')
 
47
 
 
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
 
54
        # python executable
 
55
        to_file.write(u'<executable>%s</executable>' % sys.executable)
 
56
    else:
 
57
        # pythonXY.dll
 
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>')
 
65
 
 
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())
 
72
    if show_config:
 
73
        _show_bzr_config(to_file)
 
74
    if show_copyright:
 
75
        to_file.write('<copyright>')
 
76
        _show_copyright(to_file)
 
77
        to_file.write('</copyright>')
 
78
    to_file.write('</bazaar>')
 
79
 
 
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__)
 
85
    else:
 
86
        return bzrlib.__path__[0]
 
87
 
 
88
 
 
89
def _show_source_tree(to_file):
 
90
    src_tree = _get_bzr_source_tree()
 
91
    if src_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>')
 
100
 
 
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)
 
110
 
 
111
def _show_copyright(to_file):
 
112
    to_file.write(bzrlib.__copyright__)
 
113
    to_file.write("http://bazaar-vcs.org/")
 
114
    to_file.write('')
 
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.")
 
118