Exemplo n.º 1
0
 def generate(self):
     """
     Replace file hashes with new ones by running
     ``hashlib.sha1()`` on the file contents.
     """
     hashes = []
     for filename, ignore in self.data:
         h = util.sha1_digest(filename)
         if not h:
             raise ValueError, 'FileRefTableHDU.generate() failed take SHA1 of "%s"' % filename
         hashes.append(h.hexdigest())
         continue
     self.set_column_array("SHA1Hash", hashes)
     return
Exemplo n.º 2
0
    def validate(self):
        """
        Validate the referenced files.

        This will locate each file by its path and calculate the SHA1
        hash of its contents.

        See util.full_path() for how the files are located.
        """
        for name, digest in self.data:
            h = util.sha1_digest(name)
            if not h:
                raise ValueError, 'Failed to take SHA1 of "%s"' % name
            h = h.hexdigest()
            if h != digest:
                raise ValueError, 'SHA1 hash mismatch for "%s": %s != %s' % (name, h, digest)
            continue
        return