Mercurial > hg > cc > cirrus_work
view lib/python/cc/build_idx.py @ 173:10c87f5c704d
add minimal logging and don't return until finished
| author | Henry S. Thompson <ht@inf.ed.ac.uk> |
|---|---|
| date | Fri, 24 Nov 2023 19:50:12 +0000 |
| parents | 1d1bd22124c0 |
| children | 4bae5b876418 |
line wrap: on
line source
#!/usr/bin/python3 '''Turn a merge_nnn.log file into a cluster.idx file We cheat and use the old cluster.idx to save having to read all the cdx-....gz files''' import sys with open('cluster.idx','r') as oidx, open('new.idx','w') as nidx: i=-1 curpos=0 target="cdx-00%03d.gz"%i log=open("/dev/null",'r') # embarassing hack for ol in oidx: (surt, datestamp, file, offset, length, cnt) = ol.split() if file!=target: i+=1 target="cdx-00%03d.gz"%i log.close() curpos=0 log=open('merge_%d.log'%(i+1),'r') hdr=log.readline() (j,f) = hdr.split() sys.stderr.write(hdr) if int(j)!=i+1: raise ValueError("wrong file: i=%s, j=%s"%(i,j)) nl=log.readline() if not nl: sys.stderr.write('quiting early: %s\n'%i) exit(1) nlen=int(nl) nidx.write("%s %s\t%s\t%s\t%s\t%s\n"%(surt, datestamp, file, curpos, nlen, cnt)) curpos+=nlen
