Mercurial > hgrepos > DevTools > mercurial-extensions
annotate 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 |
| rev | line source |
|---|---|
|
5
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
|
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
2 r"""Read the output of the revinfo extension. |
|
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
3 |
| 7 | 4 The module handles the contents of a ".hg_archival.txt" file also. |
|
5
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
5 """ |
|
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
6 |
|
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
7 __version__ = "0" |
|
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
8 |
|
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
9 __author__ = "Franz Glasner" |
|
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
10 |
|
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
11 |
|
15
b6e28cd1a610
Comment the sample file reader in read_revinfo.py with regard to multiple path items
Franz Glasner <hg@dom66.de>
parents:
7
diff
changeset
|
12 def read_revinfo_simple(filename): |
|
5
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
13 """Read file file `filename` and return it's contents as dict. |
|
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
14 |
|
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
15 If `filename` does not exist return `None`. |
|
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
16 |
|
15
b6e28cd1a610
Comment the sample file reader in read_revinfo.py with regard to multiple path items
Franz Glasner <hg@dom66.de>
parents:
7
diff
changeset
|
17 This is a simple-minded implementation: squashes many path items into |
|
b6e28cd1a610
Comment the sample file reader in read_revinfo.py with regard to multiple path items
Franz Glasner <hg@dom66.de>
parents:
7
diff
changeset
|
18 one (the last encountered). |
|
5
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
19 """ |
|
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
20 try: |
|
6
538c8f20ed51
Make compatible to older Python versions: don't use "with:" construct
Franz Glasner <hg@dom66.de>
parents:
5
diff
changeset
|
21 f = open(filename, "rt") |
|
538c8f20ed51
Make compatible to older Python versions: don't use "with:" construct
Franz Glasner <hg@dom66.de>
parents:
5
diff
changeset
|
22 try: |
| 17 | 23 return dict([[i.strip() for i in l.split(":", 1)] for l in f]) |
|
6
538c8f20ed51
Make compatible to older Python versions: don't use "with:" construct
Franz Glasner <hg@dom66.de>
parents:
5
diff
changeset
|
24 finally: |
|
538c8f20ed51
Make compatible to older Python versions: don't use "with:" construct
Franz Glasner <hg@dom66.de>
parents:
5
diff
changeset
|
25 f.close() |
|
5
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
26 except EnvironmentError: |
|
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
27 return None |
|
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
28 |
|
16
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
29 |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
30 def read_revinfo_all(filename): |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
31 """Read file file `filename` and return it's contents as dict. |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
32 |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
33 If `filename` does not exist return `None`. |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
34 |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
35 All the "path" items are collected into a list. |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
36 """ |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
37 try: |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
38 f = open(filename, "rt") |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
39 try: |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
40 rv = {} |
| 17 | 41 for k, v in [[i.strip() for i in l.split(":", 1)] for l in f]: |
|
16
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
42 if k == "path": |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
43 try: |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
44 rv[k].append(v) |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
45 except KeyError: |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
46 rv[k] = [v] |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
47 else: |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
48 rv[k] = v |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
49 return rv |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
50 finally: |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
51 f.close() |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
52 except EnvironmentError: |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
53 return None |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
54 |
|
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
55 |
|
5
3e0f25b30aaa
Module und function to read .hg_archival.txt and frieds and parse it's contents
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
56 import sys |
|
15
b6e28cd1a610
Comment the sample file reader in read_revinfo.py with regard to multiple path items
Franz Glasner <hg@dom66.de>
parents:
7
diff
changeset
|
57 print read_revinfo_simple(sys.argv[1]) |
|
16
e0f9f80704a1
Implement a "read_revinfo_all()" function that handles multiple "path" items also
Franz Glasner <hg@dom66.de>
parents:
15
diff
changeset
|
58 print read_revinfo_all(sys.argv[1]) |
