Mercurial > libervia-backend
comparison src/tools/utils.py @ 1471:934e402c90bf
core: tools.utils.getRepositoryData now return "hg log -r -1" and short form of node + fixed crash if mercurial is not present:
short form is now returned in string version for better readability. Even if a collision is possible, it's not a big deal as it is used mainly in about dialog to help identify a version in case of e.g. bug.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 18 Aug 2015 09:37:25 +0200 |
parents | 069ad98b360d |
children | 566908d483f6 |
comparison
equal
deleted
inserted
replaced
1470:8bfbf5cb0e28 | 1471:934e402c90bf |
---|---|
49 - date: ISO 8601 format date | 49 - date: ISO 8601 format date |
50 - tag: latest tag used in hierarchie | 50 - tag: latest tag used in hierarchie |
51 """ | 51 """ |
52 from distutils.spawn import find_executable | 52 from distutils.spawn import find_executable |
53 import subprocess | 53 import subprocess |
54 KEYS=("node", "branch", "date", "tag") | 54 KEYS=("node", "node_short", "branch", "date", "tag") |
55 repos_root = os.path.dirname(module.__file__) | 55 repos_root = os.path.dirname(module.__file__) |
56 hg_path = find_executable('hg') | 56 hg_path = find_executable('hg') |
57 | 57 |
58 if hg_path is not None: | 58 if hg_path is not None: |
59 os.chdir(repos_root) | 59 os.chdir(repos_root) |
60 try: | 60 try: |
61 hg_data_raw = subprocess.check_output(["hg","parents","--template","{node}\n{branch}\n{date|isodate}\n{latesttag}"]) | 61 hg_data_raw = subprocess.check_output(["hg","log", "-r", "-1", "--template","{node}\n{node|short}\n{branch}\n{date|isodate}\n{latesttag}"]) |
62 except subprocess.CalledProcessError: | 62 except subprocess.CalledProcessError: |
63 hg_data = {} | 63 hg_data = {} |
64 else: | 64 else: |
65 hg_data = dict(zip(KEYS, hg_data_raw.split('\n'))) | 65 hg_data = dict(zip(KEYS, hg_data_raw.split('\n'))) |
66 try: | 66 try: |
67 hg_data['modified'] = '+' in subprocess.check_output(["hg","id","-i"]) | 67 hg_data['modified'] = '+' in subprocess.check_output(["hg","id","-i"]) |
68 except subprocess.CalledProcessError: | 68 except subprocess.CalledProcessError: |
69 pass | 69 pass |
70 else: | |
71 hg_data = {} | |
70 | 72 |
71 if not hg_data: | 73 if not hg_data: |
72 log.debug(u"Mercurial not available or working, trying to get data from dirstate") | 74 log.debug(u"Mercurial not available or working, trying to get data from dirstate") |
73 os.chdir(os.path.relpath('..', repos_root)) | 75 os.chdir(os.path.relpath('..', repos_root)) |
74 try: | 76 try: |
75 with open('.hg/dirstate') as hg_dirstate: | 77 with open('.hg/dirstate') as hg_dirstate: |
76 hg_data['node'] = hg_dirstate.read(20).encode('hex') | 78 hg_data['node'] = hg_dirstate.read(20).encode('hex') |
79 hg_data['node_short'] = hg_data['node'][:12] | |
77 except IOError: | 80 except IOError: |
78 log.warning(u"Can't access repository data") | 81 log.warning(u"Can't access repository data") |
79 | 82 |
80 if as_string: | 83 if as_string: |
81 if not hg_data: | 84 if not hg_data: |
82 return u'repository data unknown' | 85 return u'repository data unknown' |
83 strings = [u'rev', hg_data['node']] | 86 strings = [u'rev', hg_data['node_short']] |
84 try: | 87 try: |
85 if hg_data['modified']: | 88 if hg_data['modified']: |
86 strings.append(u"[M]") | 89 strings.append(u"[M]") |
87 except KeyError: | 90 except KeyError: |
88 pass | 91 pass |