comparison repair.py @ 66:53c37a02d471

working, I think/hope
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Thu, 14 Dec 2023 20:17:48 +0000
parents 5e5feacb730d
children
comparison
equal deleted inserted replaced
65:5e5feacb730d 66:53c37a02d471
34 if ll: 34 if ll:
35 res.append(ll.pop(0)) # method 35 res.append(ll.pop(0)) # method
36 else: 36 else:
37 return res 37 return res
38 if ll: 38 if ll:
39 res.append(dict((e[0],e[1:]) for e in ll.pop(0))) # params 39 params = ll.pop(0)
40 if params == 'nil':
41 res.append(params)
42 else:
43 res.append(dict((e[0],e[1:]) for e in params)) # params
40 else: 44 else:
41 return res 45 return res
42 if ll: 46 if ll:
43 raise ValueError("too many args: %s"%ll) 47 raise ValueError("too many args: %s"%ll)
44 return res 48 return res
83 # except ValueError: 87 # except ValueError:
84 # f.write(pl) 88 # f.write(pl)
85 else: 89 else:
86 f.write(pl) 90 f.write(pl)
87 91
92 def mergeOne(gv,mv):
93 '''rank: deeper in gnus wins
94 read: if unequal
95 if mail is nil, use gnus
96 otherwise use mail
97 marks: merge unseen keys, unequal values for same key prefer gnus
98 EXCEPT bogus, w3c-ac-forum, handle by hand DONE
99 method: change "ht" to "nnml+ht"
100 FIX group-2002-07 in gnus by hand DONE
101 params: merge by keys
102 '''
103 res = mv.copy()
104 if gv[0] > res[0]: # rank
105 res[0] = gv[0]
106 if res[1] == 'nil': # read
107 res[1] = gv[1]
108 if res[2] != gv[2]: # marks
109 if res[2] == 'nil':
110 res[2] = gv[2]
111 else:
112 for k, v in gv[2].items():
113 # fill in missing, override unequal, if equal no harm done
114 res[2][k] = v
115 # we prefer m to g for method
116 if len(res) == 4:
117 # no params
118 if len(gv) == 5:
119 res.append(gv[4])
120 elif len(gv) == 5:
121 if res[4] != gv[4]:
122 for k, v in gv[4].items():
123 # fill in missing, override unequal, if equal no harm done
124 res[4][k] = v
125 return res
126
127 def lineout(k,res,outf):
128 outf.write('("%s" '%k)
129 outf.write(str(res[0])) # rank
130 for v in res[1:]:
131 outf.write(' ')
132 p2l(v,outf)
133 outf.write(')\n')
134
88 def merge(gnus, mail, out): 135 def merge(gnus, mail, out):
89 ''' 136 '''
90 rank, read, marks, method, params 137 rank, read, marks, method, params
91 138
92 read is everything that is unmarked (nothing in left column) 139 read is everything that is unmarked (nothing in left column)
93 marks.seen is everything that has ever been looked it and not DELETED 140 marks.seen is everything that has ever been looked it and not DELETED
94 marks.tick is a !, marks.forward is F, marks.reply is A. 141 marks.tick is a !, marks.forward is F, marks.reply is A.
95
96 rank: deeper in gnus wins
97 read: if unequal
98 if mail is nil, use gnus
99 otherwise use mail
100 marks: merge unseen keys, unequal values for same key prefer gnus
101 EXCEPT bogus, w3c-ac-forum, handle by hand DONE
102 method: change "ht" to "nnml+ht", flag anything else
103 FIX group-2002-07 in gnus by hand DONE
104 params: merge by keys
105 ''' # ' 142 ''' # '
106 global g, m 143 global g, m
107 g1, g, g2 = readAlist(gnus) 144 g1, g, g2 = readAlist(gnus)
108 _, m, _ = readAlist(mail) 145 _, m, _ = readAlist(mail)
109 with open(out, "w") as outf: 146 with open(out, "w") as outf:
110 outf.write(g1) 147 outf.write(g1)
111 for k, v in g.items(): 148 for k, v in g.items():
112 if k in m: 149 if k in m:
113 return
114 res = mergeOne(v, m[k]) 150 res = mergeOne(v, m[k])
115 else: 151 else:
116 res = v 152 res = v
117 outf.write('("%s" '%k) 153 lineout(k,res,outf)
118 outf.write(str(res[0])) # rank 154 for k, v in m.items():
119 for v in res[1:]: 155 if k not in g:
120 outf.write(' ') 156 lineout(k,v,outf)
121 p2l(v,outf)
122 outf.write(')\n')
123 outf.write(g2) 157 outf.write(g2)
124 158
125 def stale(): 159 def stale():
126 ''' 160 '''
127 161