comparison src/tools/utils.py @ 1376:28fd9e838f8f

core: getRepositoryData now get the module in argument
author Goffi <goffi@goffi.org>
date Thu, 19 Mar 2015 20:40:10 +0100
parents 3a20312d4012
children 069ad98b360d
comparison
equal deleted inserted replaced
1375:3a20312d4012 1376:28fd9e838f8f
34 if unicodedata.category(char) == 'Cc' and char!='\n': 34 if unicodedata.category(char) == 'Cc' and char!='\n':
35 continue 35 continue
36 yield char 36 yield char
37 return ''.join(valid_chars(ustr)) 37 return ''.join(valid_chars(ustr))
38 38
39 def getRepositoryData(as_string=True): 39 def getRepositoryData(module, as_string=True):
40 """Retrieve info on current mecurial repository 40 """Retrieve info on current mecurial repository
41 41
42 @param module: module to look for (e.g. sat, libervia)
42 @param as_string(bool): if True return a string, else return a dictionary 43 @param as_string(bool): if True return a string, else return a dictionary
43 @return (unicode, dictionary): retrieved info in a nice string, 44 @return (unicode, dictionary): retrieved info in a nice string,
44 or a dictionary with retrieved data (key is not present if data is not found), 45 or a dictionary with retrieved data (key is not present if data is not found),
45 key can be: 46 key can be:
46 - node: full revision number (40 bits) 47 - node: full revision number (40 bits)
48 - date: ISO 8601 format date 49 - date: ISO 8601 format date
49 - tag: latest tag used in hierarchie 50 - tag: latest tag used in hierarchie
50 """ 51 """
51 from distutils.spawn import find_executable 52 from distutils.spawn import find_executable
52 import subprocess 53 import subprocess
53 import sat
54 KEYS=("node", "branch", "date", "tag") 54 KEYS=("node", "branch", "date", "tag")
55 sat_root = os.path.dirname(sat.__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(sat_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","parents","--template","{node}\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:
68 except subprocess.CalledProcessError: 68 except subprocess.CalledProcessError:
69 pass 69 pass
70 70
71 if not hg_data: 71 if not hg_data:
72 log.debug(u"Mercurial not available or working, trying to get data from dirstate") 72 log.debug(u"Mercurial not available or working, trying to get data from dirstate")
73 os.chdir(os.path.relpath('..', sat_root)) 73 os.chdir(os.path.relpath('..', repos_root))
74 try: 74 try:
75 with open('.hg/dirstate') as hg_dirstate: 75 with open('.hg/dirstate') as hg_dirstate:
76 hg_data['node'] = hg_dirstate.read(20).encode('hex') 76 hg_data['node'] = hg_dirstate.read(20).encode('hex')
77 except IOError: 77 except IOError:
78 log.warning(u"Can't access repository data") 78 log.warning(u"Can't access repository data")