Browse Source

Add more error checking.

suites/ascii
Petter Reinholdtsen 19 years ago
parent
commit
bb10a2108b
  1. 56
      prepop.py

56
prepop.py

@ -6,6 +6,7 @@
#
import sys, string, os, time, re
from sys import stderr
dirname = 'popcon-entries'
output = None
@ -13,11 +14,23 @@ output = None
now = time.time()
msgstartre = re.compile("^From")
md5sumre = re.compile("^([a-f0-9]{32})$")
md5sumre = re.compile("^[a-f0-9]{32}$")
timere = re.compile("^[0-9]+$")
def closereport(output, md5, mtime):
if output != None:
print "%s: %s" % (md5, time.ctime(mtime))
output.write(line)
output.close()
output = None
os.utime(fname, (mtime, mtime))
return output
while 1:
line = sys.stdin.readline()
if not line: break
if not line:
output = closereport(output, md5, mtime)
break
split = string.split(line)
if not split: continue
@ -34,30 +47,29 @@ while 1:
key, value = list
except:
continue
if key == 'ID' and md5sumre.match(value):
md5 = value
subdir = dirname + '/' + value[0:2]
try:
os.mkdir(subdir)
except os.error: # already exists
pass
fname = subdir + '/' + md5
output = open(fname, "w")
output.write(line)
if key == 'ID':
if not md5sumre.match(value):
print >>stderr,"Bad hostid: %s" % value
else:
md5 = value
subdir = dirname + '/' + value[0:2]
try:
os.mkdir(subdir)
except os.error: # already exists
pass
fname = subdir + '/' + md5
output = open(fname, "w")
output.write(line)
elif key == 'TIME':
mtime = float(value)
if (mtime > now):
if not timere.match(value):
print >>stderr,"Bad mtime: %s" % value
else:
mtime = float(value)
if (mtime > now):
mtime = now
elif split[0] == 'END-POPULARITY-CONTEST-0' or msgstartre.match(split[0]):
if output != None:
print "%s: %s" % (md5, time.ctime(mtime))
output.write(line)
output.close()
output = None
os.utime(fname, (mtime, mtime))
output = closereport(output, md5, mtime)
elif output != None:
output.write(line)

Loading…
Cancel
Save