Mercurial > hg > python
annotate repair.py @ 62:c82a8743fd48
taking notes on how to merge
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Thu, 14 Dec 2023 00:13:19 +0000 |
parents | bc1acb1416ab |
children | 721bd7a04efb |
rev | line source |
---|---|
60
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
1 import lisparser |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
2 |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
3 def readAlist(fn): |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
4 with open(fn,'r') as f: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
5 sline = f.readline() |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
6 alines = [l for l in f if (L:=l).startswith("(")] |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
7 return sline, alist(alines), L |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
8 |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
9 def alist(lines): |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
10 res = {} |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
11 for l in lines: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
12 ll = lisparser.get_ast(lisparser.normalize_str(l))[0] |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
13 k = ll.pop(0) |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
14 n = ll.pop(0) |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
15 t = ll.pop(0) |
62
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
16 if ll: |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
17 pp = ll.pop(0) |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
18 if pp[0] == '(': |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
19 pp = dict((a[0],a[1:]) for a in pp) |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
20 # Otherwise only "nil", I think, so pass through |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
21 else: |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
22 pp = None |
60
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
23 res[eval(k)]=(n, t, pp, ll) |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
24 return res |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
25 |
62
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
26 # alist fields are: group, rank, read, marks, method, params |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
27 |
60
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
28 def p2l(pl, f, top = False): |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
29 if isinstance(pl,list) or isinstance(pl,tuple): |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
30 if len(pl) == 0: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
31 f.write('nil') |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
32 else: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
33 f.write('(') |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
34 space = False |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
35 for e in pl: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
36 if space: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
37 f.write(' ') |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
38 p2l(e,f) |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
39 else: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
40 p2l(e,f) |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
41 space = True |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
42 f.write(')') |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
43 elif isinstance(pl,dict): |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
44 if top: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
45 f.write("(setq gnus-newsrc-alist '(\n") |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
46 space = False |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
47 for k, v in pl.items(): |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
48 if space: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
49 f.write('%s('%('\n' if top else ' ')) |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
50 else: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
51 f.write('(' if top else '((') |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
52 space = True |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
53 if top: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
54 f.write('"%s"'%k) |
62
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
55 for e in v[:3]: # v is [n, t, pp, ll], pp may be None |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
56 if e: |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
57 f.write(' ') |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
58 p2l(e,f) |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
59 # ll may be empty |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
60 for e in v[3]: |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
61 if e: |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
62 f.write(' ') |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
63 p2l(e,f) |
60
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
64 else: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
65 f.write(k) |
62
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
66 for e in v: |
60
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
67 f.write(' ') |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
68 p2l(e,f) |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
69 f.write(')') |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
70 if top: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
71 f.write('\n))\n') |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
72 else: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
73 f.write(')') |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
74 elif isinstance(pl,str): |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
75 if pl in ['.','nil']: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
76 f.write(pl) |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
77 else: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
78 try: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
79 int(pl) |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
80 f.write(pl) |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
81 except ValueError: |
62
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
82 f.write(pl) |
60
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
83 else: |
bc1acb1416ab
working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
84 f.write(pl) |
62
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
85 |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
86 def merge(gnus, mail): |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
87 ''' |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
88 rank, read, marks, method, params |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
89 |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
90 read is everything that is unmarked (nothing in left column) |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
91 marks.seen is everything that has ever been looked it and not DELETED |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
92 marks.tick is a !, marks.forward is F, marks.reply is A. |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
93 |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
94 rank: deeper in gnus wins |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
95 read: if unequal |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
96 if mail is nil, use gnus |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
97 otherwise use mail |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
98 marks: merge unseen keys, unequal values for same key prefer gnus |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
99 EXCEPT bogus, w3c-ac-forum, handle by hand |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
100 method: change "ht" to "nnml+ht", flag anything else |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
101 params: TBD |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
102 |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
103 Comparison tool: |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
104 |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
105 export P='\(nil\|(\(\([0-9]\+\|([^)]*)\) \?\)*)\)' |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
106 paste <(cat shared) <(fgrep -f shared mail/alist.fixed | sed 's/ \([0-9]\) '"$P $P/ \1 \2 \5 /g" | cut -f 3) <(fgrep -f shared gnus/alist.fixed | sed 's/ \([0-9]\) '"$P $P/ \1 \2 \5 /g" | cut -f 3) | { IFS=' ' ; while read gn g m; do if [ "$g" != "$m" ]; then printf "=----%s------\n%s\n%s\n" "$gn" "$g" "$m"; fi; done ; } | less |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
107 |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
108 Watch out for tabs! |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
109 To look for overlap, change 2nd \n in printf to \t |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
110 |
c82a8743fd48
taking notes on how to merge
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
60
diff
changeset
|
111 ''' |