Mercurial > hg > cc > cirrus_work
comparison bin/merge_date.py @ 101:e2e64c3d763e
bug4 fixed, but that created a new, earlier bug
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Mon, 11 Sep 2023 22:06:45 +0100 |
parents | 18446a7eeb9e |
children | e606c609f813 |
comparison
equal
deleted
inserted
replaced
100:18446a7eeb9e | 101:e2e64c3d763e |
---|---|
61 NF.close() | 61 NF.close() |
62 print(NN, flush=True) # so we can compress it | 62 print(NN, flush=True) # so we can compress it |
63 time.sleep(0.1) # so it flushes? | 63 time.sleep(0.1) # so it flushes? |
64 XN=XPATH%FN | 64 XN=XPATH%FN |
65 if not os.path.exists(XN): | 65 if not os.path.exists(XN): |
66 return | 66 return (None, None) |
67 XF = igzip.IGzipFile(filename=XN) | 67 XF = igzip.IGzipFile(filename=XN) |
68 NF = open((NN:=NPATH%FN), 'wb') | 68 NF = open((NN:=NPATH%FN), 'wb') |
69 xl = XF.readline() | 69 xl = XF.readline() |
70 XCNT = 1 | 70 XCNT = 1 |
71 return xl, xq | 71 return xl, xq |
108 if DEBUG>1: | 108 if DEBUG>1: |
109 sys.stderr.write("xl: %s\n"%(' '.join(xp.decode('ascii') | 109 sys.stderr.write("xl: %s\n"%(' '.join(xp.decode('ascii') |
110 for xp in (xkey, xdate, xurl)))) | 110 for xp in (xkey, xdate, xurl)))) |
111 messyU, xkey1, xkey2 = keys(xkey) | 111 messyU, xkey1, xkey2 = keys(xkey) |
112 if messyD: | 112 if messyD: |
113 noMatch = (ddate != xdate or | |
114 not dkey.startswith(xkey1) or | |
115 dkey!=xkey1 or | |
116 durl!=xurl) | |
113 if messyU: | 117 if messyU: |
114 # better match | 118 # better match |
115 if (ddate != xdate or | 119 if noMatch: |
116 not dkey.startswith(xkey1) or | |
117 dkey!=xkey1 or | |
118 durl!=xurl): | |
119 raise ValueError("Fail: xkey: %s\n" | 120 raise ValueError("Fail: xkey: %s\n" |
120 " dkey: %s\n" | 121 " dkey: %s\n" |
121 " xdate: %s\n" | 122 " xdate: %s\n" |
122 " ddate: %s\n" | 123 " ddate: %s\n" |
123 " xurl: %s\n" | 124 " xurl: %s\n" |
126 "k1, k2: |%s|%s|\n" | 127 "k1, k2: |%s|%s|\n" |
127 "FN: %s XCNT: %s DCNT: %s\n" | 128 "FN: %s XCNT: %s DCNT: %s\n" |
128 "xl: %s"%(xkey, dkey, xdate, ddate, xurl, durl, | 129 "xl: %s"%(xkey, dkey, xdate, ddate, xurl, durl, |
129 (b'\n '.join(dfq)).decode('ascii'), | 130 (b'\n '.join(dfq)).decode('ascii'), |
130 xkey1, xkey2, FN, XCNT, DCNT, xl)) | 131 xkey1, xkey2, FN, XCNT, DCNT, xl)) |
131 messyD = False | |
132 # fall through to the ordinary (non-messy) match case | 132 # fall through to the ordinary (non-messy) match case |
133 else: | 133 else: |
134 # still looking, save this one | 134 # still looking, save if >= date else fall through to write |
135 if DEBUG: | 135 if DEBUG>1: |
136 print("Diso: xkey: %s\n" | 136 print("Diso: xkey: %s\n" |
137 " dkey: %s\n" | 137 " dkey: %s\n" |
138 " xdate: %s\n" | 138 " xdate: %s\n" |
139 " ddate: %s\n" | 139 " ddate: %s\n" |
140 " xurl: %s\n" | 140 " xurl: %s\n" |
141 " durl: %s\n" | 141 " durl: %s\n" |
142 "xl: %s"%(xkey, dkey, xdate, ddate, xurl, durl, xl), | 142 "xl: %s"%(xkey, dkey, xdate, ddate, xurl, durl, xl), |
143 file=sys.stderr) | 143 file=sys.stderr) |
144 xq.append(xl) | 144 if not noMatch: |
145 if DEBUG>1: | 145 xq.append(xl) |
146 sys.stderr.write('xpush\n') | 146 if DEBUG>1: |
147 continue | 147 sys.stderr.write('xpush\n') |
148 continue | |
149 # else fall through | |
148 else: | 150 else: |
149 # Not messyD | 151 # Not messyD |
150 if messyU: | 152 if messyU: |
151 raise ValueError("messyD w/o messyU") | 153 raise ValueError("messyU w/o messyD:" |
154 "xkey: %s\n" | |
155 "dkey: %s\n" | |
156 "xdate: %s\n" | |
157 "ddate: %s\n" | |
158 "xurl: %s\n" | |
159 "durl: %s\n" | |
160 "dfq: %s\n" | |
161 "k1, k2: |%s|%s|\n" | |
162 "FN: %s XCNT: %s DCNT: %s\n" | |
163 "xl: %s"%(xkey, dkey, xdate, ddate, xurl, durl, | |
164 (b'\n '.join(dfq)).decode('ascii'), | |
165 xkey1, xkey2, FN, XCNT, DCNT, xl)) | |
152 if (ddate != xdate or | 166 if (ddate != xdate or |
153 not dkey.startswith(xkey1) or | 167 not dkey.startswith(xkey1) or |
154 (xkey2 is not None and dkey!=xkey2) or | 168 (xkey2 is not None and dkey!=xkey2) or |
155 durl!=xurl): | 169 durl!=xurl): |
156 NF.write(xl) | 170 NF.write(xl) |