annotate repair.py @ 60:bc1acb1416ab

working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Wed, 13 Dec 2023 17:31:28 +0000
parents
children c82a8743fd48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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)
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
16 pp = dict((a[0],a[1:]) for a in ll.pop(0)) if ll else None
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
17 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
18 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
19
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
20 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
21 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
22 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
23 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
24 else:
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
25 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
26 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
27 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
28 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
29 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
30 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
31 else:
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
32 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
33 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
34 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
35 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
36 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
37 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
38 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
39 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
40 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
41 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
42 else:
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
43 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
44 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
45 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
46 f.write('"%s"'%k)
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
47 else:
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
48 f.write(k)
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
49 for e in v:
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
50 if e:
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
51 # 4th tuple, from tail of original (ref 'll' in alist), may be empty
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
52 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
53 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
54 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
55 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
56 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
57 else:
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
58 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
59 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
60 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
61 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
62 else:
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
63 try:
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
64 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
65 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
66 except ValueError:
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('"%s"'%pl)
bc1acb1416ab working on fixing gnus home foulup, see /disk/scratch/{mail,gnus}
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
68 else:
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(pl)