Example #1
0
 def writeContents(self):
     self.changedValueNumber = 0
     oldAndNewPathValues = []
     isNewDirectoriesSame = True
     isMovedToNewDirectory = False
     currentDirectoryPath = ""
     newDirectoryPath = ""
     startRowNo, rowStep = 0, 1
     uni.startThreadAction()
     allItemNumber = len(self.values)
     Dialogs.showState(
         translate("FileUtils/Covers", "Writing Cover Informations"), 0,
         allItemNumber, True)
     for rowNo in range(startRowNo, self.rowCount(), rowStep):
         isContinueThreadAction = uni.isContinueThreadAction()
         if isContinueThreadAction:
             try:
                 if fu.isWritableFileOrDir(self.values[rowNo]["path"],
                                           False, True):
                     if self.isRowHidden(rowNo):
                         fu.removeFileOrDir(self.values[rowNo]["path"])
                         self.changedValueNumber += 1
                     else:
                         baseNameOfDirectory = str(
                             self.values[rowNo]["baseNameOfDirectory"])
                         baseName = str(self.values[rowNo]["baseName"])
                         if (self.isChangeableItem(rowNo, "sourceCover")
                                 or self.isChangeableItem(
                                     rowNo, "destinationCover")):
                             sourcePath = self.values[rowNo]["sourceCover"]
                             destinationPath = self.values[rowNo][
                                 "destinationCover"]
                             if self.isChangeableItem(rowNo, "sourceCover"):
                                 sourcePath = str(
                                     self.item(rowNo, 3).text()).strip()
                             if self.isChangeableItem(
                                     rowNo, "destinationCover"):
                                 destinationPath = str(
                                     self.item(rowNo, 4).text()).strip()
                             if (str(self.item(rowNo,
                                               2).text()) != sourcePath
                                     or sourcePath != destinationPath
                                     or str(self.item(rowNo, 2).text()) !=
                                     destinationPath
                                 ) or (str(self.item(rowNo, 2).text()) !=
                                       self.values[rowNo]["currentCover"]
                                       and
                                       (str(self.item(rowNo, 2).text()) !=
                                        sourcePath
                                        and str(self.item(rowNo, 2).text())
                                        != destinationPath)):
                                 if str(self.item(rowNo,
                                                  3).text()).strip() != "":
                                     sourcePath = fu.getRealPath(
                                         sourcePath,
                                         self.values[rowNo]["path"])
                                     sourcePath = fu.checkSource(
                                         sourcePath, "file")
                                     if sourcePath is not None:
                                         if destinationPath != "":
                                             destinationPath = fu.getRealPath(
                                                 destinationPath,
                                                 self.values[rowNo]["path"])
                                             if sourcePath != destinationPath:
                                                 destinationPath = fu.moveOrChange(
                                                     sourcePath,
                                                     destinationPath)
                                         else:
                                             destinationPath = sourcePath
                                         fu.setIconToDirectory(
                                             self.values[rowNo]["path"],
                                             destinationPath)
                                         self.changedValueNumber += 1
                                 else:
                                     fu.setIconToDirectory(
                                         self.values[rowNo]["path"], "")
                                     self.changedValueNumber += 1
                         if self.isChangeableItem(rowNo,
                                                  "baseNameOfDirectory",
                                                  baseNameOfDirectory):
                             baseNameOfDirectory = str(
                                 self.item(rowNo, 0).text())
                             self.changedValueNumber += 1
                             isMovedToNewDirectory = True
                             currentDirectoryPath = fu.getDirName(
                                 self.values[rowNo]["path"])
                             newDirectoryPath = fu.joinPath(
                                 fu.getDirName(
                                     fu.getDirName(
                                         self.values[rowNo]["path"])),
                                 baseNameOfDirectory)
                             self.setNewDirectory(newDirectoryPath)
                             if rowNo > 0:
                                 if str(self.item(
                                         rowNo - 1,
                                         0).text()) != baseNameOfDirectory:
                                     isNewDirectoriesSame = False
                         if self.isChangeableItem(rowNo, "baseName",
                                                  baseName, False):
                             baseName = str(self.item(rowNo, 1).text())
                             self.changedValueNumber += 1
                         newFilePath = fu.joinPath(
                             fu.getDirName(
                                 fu.getDirName(self.values[rowNo]["path"])),
                             baseNameOfDirectory, baseName)
                         oldFilePath = fu.getRealPath(
                             self.values[rowNo]["path"])
                         newFilePath = fu.getRealPath(newFilePath)
                         if oldFilePath != newFilePath:
                             oldAndNewPaths = {}
                             oldAndNewPaths["oldPath"] = oldFilePath
                             oldAndNewPaths["newPath"] = fu.moveOrChange(
                                 oldFilePath, newFilePath, "directory")
                             if oldFilePath != oldAndNewPaths["newPath"]:
                                 oldAndNewPathValues.append(oldAndNewPaths)
                                 oldDirName = fu.getDirName(oldFilePath)
                                 if uni.getBoolValue(
                                         "isClearEmptyDirectoriesWhenFileMove"
                                 ):
                                     fu.checkEmptyDirectories(
                                         oldDirName, True, True,
                                         uni.getBoolValue(
                                             "isAutoCleanSubFolderWhenFileMove"
                                         ))
             except:
                 ReportBug.ReportBug()
         else:
             allItemNumber = rowNo + 1
         Dialogs.showState(
             translate("FileUtils/Covers", "Writing Cover Informations"),
             rowNo + 1, allItemNumber, True)
         if isContinueThreadAction is False:
             break
     uni.finishThreadAction()
     if self.rowCount() == len(
             oldAndNewPathValues
     ) and isMovedToNewDirectory and isNewDirectoriesSame:
         otherFileNames = fu.readDirectory(currentDirectoryPath,
                                           "fileAndDirectory", True)
         if len(otherFileNames) > 0:
             answer = Dialogs.ask(
                 translate("FileUtils/Musics", "There Are More Files"),
                 str(
                     translate(
                         "FileUtils/Musics",
                         "\"%s\" : there are more files in this directory.<br>Are you want to move all found files into new directory?<br>New Directory : \"%s\""
                     )) % (Organizer.getLink(currentDirectoryPath),
                           Organizer.getLink(newDirectoryPath)))
             if answer == Dialogs.Yes:
                 uni.startThreadAction()
                 allItemNumber = len(otherFileNames)
                 for rowNo, fileName in enumerate(otherFileNames):
                     isContinueThreadAction = uni.isContinueThreadAction()
                     if isContinueThreadAction:
                         try:
                             oldFilePath = fu.getRealPath(
                                 fu.joinPath(currentDirectoryPath,
                                             fileName))
                             newFilePath = fu.getRealPath(
                                 fu.joinPath(newDirectoryPath, fileName))
                             if oldFilePath != newFilePath:
                                 oldAndNewPaths = {}
                                 oldAndNewPaths["oldPath"] = oldFilePath
                                 oldAndNewPaths[
                                     "newPath"] = fu.moveOrChange(
                                         oldFilePath, newFilePath,
                                         fu.getObjectType(oldFilePath))
                                 if oldFilePath != oldAndNewPaths["newPath"]:
                                     oldAndNewPathValues.append(
                                         oldAndNewPaths)
                         except:
                             ReportBug.ReportBug()
                     else:
                         allItemNumber = rowNo + 1
                     Dialogs.showState(
                         translate(
                             "FileUtils/Covers",
                             "Writing Directory And File Informations"),
                         rowNo + 1, allItemNumber, True)
                     if isContinueThreadAction is False:
                         break
                 uni.finishThreadAction()
                 if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"):
                     fu.checkEmptyDirectories(
                         currentDirectoryPath, True, True,
                         uni.getBoolValue(
                             "isAutoCleanSubFolderWhenFileMove"))
                 if (uni.isActiveDirectoryCover and
                         uni.getBoolValue("isActiveAutoMakeIconToDirectory")
                         and uni.getBoolValue(
                             "isAutoMakeIconToDirectoryWhenFileMove")):
                     fu.checkIcon(newDirectoryPath)
     return True
Example #2
0
    def writeContents(self):
        self.changedValueNumber = 0
        oldAndNewPathValues = []
        startRowNo, rowStep = 0, 1
        uni.startThreadAction()
        allItemNumber = len(self.values)
        Dialogs.showState(
            translate("FileUtils/Covers", "Writing Cover Informations"), 0,
            allItemNumber, True)
        for rowNo in range(startRowNo, self.rowCount(), rowStep):
            isContinueThreadAction = uni.isContinueThreadAction()
            if isContinueThreadAction:
                try:
                    if fu.isWritableFileOrDir(self.values[rowNo]["path"],
                                              False, True):
                        if self.isRowHidden(rowNo):
                            fu.removeFileOrDir(self.values[rowNo]["path"])
                            self.changedValueNumber += 1
                        else:
                            pathOfParentDirectory = str(
                                self.values[rowNo]["pathOfParentDirectory"])
                            baseName = str(self.values[rowNo]["baseName"])
                            if self.isChangeableItem(
                                    rowNo,
                                    "sourceCover") or self.isChangeableItem(
                                        rowNo, "destinationCover"):
                                sourcePath = self.values[rowNo]["sourceCover"]
                                destinationPath = self.values[rowNo][
                                    "destinationCover"]
                                if self.isChangeableItem(rowNo, "sourceCover"):
                                    sourcePath = str(
                                        self.item(rowNo, 3).text()).strip()
                                if self.isChangeableItem(
                                        rowNo, "destinationCover"):
                                    destinationPath = str(
                                        self.item(rowNo, 4).text()).strip()
                                if (str(self.item(rowNo,
                                                  2).text()) != sourcePath
                                        or sourcePath != destinationPath
                                        or str(self.item(rowNo, 2).text()) !=
                                        destinationPath
                                    ) or (str(self.item(rowNo, 2).text()) !=
                                          self.values[rowNo]["currentCover"]
                                          and
                                          (str(self.item(rowNo, 2).text()) !=
                                           sourcePath
                                           and str(self.item(rowNo, 2).text())
                                           != destinationPath)):
                                    if str(self.item(rowNo,
                                                     3).text()).strip() != "":
                                        sourcePath = fu.getRealPath(
                                            sourcePath,
                                            self.values[rowNo]["path"])
                                        sourcePath = fu.checkSource(
                                            sourcePath, "file")
                                        if sourcePath is not None:
                                            if destinationPath != "":
                                                destinationPath = fu.getRealPath(
                                                    destinationPath,
                                                    self.values[rowNo]["path"])
                                                if sourcePath != destinationPath:
                                                    destinationPath = fu.moveOrChange(
                                                        sourcePath,
                                                        destinationPath)
                                            else:
                                                destinationPath = sourcePath
                                            fu.setIconToDirectory(
                                                self.values[rowNo]["path"],
                                                destinationPath)
                                            self.changedValueNumber += 1
                                    else:
                                        fu.setIconToDirectory(
                                            self.values[rowNo]["path"], "")
                                        self.changedValueNumber += 1
                            if self.isChangeableItem(rowNo,
                                                     "baseNameOfDirectory",
                                                     pathOfParentDirectory):
                                pathOfParentDirectory = str(
                                    self.item(rowNo, 0).text())
                                self.changedValueNumber += 1
                            if self.isChangeableItem(rowNo, "baseName",
                                                     baseName, False):
                                baseName = str(self.item(rowNo, 1).text())
                                self.changedValueNumber += 1
                            newFilePath = fu.joinPath(pathOfParentDirectory,
                                                      baseName)
                            oldFilePath = fu.getRealPath(
                                self.values[rowNo]["path"])
                            newFilePath = fu.getRealPath(newFilePath)
                            if oldFilePath != newFilePath:
                                oldAndNewPaths = {}
                                oldAndNewPaths["oldPath"] = oldFilePath
                                oldAndNewPaths["newPath"] = fu.moveOrChange(
                                    oldFilePath, newFilePath, "directory")
                                if oldFilePath != oldAndNewPaths["newPath"]:
                                    oldAndNewPathValues.append(oldAndNewPaths)
                                    oldDirName = fu.getDirName(oldFilePath)
                                    if uni.getBoolValue(
                                            "isClearEmptyDirectoriesWhenFileMove"
                                    ):
                                        fu.checkEmptyDirectories(
                                            oldDirName, True, True,
                                            uni.getBoolValue(
                                                "isAutoCleanSubFolderWhenFileMove"
                                            ))
                except:
                    ReportBug.ReportBug()
            else:
                allItemNumber = rowNo + 1
            Dialogs.showState(
                translate("FileUtils/Covers", "Writing Cover Informations"),
                rowNo + 1, allItemNumber, True)
            if isContinueThreadAction is False:
                break
        uni.finishThreadAction()
        if len(oldAndNewPathValues) > 0:
            from Amarok import Operations

            Operations.changePaths(oldAndNewPathValues)
        return True
    def writeContents(self):
        self.changedValueNumber = 0
        oldAndNewPathValues = []
        startRowNo, rowStep = 0, 1
        uni.startThreadAction()
        allItemNumber = len(self.values)
        Dialogs.showState(translate("FileUtils/Covers", "Writing Cover Informations"), 0, allItemNumber, True)
        for rowNo in range(startRowNo, self.rowCount(), rowStep):
            isContinueThreadAction = uni.isContinueThreadAction()
            if isContinueThreadAction:
                try:
                    if fu.isWritableFileOrDir(self.values[rowNo]["path"], False, True):
                        if self.isRowHidden(rowNo):
                            fu.removeFileOrDir(self.values[rowNo]["path"])
                            self.changedValueNumber += 1
                        else:
                            pathOfParentDirectory = str(
                                self.values[rowNo]["pathOfParentDirectory"])
                            baseName = str(self.values[rowNo]["baseName"])
                            if self.isChangeableItem(rowNo, "sourceCover") or self.isChangeableItem(rowNo, "destinationCover"):
                                sourcePath = self.values[rowNo]["sourceCover"]
                                destinationPath = self.values[rowNo]["destinationCover"]
                                if self.isChangeableItem(rowNo, "sourceCover"):
                                    sourcePath = str(self.item(rowNo, 3).text()).strip()
                                if self.isChangeableItem(rowNo, "destinationCover"):
                                    destinationPath = str(self.item(rowNo, 4).text()).strip()
                                if (str(self.item(rowNo,
                                                  2).text()) != sourcePath or sourcePath != destinationPath or str(
                                    self.item(rowNo, 2).text()) != destinationPath) or (
                                            str(self.item(rowNo, 2).text()) !=
                                            self.values[rowNo]["currentCover"] and (
                                                str(self.item(rowNo, 2).text()) != sourcePath and str(
                                            self.item(rowNo, 2).text()) != destinationPath)):
                                    if str(self.item(rowNo, 3).text()).strip() != "":
                                        sourcePath = fu.getRealPath(sourcePath,
                                                                    self.values[rowNo]["path"])
                                        sourcePath = fu.checkSource(sourcePath, "file")
                                        if sourcePath is not None:
                                            if destinationPath != "":
                                                destinationPath = fu.getRealPath(destinationPath,
                                                                                 self.values[
                                                                                     rowNo]["path"])
                                                if sourcePath != destinationPath:
                                                    destinationPath = fu.moveOrChange(sourcePath, destinationPath)
                                            else:
                                                destinationPath = sourcePath
                                            fu.setIconToDirectory(self.values[rowNo]["path"],
                                                                  destinationPath)
                                            self.changedValueNumber += 1
                                    else:
                                        fu.setIconToDirectory(self.values[rowNo]["path"], "")
                                        self.changedValueNumber += 1
                            if self.isChangeableItem(rowNo, "baseNameOfDirectory", pathOfParentDirectory):
                                pathOfParentDirectory = str(self.item(rowNo, 0).text())
                                self.changedValueNumber += 1
                            if self.isChangeableItem(rowNo, "baseName", baseName, False):
                                baseName = str(self.item(rowNo, 1).text())
                                self.changedValueNumber += 1
                            newFilePath = fu.joinPath(pathOfParentDirectory, baseName)
                            oldFilePath = fu.getRealPath(self.values[rowNo]["path"])
                            newFilePath = fu.getRealPath(newFilePath)
                            if oldFilePath != newFilePath:
                                oldAndNewPaths = {}
                                oldAndNewPaths["oldPath"] = oldFilePath
                                oldAndNewPaths["newPath"] = fu.moveOrChange(oldFilePath, newFilePath, "directory")
                                if oldFilePath != oldAndNewPaths["newPath"]:
                                    oldAndNewPathValues.append(oldAndNewPaths)
                                    oldDirName = fu.getDirName(oldFilePath)
                                    if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"):
                                        fu.checkEmptyDirectories(oldDirName, True, True,
                                                                 uni.getBoolValue("isAutoCleanSubFolderWhenFileMove"))
                except:
                    ReportBug.ReportBug()
            else:
                allItemNumber = rowNo + 1
            Dialogs.showState(translate("FileUtils/Covers", "Writing Cover Informations"), rowNo + 1, allItemNumber,
                              True)
            if isContinueThreadAction is False:
                break
        uni.finishThreadAction()
        if len(oldAndNewPathValues) > 0:
            from Amarok import Operations

            Operations.changePaths(oldAndNewPathValues)
        return True
Example #4
0
 def writeContents(self):
     self.changedValueNumber = 0
     oldAndNewPathValues = []
     isNewDirectoriesSame = True
     isMovedToNewDirectory = False
     currentDirectoryPath = ""
     newDirectoryPath = ""
     startRowNo, rowStep = 0, 1
     uni.startThreadAction()
     allItemNumber = len(self.values)
     Dialogs.showState(translate("FileUtils/Covers", "Writing Cover Informations"), 0, allItemNumber, True)
     for rowNo in range(startRowNo, self.rowCount(), rowStep):
         isContinueThreadAction = uni.isContinueThreadAction()
         if isContinueThreadAction:
             try:
                 if fu.isWritableFileOrDir(self.values[rowNo]["path"], False, True):
                     if self.isRowHidden(rowNo):
                         fu.removeFileOrDir(self.values[rowNo]["path"])
                         self.changedValueNumber += 1
                     else:
                         baseNameOfDirectory = str(
                             self.values[rowNo]["baseNameOfDirectory"])
                         baseName = str(self.values[rowNo]["baseName"])
                         if (self.isChangeableItem(rowNo, "sourceCover") or
                                 self.isChangeableItem(rowNo, "destinationCover")):
                             sourcePath = self.values[rowNo]["sourceCover"]
                             destinationPath = self.values[rowNo]["destinationCover"]
                             if self.isChangeableItem(rowNo, "sourceCover"):
                                 sourcePath = str(self.item(rowNo, 3).text()).strip()
                             if self.isChangeableItem(rowNo, "destinationCover"):
                                 destinationPath = str(self.item(rowNo, 4).text()).strip()
                             if (str(self.item(rowNo,
                                               2).text()) != sourcePath or sourcePath != destinationPath or str(
                                 self.item(rowNo, 2).text()) != destinationPath) or (
                                         str(self.item(rowNo, 2).text()) !=
                                         self.values[rowNo]["currentCover"] and (
                                             str(self.item(rowNo, 2).text()) != sourcePath and str(
                                         self.item(rowNo, 2).text()) != destinationPath)):
                                 if str(self.item(rowNo, 3).text()).strip() != "":
                                     sourcePath = fu.getRealPath(sourcePath,
                                                                 self.values[rowNo]["path"])
                                     sourcePath = fu.checkSource(sourcePath, "file")
                                     if sourcePath is not None:
                                         if destinationPath != "":
                                             destinationPath = fu.getRealPath(destinationPath,
                                                                              self.values[
                                                                                  rowNo]["path"])
                                             if sourcePath != destinationPath:
                                                 destinationPath = fu.moveOrChange(sourcePath, destinationPath)
                                         else:
                                             destinationPath = sourcePath
                                         fu.setIconToDirectory(self.values[rowNo]["path"],
                                                               destinationPath)
                                         self.changedValueNumber += 1
                                 else:
                                     fu.setIconToDirectory(self.values[rowNo]["path"], "")
                                     self.changedValueNumber += 1
                         if self.isChangeableItem(rowNo, "baseNameOfDirectory", baseNameOfDirectory):
                             baseNameOfDirectory = str(self.item(rowNo, 0).text())
                             self.changedValueNumber += 1
                             isMovedToNewDirectory = True
                             currentDirectoryPath = fu.getDirName(
                                 self.values[rowNo]["path"])
                             newDirectoryPath = fu.joinPath(
                                 fu.getDirName(fu.getDirName(self.values[rowNo]["path"])),
                                 baseNameOfDirectory)
                             self.setNewDirectory(newDirectoryPath)
                             if rowNo > 0:
                                 if str(self.item(rowNo - 1, 0).text()) != baseNameOfDirectory:
                                     isNewDirectoriesSame = False
                         if self.isChangeableItem(rowNo, "baseName", baseName, False):
                             baseName = str(self.item(rowNo, 1).text())
                             self.changedValueNumber += 1
                         newFilePath = fu.joinPath(
                             fu.getDirName(fu.getDirName(self.values[rowNo]["path"])),
                             baseNameOfDirectory, baseName)
                         oldFilePath = fu.getRealPath(self.values[rowNo]["path"])
                         newFilePath = fu.getRealPath(newFilePath)
                         if oldFilePath != newFilePath:
                             oldAndNewPaths = {}
                             oldAndNewPaths["oldPath"] = oldFilePath
                             oldAndNewPaths["newPath"] = fu.moveOrChange(oldFilePath, newFilePath, "directory")
                             if oldFilePath != oldAndNewPaths["newPath"]:
                                 oldAndNewPathValues.append(oldAndNewPaths)
                                 oldDirName = fu.getDirName(oldFilePath)
                                 if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"):
                                     fu.checkEmptyDirectories(oldDirName, True, True,
                                                              uni.getBoolValue("isAutoCleanSubFolderWhenFileMove"))
             except:
                 ReportBug.ReportBug()
         else:
             allItemNumber = rowNo + 1
         Dialogs.showState(translate("FileUtils/Covers", "Writing Cover Informations"), rowNo + 1, allItemNumber,
                           True)
         if isContinueThreadAction is False:
             break
     uni.finishThreadAction()
     if self.rowCount() == len(oldAndNewPathValues) and isMovedToNewDirectory and isNewDirectoriesSame:
         otherFileNames = fu.readDirectory(currentDirectoryPath, "fileAndDirectory", True)
         if len(otherFileNames) > 0:
             answer = Dialogs.ask(translate("FileUtils/Musics", "There Are More Files"),
                                  str(translate("FileUtils/Musics",
                                                "\"%s\" : there are more files in this directory.<br>Are you want to move all found files into new directory?<br>New Directory : \"%s\"")) % (
                                      Organizer.getLink(currentDirectoryPath), Organizer.getLink(newDirectoryPath)))
             if answer == Dialogs.Yes:
                 uni.startThreadAction()
                 allItemNumber = len(otherFileNames)
                 for rowNo, fileName in enumerate(otherFileNames):
                     isContinueThreadAction = uni.isContinueThreadAction()
                     if isContinueThreadAction:
                         try:
                             oldFilePath = fu.getRealPath(fu.joinPath(currentDirectoryPath, fileName))
                             newFilePath = fu.getRealPath(fu.joinPath(newDirectoryPath, fileName))
                             if oldFilePath != newFilePath:
                                 oldAndNewPaths = {}
                                 oldAndNewPaths["oldPath"] = oldFilePath
                                 oldAndNewPaths["newPath"] = fu.moveOrChange(oldFilePath, newFilePath,
                                                                             fu.getObjectType(oldFilePath))
                                 if oldFilePath != oldAndNewPaths["newPath"]:
                                     oldAndNewPathValues.append(oldAndNewPaths)
                         except:
                             ReportBug.ReportBug()
                     else:
                         allItemNumber = rowNo + 1
                     Dialogs.showState(translate("FileUtils/Covers", "Writing Directory And File Informations"),
                                       rowNo + 1, allItemNumber, True)
                     if isContinueThreadAction is False:
                         break
                 uni.finishThreadAction()
                 if uni.getBoolValue("isClearEmptyDirectoriesWhenFileMove"):
                     fu.checkEmptyDirectories(currentDirectoryPath, True, True,
                                              uni.getBoolValue("isAutoCleanSubFolderWhenFileMove"))
                 if (uni.isActiveDirectoryCover and uni.getBoolValue("isActiveAutoMakeIconToDirectory") and
                         uni.getBoolValue("isAutoMakeIconToDirectoryWhenFileMove")):
                     fu.checkIcon(newDirectoryPath)
     return True