# HG changeset patch # User Henry S. Thompson # Date 1702488688 0 # Node ID bc1acb1416ab649c4a0e0c9492be4eea30f89dd9 # Parent dd63412fc8825c7f8509bf97f3da661ad3dc450d working on fixing gnus home foulup, see /disk/scratch/{mail,gnus} diff -r dd63412fc882 -r bc1acb1416ab repair.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/repair.py Wed Dec 13 17:31:28 2023 +0000 @@ -0,0 +1,69 @@ +import lisparser + +def readAlist(fn): + with open(fn,'r') as f: + sline = f.readline() + alines = [l for l in f if (L:=l).startswith("(")] + return sline, alist(alines), L + +def alist(lines): + res = {} + for l in lines: + ll = lisparser.get_ast(lisparser.normalize_str(l))[0] + k = ll.pop(0) + n = ll.pop(0) + t = ll.pop(0) + pp = dict((a[0],a[1:]) for a in ll.pop(0)) if ll else None + res[eval(k)]=(n, t, pp, ll) + return res + +def p2l(pl, f, top = False): + if isinstance(pl,list) or isinstance(pl,tuple): + if len(pl) == 0: + f.write('nil') + else: + f.write('(') + space = False + for e in pl: + if space: + f.write(' ') + p2l(e,f) + else: + p2l(e,f) + space = True + f.write(')') + elif isinstance(pl,dict): + if top: + f.write("(setq gnus-newsrc-alist '(\n") + space = False + for k, v in pl.items(): + if space: + f.write('%s('%('\n' if top else ' ')) + else: + f.write('(' if top else '((') + space = True + if top: + f.write('"%s"'%k) + else: + f.write(k) + for e in v: + if e: + # 4th tuple, from tail of original (ref 'll' in alist), may be empty + f.write(' ') + p2l(e,f) + f.write(')') + if top: + f.write('\n))\n') + else: + f.write(')') + elif isinstance(pl,str): + if pl in ['.','nil']: + f.write(pl) + else: + try: + int(pl) + f.write(pl) + except ValueError: + f.write('"%s"'%pl) + else: + f.write(pl)