Mercurial > hgrepos > DevTools > mercurial-extensions
view read_revinfo.py @ 125:fb7e1e4e4d2c
Provide some SCCS markers also to be able to search with "what(1)" also
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Fri, 17 Aug 2018 09:07:02 +0200 |
| parents | bfb7cad85467 |
| children |
line wrap: on
line source
# -*- coding: utf-8 -*- r"""Read the output of the revinfo extension. The module handles the contents of a ".hg_archival.txt" file also. """ __version__ = "0" __author__ = "Franz Glasner" def read_revinfo_simple(filename): """Read file file `filename` and return it's contents as dict. If `filename` does not exist return `None`. This is a simple-minded implementation: squashes many path items into one (the last encountered). """ try: f = open(filename, "rt") try: return dict([[i.strip() for i in l.split(":", 1)] for l in f]) finally: f.close() 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 l.split(":", 1)] for l 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])
