def __init__(self, outputdir, overwrite=False, crcs={}, **options):
        self.outputdir = outputdir
        self.overwrite = overwrite
        self.parseopts(**options)

        # Read MD5 sums for testing file changes.
        self.md5file = os.path.join(self.outputdir, '.md5sums')
        self.md5sums = {}
        if os.path.exists(self.md5file):
            for line in open(self.md5file, 'r'):
                try:
                    digest, filename = line.rstrip().split(None, 1)
                    self.md5sums[filename] = digest
                except:
                    pass

        # Migrate legacy CRCs to MD5 sums. If the file is unchanged, calculate
        # the MD5; otherwise, continue to check the old CRC32.
        self.crcs = {}
        for filename in crcs:
            if filename in self.md5sums:
                # Assume MD5 sum is more recent
                continue
            # Check if the file has changed since the last CRC32.
            pathname = os.path.join(self.outputdir, filename)
            if not os.path.exists(pathname):
                # The file has been removed, and can be regenerated.
                continue
            if crcs[filename] == str(utils.fileCRC(pathname, stripnewlines=True)):
                # File is unchanged, calculate MD5 sum.
                self.md5sums[filename] = utils.fileMD5(pathname)
            else:
                self.crcs[filename] = crcs[filename]
 def fileChanged(self, filename):
     pathname = os.path.join(self.outputdir, filename)
     if not os.path.exists(pathname):
         return False
     lastHash = self.md5sums.get(filename, None)
     if lastHash is None and filename in self.crcs:
         lastHash = self.crcs[filename]
         currentHash = str(utils.fileCRC(pathname, stripnewlines=True))
     else:
         currentHash = utils.fileMD5(pathname)
     return lastHash != currentHash
示例#3
0
 def fileChanged(self, filename, userfile=False):
     if userfile:
         return True
     pathname = os.path.join(self.outputdir, filename)
     if not os.path.exists(pathname):
         return False
     lastHash = self.md5sums.get(filename, None)
     if lastHash is None and filename in self.crcs:
         lastHash = self.crcs[filename]
         currentHash = str(utils.fileCRC(pathname, stripnewlines=True))
     else:
         currentHash = utils.fileMD5(pathname)
     return lastHash != currentHash
示例#4
0
    def __init__(self,
                 outputdir,
                 overwrite=False,
                 crcs={},
                 variant="",
                 header=None,
                 **options):

        self.outputdir = outputdir
        self.overwrite = overwrite
        if variant != "":
            variant = "_" + variant
        self.variant = variant
        self.parseopts(**options)

        # Read MD5 sums for testing file changes.
        self.md5file = os.path.join(self.outputdir, '.md5sums')
        self.md5sums = {}
        if os.path.exists(self.md5file):
            for line in open(self.md5file, 'r'):
                try:
                    digest, filename = line.rstrip().split(None, 1)
                    self.md5sums[filename] = digest
                except:
                    pass

        # Migrate legacy CRCs to MD5 sums. If the file is unchanged, calculate
        # the MD5; otherwise, continue to check the old CRC32.
        self.crcs = {}
        for filename in crcs:
            if filename in self.md5sums:
                # Assume MD5 sum is more recent
                continue
            # Check if the file has changed since the last CRC32.
            pathname = os.path.join(self.outputdir, filename)
            if not os.path.exists(pathname):
                # The file has been removed, and can be regenerated.
                continue
            if crcs[filename] == str(
                    utils.fileCRC(pathname, stripnewlines=True)):
                # File is unchanged, calculate MD5 sum.
                self.md5sums[filename] = utils.fileMD5(pathname)
            else:
                self.crcs[filename] = crcs[filename]

        # Save the header (if given)
        self.header = header