| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
om> |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 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 |
|
| 43 |
|
| 44 |
source_tree = None |
| 45 |
if source_tree: |
| 46 |
result["bzr-source-tree"] = _source_tree_details() |
| 47 |
else: |
| 48 |
result["bzr-source-tree"] = None |
| 49 |
|
| 50 |
|
| 51 |
|
| 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 |
|
| 59 |
|
| 60 |
|
| 61 |
if not hasattr(sys, 'frozen'): |
| 62 |
|
| 63 |
py_file = sys.executable |
| 64 |
else: |
| 65 |
|
| 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 |