diff options
author | Bjoern Tropf <asym@gentoo.org> | 2010-01-10 12:12:08 +0100 |
---|---|---|
committer | Bjoern Tropf <asym@gentoo.org> | 2010-01-10 12:12:08 +0100 |
commit | a132389d6137a663c6af368178912a64e482fa66 (patch) | |
tree | 9882d3c3f16c042b643a20533aa863ac6359f82c | |
parent | Small fix (diff) | |
download | kernel-check-a132389d6137a663c6af368178912a64e482fa66.tar.gz kernel-check-a132389d6137a663c6af368178912a64e482fa66.tar.bz2 kernel-check-a132389d6137a663c6af368178912a64e482fa66.zip |
Add an exception
-rwxr-xr-x | tools/cron.py | 32 |
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): |