def runExportJobs(inDirectory, tempDirectory): listJob = [ o for o in os.listdir(tempDirectory) if (os.path.isfile(os.path.join(tempDirectory, o)) and o.endswith('.fej')) ] allArray = [] if len(listJob) > 0: allArray = ["All"] dirChoiceList = allArray + listJob + ["Return to Main menu"] theRunDirectoryChoice = 0 while (theRunDirectoryChoice != -1 and theRunDirectoryChoice != (len(dirChoiceList) - 1)): targetedJob = [] theRunDirectoryChoice = InteractionUtils.query_choice_list( "Choose the targeted directory(ies).", dirChoiceList, True) if (theRunDirectoryChoice > 0 and theRunDirectoryChoice != (len(dirChoiceList) - 1)): targetedJob.append(listJob[theRunDirectoryChoice - 1]) elif theRunDirectoryChoice == 0: targetedJob = listJob elif (theRunDirectoryChoice == -1 or theRunDirectoryChoice == (len(dirChoiceList) - 1)): break for aJobFile in targetedJob: excludedEpisodePath = os.path.join(tempDirectory, aJobFile[:-4] + '.ejd') jobListPath = os.path.join(tempDirectory, aJobFile) excludedEpisode = FileUtils.importFileOrCreateArray( excludedEpisodePath) jobList = FileUtils.importFileOrCreateDict(jobListPath) print(jobList) jobListBis = copy.deepcopy(jobList) indexJobList = 1 for src, dest in jobList.items(): print("[" + str(indexJobList) + "/" + str(len(jobList.items())) + "]Move '" + src[14:] + "' to '" + dest + "'.") newDest = os.path.join(dest, src[14:]) oldDest = os.path.join(inDirectory, src) if os.path.exists(newDest) and not filecmp.cmp( oldDest, newDest): os.remove(newDest) if not os.path.exists(newDest): shutil.copy(oldDest, dest) excludedEpisode.append(src[14:]) del jobListBis[src] FileUtils.writeFile(jobListPath, jobListBis) FileUtils.writeFile(excludedEpisodePath, excludedEpisode) indexJobList += 1
def buildExportJobs(inDirectory, outDirectory, tempDirectory): listDir = [ o for o in os.listdir(inDirectory) if (os.path.isdir(os.path.join(inDirectory, o)) and re.search( "[0-9][0-9][0-9][0-9][0-9][0-9]_[0-9][0-9][0-9][0-9][0-9][0-9]", o) ) ] allArray = [] targetedArray = [] if len(listDir) > 0: allArray = ["All"] dirChoiceList = allArray + listDir + ["Return to Main menu"] theBuildDirectoryChoice = 0 while (theBuildDirectoryChoice != -1 and theBuildDirectoryChoice != (len(dirChoiceList) - 1)): theBuildDirectoryChoice = InteractionUtils.query_choice_list( "Choose the targeted directory(ies).", dirChoiceList, True) if (theBuildDirectoryChoice > 0 and theBuildDirectoryChoice != (len(dirChoiceList) - 1)): targetedArray.append(listDir[theBuildDirectoryChoice - 1]) elif theBuildDirectoryChoice == 0: targetedArray = listDir elif (theBuildDirectoryChoice == -1 or theBuildDirectoryChoice == (len(dirChoiceList) - 1)): break for aDir in targetedArray: print( "##########################################################################" ) print("We build the export Jobs for directory '" + aDir + "' with file '" + aDir + ".fej'") exportJobDoneFileName = os.path.join(tempDirectory, aDir + ".ejd") jobOrderFileName = os.path.join(tempDirectory, aDir + ".fej") associationTable = FileUtils.importFileOrCreateDict( jobOrderFileName) excludedArray = FileUtils.importFileOrCreateArray( exportJobDoneFileName) aWeekDirPath = os.path.join(inDirectory, aDir) listEpisode = [ o for o in os.listdir(aWeekDirPath) if (os.path.isfile(os.path.join(aWeekDirPath, o)) and not o.endswith('.srt')) ] for anEpisode in listEpisode: if (anEpisode not in excludedArray and os.path.join( aDir, anEpisode) not in associationTable.keys()): episodeChoiceList = [ "Build export for this episode", "Skip the episode", "Ignore the episode", "Return to folder choice" ] exportAnswer = int( InteractionUtils.query_choice_list( "Choose your action for '" + anEpisode + "'.", episodeChoiceList, True)) if exportAnswer == 0: buildJobForEpisode(aDir, anEpisode, associationTable, outDirectory) elif exportAnswer == 2: excludedAnEpisode(anEpisode, excludedArray, aWeekDirPath) elif exportAnswer == 3: break FileUtils.writeFile(jobOrderFileName, associationTable) FileUtils.writeFile(exportJobDoneFileName, excludedArray)