def store_scan(self, fname, **kargs): """This method opens a scan result, and calls the appropriate store_scan_* method to parse (and store) the scan result. """ scanid = utils.hash_file(fname, hashtype="sha256").hexdigest() if self.is_scan_present(scanid): if config.DEBUG: sys.stderr.write("WARNING: Scan already present in Database" " (%r).\n" % fname) return False with utils.open_file(fname) as fdesc: fchar = fdesc.read(1) try: store_scan_function = {"<": self.store_scan_xml, "{": self.store_scan_json}[fchar] except KeyError: raise ValueError("Unknown file type %s" % fname) return store_scan_function(fname, filehash=scanid, **kargs)
def store_scan(self, fname, **kargs): """This method opens a scan result, and calls the appropriate store_scan_* method to parse (and store) the scan result. """ scanid = utils.hash_file(fname, hashtype="sha256").hexdigest() if self.is_scan_present(scanid): if config.DEBUG: sys.stderr.write("WARNING: Scan already present in Database" " (%r).\n" % fname) return False with utils.open_file(fname) as fdesc: fchar = fdesc.read(1) try: return { '<': self.store_scan_xml, '{': self.store_scan_json, }[fchar](fname, filehash=scanid, **kargs) except KeyError: raise ValueError("Unknown file type %s" % fname)