Beispiel #1
0
def unmergeFileList(rootdir, fileList, forced=False):
    """ delete files in the fileList if has matches or forced is True """
    for filename, filehash in fileList:
        fullPath = os.path.join(rootdir, os.path.normcase( filename))
        if os.path.isfile(fullPath):
            algorithm = EmergeHash.HashAlgorithm.getAlgorithmFromPrefix(filehash)
            if not algorithm:
                currentHash = EmergeHash.digestFile(fullPath, EmergeHash.HashAlgorithm.MD5)
            else:
                currentHash = algorithm.stringPrefix() + EmergeHash.digestFile(fullPath, algorithm)
            if currentHash == filehash or filehash == "":
                EmergeDebug.debug("deleting file %s" % fullPath, 2)
                try:
                    os.remove(fullPath)
                except OSError:
                    system( "cmd /C \"attrib -R %s\"" % fullPath )
                    os.remove(fullPath)
            else:
                if forced:
                    EmergeDebug.warning("file %s has different hash: %s %s, deleting anyway" % \
                            (fullPath, currentHash, filehash ))
                try:
                    os.remove(fullPath)
                except OSError:
                    system( "cmd /C \"attrib -R %s\"" % fullPath )
                    os.remove(fullPath)
                else:
                    EmergeDebug.warning("file %s has different hash: %s %s, run with option --force to delete it anyway" % \
                            (fullPath, currentHash, filehash ))
        elif not os.path.isdir(fullPath):
            EmergeDebug.warning("file %s does not exist" % fullPath)
Beispiel #2
0
def unmergeFileList(rootdir, fileList, forced=False):
    """ delete files in the fileList if has matches or forced is True """
    for filename, filehash in fileList:
        fullPath = os.path.join(rootdir, os.path.normcase( filename))
        if os.path.isfile(fullPath):
            algorithm = EmergeHash.HashAlgorithm.getAlgorithmFromPrefix(filehash)
            if not algorithm:
                currentHash = EmergeHash.digestFile(fullPath, EmergeHash.HashAlgorithm.MD5)
            else:
                currentHash = algorithm.stringPrefix() + EmergeHash.digestFile(fullPath, algorithm)
            if currentHash == filehash or filehash == "":
                OsUtils.rm(fullPath, True)
            else:
                if forced:
                    EmergeDebug.warning("file %s has different hash: %s %s, deleting anyway" % \
                            (fullPath, currentHash, filehash ))
                    OsUtils.rm(fullPath, True)
                else:
                    EmergeDebug.warning("file %s has different hash: %s %s, run with option --force to delete it anyway" % \
                            (fullPath, currentHash, filehash ))
        elif not os.path.isdir(fullPath):
            EmergeDebug.warning("file %s does not exist" % fullPath)
Beispiel #3
0
def getFileListFromDirectory( imagedir ):
    """ create a file list containing hashes """
    ret = []

    myimagedir = imagedir
    if ( not imagedir.endswith( "\\" ) ):
        myimagedir = myimagedir + "\\"

    algorithm = EmergeHash.HashAlgorithm.SHA256
    for root, _, files in os.walk( imagedir ):
        for fileName in files:
            ret.append( ( os.path.join( root, fileName ).replace( myimagedir, "" ), algorithm.stringPrefix() + EmergeHash.digestFile( os.path.join( root, fileName), algorithm) ) )
    return ret