Mercurial > pylearn
annotate version.py @ 323:44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
author | Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca> |
---|---|
date | Thu, 12 Jun 2008 17:12:45 -0400 |
parents | 9ebc960260c5 |
children | ce79bf5fa463 |
rev | line source |
---|---|
308 | 1 import subprocess as _subprocess |
2 import imp as _imp | |
323
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
3 import sys |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
4 import os |
308 | 5 |
6 _cache = {} | |
7 | |
8 def src_version(module_name): | |
9 """Return compact identifier of module code. | |
10 | |
11 @return: compact identifier of module code. | |
12 @rtype: string | |
13 | |
14 @note: This function tries to establish that the source files and the repo | |
15 are syncronized. It raises an Exception if there are un-tracked '.py' | |
16 files, or if there are un-committed modifications. This implementation uses | |
17 "hg id" to establish this. The code returned by "hg id" is not affected by | |
18 hg pull, but pulling might remove the " tip" string which might have | |
19 appeared. This implementation ignores the " tip" information, and only | |
20 uses the code. | |
21 | |
22 @note: This implementation is assumes that the import directory is under | |
23 version control by mercurial. | |
24 | |
25 """ | |
26 | |
27 if module_name not in _cache: | |
28 | |
323
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
29 try : |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
30 location = _imp.find_module(module_name)[1] |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
31 except ImportError: |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
32 _cache[module_name] = None |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
33 return None |
308 | 34 #print 'location:', location |
323
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
35 isdir = False |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
36 if os.path.isdir(location) : |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
37 isdir = True |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
38 elif os.path.isfile(location) : |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
39 isdir = False |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
40 else : |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
41 # SEEMS THIS CASE EXIST, FOR WEIRD BUILTIN FUNCTIONS |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
42 #print location,": it's 'not a dir, it's not a file, it's superman!" |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
43 #raise Exception('Unknown location or file type') |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
44 _cache[module_name] = None |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
45 return None |
308 | 46 |
47 | |
323
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
48 # we're dealing with a dir |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
49 if isdir : |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
50 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
51 # under hg? |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
52 if not os.path.exists( os.path.join( location , '.hg') ) : |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
53 _cache[module_name] = None |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
54 return None |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
55 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
56 status = _subprocess.Popen(('hg','st'),cwd=location,stdout=_subprocess.PIPE).communicate()[0] |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
57 #print 'status =', status |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
58 #TODO: check that the process return code is 0 (ticket #45) |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
59 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
60 #status_codes = [line[0] for line in if line and line[0] != '?'] |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
61 for line in status.split('\n'): |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
62 if not line: continue |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
63 if line[0] != '?': |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
64 raise Exception('Uncommitted modification to "%s" in %s (%s)' |
308 | 65 %(line[2:], __name__,location)) |
323
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
66 if line[0] == '?' and line[-3:] == '.py': |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
67 raise Exception('Untracked file "%s" in %s (%s)' |
308 | 68 %(line[2:], __name__, location)) |
69 | |
323
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
70 hg_id = _subprocess.Popen(('hg','id'),cwd=location,stdout=_subprocess.PIPE).communicate()[0] |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
71 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
72 # This asserts my understanding of hg id return values |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
73 # There is mention in the doc that it might return two parent hash codes |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
74 # but I've never seen it, and I dont' know what it means or how it is |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
75 # formatted. |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
76 tokens = hg_id.split(' ') |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
77 assert len(tokens) <= 2 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
78 assert len(tokens) >= 1 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
79 assert tokens[0][-1] != '+' # the trailing + indicates uncommitted changes |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
80 if len(tokens) == 2: |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
81 assert tokens[1] == 'tip\n' |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
82 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
83 _cache[module_name] = tokens[0] |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
84 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
85 # we're dealing with a file |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
86 if not isdir : |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
87 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
88 folder = os.path.split( os.path.abspath(location) )[0] |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
89 # under hg? |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
90 if not os.path.exists( os.path.join( folder , '.hg') ) : |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
91 _cache[module_name] = None |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
92 return None |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
93 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
94 status = _subprocess.Popen(('hg','st',location),cwd=folder,stdout=_subprocess.PIPE).communicate()[0] |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
95 #print 'status =', status |
308 | 96 |
323
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
97 #status_codes = [line[0] for line in if line and line[0] != '?'] |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
98 for line in status.split('\n'): |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
99 if not line: continue |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
100 if line[0] != '?': |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
101 raise Exception('Uncommitted modification to "%s" in %s (%s)' |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
102 %(line[2:], location,folder)) |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
103 if line[0] == '?' and line[-3:] == '.py': |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
104 raise Exception('Untracked file "%s" in %s (%s)' |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
105 %(line[2:], location, folder)) |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
106 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
107 hg_id = _subprocess.Popen(('hg','id'),cwd=folder,stdout=_subprocess.PIPE).communicate()[0] |
308 | 108 |
323
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
109 # This asserts my understanding of hg id return values |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
110 # There is mention in the doc that it might return two parent hash codes |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
111 # but I've never seen it, and I dont' know what it means or how it is |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
112 # formatted. |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
113 tokens = hg_id.split(' ') |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
114 assert len(tokens) <= 2 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
115 assert len(tokens) >= 1 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
116 if tokens[0][-1] == '+' : |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
117 tokens[0] = tokens[0][:-1] # the change was not on this file |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
118 if len(tokens) == 2: |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
119 assert tokens[1] == 'tip\n' |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
120 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
121 _cache[module_name] = tokens[0] |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
122 |
308 | 123 |
124 return _cache[module_name] | |
125 | |
126 | |
323
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
127 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
128 def get_all_src_versions() : |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
129 """ |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
130 Get the version of all loaded module. |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
131 Calls src_version on all loaded modules. These modules are found |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
132 using sys.modules. |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
133 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
134 Returns a dictionnary: name->version. |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
135 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
136 @RETURN dict Dictionnary (module's name) -> (version) |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
137 @SEE src_version |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
138 """ |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
139 allmodules = sys.modules |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
140 d = dict() |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
141 for m in allmodules : |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
142 d[m] = src_version(m) |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
143 return d |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
144 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
145 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
146 if __name__ == "__main__" : |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
147 |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
148 if len(sys.argv) == 2 : |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
149 print 'testing on', sys.argv[1] |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
150 print src_version(sys.argv[1]) |
44f94ffe28f7
version works with file and folder, returns null if not in hg. Also a function to get all modules, but seems to get junk at the same time
Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca>
parents:
308
diff
changeset
|
151 |