Mercurial > hgrepos > DevTools > mercurial-extensions
view read_revinfo.py @ 425:2a062f87f75d
Make "revinfo" and "kwarchive" work on Mercurial 6.
Some URL related utility function have been moved from within mercurial.util
to mercurial.utils.urlutil.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 27 Aug 2022 21:36:16 +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])
