summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtools/cron.py32
1 files changed, 18 insertions, 14 deletions
diff --git a/tools/cron.py b/tools/cron.py
index a5679e2..1e45db8 100755
--- a/tools/cron.py
+++ b/tools/cron.py
@@ -121,7 +121,7 @@ def main(argv):
with open(xmlfile, 'r') as data:
filetable[xmlfile] = hashlib.md5(data.read()).hexdigest()
else:
- logging.error('Invalid directory: %s', xmlfile)
+ logging.error('Invalid directory: %s' % xmlfile)
logging.info('Receiving the latest xml file from the nvd')
@@ -461,23 +461,27 @@ def write_xml_file(directory, vul, filetable):
hashfile = os.path.join(PARAM['tmpdir'], 'hash.xml')
xmlout_hash = str()
- with open(hashfile, 'w') as xmlout:
- __indent__(root)
- doc = et.ElementTree(root)
- doc.write(xmlout, encoding='utf-8')
+ try:
+ with open(hashfile, 'w') as xmlout:
+ __indent__(root)
+ doc = et.ElementTree(root)
+ doc.write(xmlout, encoding='utf-8')
+
+ with open(hashfile, 'r') as xmlout:
+ xmlout_hash = hashlib.md5(xmlout.read()).hexdigest()
- with open(hashfile, 'r') as xmlout:
- xmlout_hash = hashlib.md5(xmlout.read()).hexdigest()
+ if filename in filetable:
+ if filetable[filename] != xmlout_hash:
+ shutil.move(hashfile, filename)
+ logging.debug('File changed %s' % filename)
- if filename in filetable:
- if filetable[filename] != xmlout_hash:
+ del filetable[filename]
+ else:
shutil.move(hashfile, filename)
- logging.debug('File changed %s' % filename)
+ logging.debug('File new %s' % filename)
- del filetable[filename]
- else:
- shutil.move(hashfile, filename)
- logging.debug('File new %s' % filename)
+ except Exception, e:
+ logging.error("File creation failed: %s" % e)
def __indent__(node, level=0):