Mercurial > hgrepos > DevTools > mercurial-extensions
diff read_revinfo.py @ 16:e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Sun, 27 Sep 2015 14:28:21 +0200 |
| parents | b6e28cd1a610 |
| children | bfb7cad85467 |
line wrap: on
line diff
--- a/read_revinfo.py Sun Sep 27 14:18:06 2015 +0200 +++ b/read_revinfo.py Sun Sep 27 14:28:21 2015 +0200 @@ -2,7 +2,6 @@ r"""Read the output of the revinfo extension. The module handles the contents of a ".hg_archival.txt" file also. - """ __version__ = "0" @@ -27,5 +26,33 @@ except EnvironmentError: return None + +def read_revinfo_all(filename): + """Read file file `filename` and return it's contents as dict. + + If `filename` does not exist return `None`. + + All the "path" items are collected into a list. + """ + try: + f = open(filename, "rt") + try: + rv = {} + for k, v in [[i.strip() for i in line.split(":", 1)] for line in f]: + if k == "path": + try: + rv[k].append(v) + except KeyError: + rv[k] = [v] + else: + rv[k] = v + return rv + finally: + f.close() + except EnvironmentError: + return None + + import sys print read_revinfo_simple(sys.argv[1]) +print read_revinfo_all(sys.argv[1])
