Ejemplo n.º 1
0
def cleanDirectory( directory ):
    EmergeDebug.debug("clean directory %s" % directory, 1)
    if ( os.path.exists( directory ) ):
        for root, dirs, files in os.walk( directory, topdown=False):
            for name in files:
                if not OsUtils.rm(os.path.join(root, name), True):
                    EmergeDebug.die("couldn't delete file %s\n ( %s )" % (name, os.path.join(root, name)))
            for name in dirs:
                if not OsUtils.rmDir(os.path.join(root, name), True):
                    EmergeDebug.die("couldn't delete directory %s\n( %s )" % (name, os.path.join(root, name)))
    else:
        os.makedirs( directory )
Ejemplo n.º 2
0
def copyFile(src, dest,linkOnly = emergeSettings.getboolean("General", "UseHardlinks", False)):
    """ copy file from src to dest"""
    EmergeDebug.debug("copy file from %s to %s" % (src, dest), 2)
    destDir = os.path.dirname( dest )
    if not os.path.exists( destDir ):
        os.makedirs( destDir )
    if os.path.exists( dest ):
        EmergeDebug.warning("Overriding %s" % dest)
        OsUtils.rm( dest, True )
    if linkOnly:
        try:
            os.link( src , dest )
            return True
        except:
            EmergeDebug.warning("Failed to create hardlink %s for %s" % (dest, src))
    shutil.copy(src,dest)
    return True
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def test_rm(self):
     _, fileName = tempfile.mkstemp()
     OsUtils.rm(fileName)
Ejemplo n.º 5
0
 def test_rmDir(self):
     dirName = tempfile.mkdtemp()
     OsUtils.rmDir(dirName)
Ejemplo n.º 6
0
 def test_rm(self):
     _, fileName = tempfile.mkstemp()
     OsUtils.rm(fileName)
Ejemplo n.º 7
0
 def test_rmDir(self):
     dirName = tempfile.mkdtemp()
     OsUtils.rmDir(dirName)