예제 #1
0
파일: __init__.py 프로젝트: 0x90/ivre
    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)
예제 #2
0
    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)