Debian Codegraph @

lib/sysinfo_data.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # QBrz - Qt frontend to Breezy commands
4 # Copyright (C) 2009 Lukáš Lalinský <[email protected]om>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 import os
21 import sys
22
23 import breezy
24 from breezy import controldir, config, errors, osutils, trace, bedding
25
26
27 def get_sys_info():
28 """Get the system information.
29
30 :return: a dictionary mapping fields to values. Field names are:
31 * bzr-version - version of Bazaar
32 * bzr-lib-path - paths to breezy roots (a list)
33 * bzr-source-tree - source tree holding Bazaar (None or a Tree object)
34 * bzr-config-dir - configuration directory holding bazaar.conf, etc.
35 * bzr-log-file - path to bzr.log file
36 * python-file - path to Python interpreter
37 * python-version - version of Python interpreter
38 * python-lib-dir - path to Python standard library
39 """
40 result = {"bzr-version": breezy.__version__, "bzr-lib-path": breezy.__path__}
41
42 # Bazaar installation
43 # is breezy itself in a branch?
44 source_tree = None # _get_bzr_source_tree()
45 if source_tree:
46 result["bzr-source-tree"] = _source_tree_details()
47 else:
48 result["bzr-source-tree"] = None
49
50 # Bazaar configuration
51 # config_dir = os.path.normpath(config.config_dir()) # use native slashes
52 config_dir = osutils.normpath(bedding.config_dir())
53 if not isinstance(config_dir, str):
54 config_dir = config_dir.decode(osutils.get_user_encoding())
55 result["brz-config-dir"] = config_dir
56 result["brz-log-file"] = trace._brz_log_filename
57
58 # Python installation
59 # (bzr.exe use python interpreter from pythonXY.dll
60 # but sys.executable point to bzr.exe itself)
61 if not hasattr(sys, 'frozen'): # check for bzr.exe
62 # python executable
63 py_file = sys.executable
64 else:
65 # pythonXY.dll
66 basedir = os.path.dirname(sys.executable)
67 python_dll = "python%d%d.dll" % sys.version_info[:2]
68 py_file = os.path.join(basedir, python_dll)
69 result["python-file"] = py_file
70 result["python-version"] = breezy._format_version_tuple(sys.version_info)
71 result["python-lib-dir"] = os.path.dirname(os.__file__)
72 return result
73
74
75 def _get_bzr_source_tree():
76 """Return the WorkingTree for bzr source, if any.
77
78 If bzr is not being run from its working tree, returns None.
79 """
80 try:
81 control = controldir.ControlDir.open_containing(__file__)[0]
82 return control.open_workingtree(recommend_upgrade=False)
83 except (errors.NotBranchError, errors.UnknownFormatError, errors.NoWorkingTree):
84 return None
85
86
87 def _source_tree_details(src_tree):
88 """Get details about a source tree.
89
90 :return: dictionary with keys of path, revno, revision-id, branch-nick.
91 """
92 result = {}
93 src_revision_id = src_tree.last_revision()
94 revno = src_tree.branch.revision_id_to_revno(src_revision_id)
95 result["path"] = src_tree.basedir
96 result["revno"] = revno
97 result["revision-id"] = src_revision_id
98 result["branch-nick"] = src_tree.branch.nick
99 return result