Example #1
0
 def copyRecursively(self, sourcePath, targetPath):
     srcFileInfo = QFileInfo(sourcePath)
     if srcFileInfo.isDir() and not srcFileInfo.isSymLink():
         targetDir = QDir(targetPath)
         targetDir.cdUp()
         if not targetDir.mkdir(QFileInfo(targetPath).fileName()):
             return False
         fileNames = QDir(sourcePath).entryList(QDir.Files | QDir.Dirs | QDir.NoDotAndDotDot |
                 QDir.Hidden | QDir.System)
         for fileName in fileNames:
             newSourcePath = sourcePath + '/' + fileName
             newTargetPath = targetPath + '/' + fileName
             if not self.copyRecursively(newSourcePath, newTargetPath):
                 return False
     elif not const.OS_WIN and srcFileInfo.isSymLink():
         linkPath = readlink(sourcePath)
         return QFile.link(linkPath, targetPath)
     elif not QFile.copy(sourcePath, targetPath):
         return False
     return True
Example #2
0
 def removeRecursively(self, filePath):
     '''
     @param: filePath QString
     '''
     fileInfo = QFileInfo(filePath)
     if not fileInfo.exists() and not fileInfo.isSymLink():
         return
     if fileInfo.isDir() and not fileInfo.isSymLink():
         dir_ = QDir(filePath)
         dir_ = dir_.canonicalPath()
         if dir_.isRoot() or dir_.path() == QDir.home().canonicalPath():
             print('CRITICAL: Attempt to remove root/home directory', dir_)
             return False
         fileNames = dir_.entryList(QDir.Files | QDir.Dirs | QDir.NoDotAndDotDot |
                 QDir.Hidden | QDir.System)
         for fileName in fileNames:
             if not self.removeRecursively(filePath + '/' + fileName):
                 return False
         if not QDir.root().rmdir(dir_.path()):
             return False
     elif not QFile.remove(filePath):
         return False
     return True