def gatherMetadata(self): """Iterate through Finders until success or stagnation.""" while self.queue: for finder in self.queue: field = finder.fieldName with logSection("\nAttempting to determine the %s using %d sources." % (field, len(finder.getters))): success = finder.run(self.release) if not success: log("Failed to determine the %s. Will try again next round.\n" % field) self.nextRoundQueue.append(finder) else: log("Successfully determined the %s.\n" % field) if self.queue == self.nextRoundQueue: log("No progress has been made. The metadata gathering process " "has failed.\n") failedFields = [finder.fieldName for finder in self.queue] raise ReleaseManagerError, "Unable to determine: %s" % failedFields else: self.queue = self.nextRoundQueue self.nextRoundQueue = []
def run(self, release): """Gather track-specific data and find a consensus.""" results = [] for track in release.tracks: with logSection("Attempting to determine %s for %s." % (self.fieldName, quote(track.fileName))): data = [] for (getter, weight) in self.getters: flowcontrol.checkpoint() log(" ") data.append((getter(track), weight, getter.__name__, quote(track.fileName))) self.logResults(data) consensus = self.findConsensus(data) log("\n\n\n") if consensus: results.append((track, consensus)) else: return False log(" ") for (track, consensus) in results: track.storeData(self.fieldName, consensus) return True
def gatherMetadata(self): """Iterate through Finders until success or stagnation.""" while self.queue: for finder in self.queue: field = finder.fieldName with logSection( "\nAttempting to determine the %s using %d sources." % (field, len(finder.getters))): success = finder.run(self.release) if not success: log("Failed to determine the %s. Will try again next round.\n" % field) self.nextRoundQueue.append(finder) else: log("Successfully determined the %s.\n" % field) if self.queue == self.nextRoundQueue: log("No progress has been made. The metadata gathering process " "has failed.\n") failedFields = [finder.fieldName for finder in self.queue] raise ReleaseManagerError, "Unable to determine: %s" % failedFields else: self.queue = self.nextRoundQueue self.nextRoundQueue = []
def traverse(directoryPath): """Recursively traverse directories.""" flowcontrol.checkpoint(cleanStopPoint=True) if not functions.validatePath(directoryPath, isDirectory=True): return subdirectoryPaths = functions.getValidSubdirectories(directoryPath) # If appropriate, rename and recurse into subdirectories if subdirectoryPaths: for subdirectoryPath in clean.standardizeFilenames(subdirectoryPaths): traverse(subdirectoryPath) # We are now in a leaf directory with no subdirectories. with logSection("\nHandling %s." % quote(directoryPath)): handleDirectory(directoryPath)
def handleIt(): """Call traverse on directories; when run ends for any reason, inform GUI.""" cache.loadCacheDB() try: for directoryPath in configuration.PATHS["TO_SCAN"]: with logSection("Traversing %s." % quote(directoryPath)): configuration.PATHS["CURRENT"] = directoryPath traverse(directoryPath) except flowcontrol.StopException: if gui: emitter.emit(SIGNAL("RunEnded"), "stopped") except: traceback.print_exc() if gui: emitter.emit(SIGNAL("RunEnded"), "failed") else: if gui: emitter.emit(SIGNAL("RunEnded"), "complete") cache.saveCacheDB()
def convert(audioFilePaths): """Convert undesirable audio formats into ogg. Takes a list of audio files and converts each to ogg using appropriate commands. These commands (mac, oggenc, mpc123) must be present.""" for audioFilePath in audioFilePaths: fileName = os.path.basename(audioFilePath) with logSection("Converting %s." % quote(fileName)): filePathWithoutExtension, extension = os.path.splitext( audioFilePath) commands = convertorCommands[extension] success = True for command in commands: cmd = [ arg.replace("$$", filePathWithoutExtension) for arg in command ] log(" ".join(cmd)) try: p = subprocess.Popen(cmd) p.wait() except OSError: log("% command not found." % cmd[0]) success = False break if p.returncode != 0: success = False break if not success: # FIXME: Should we reject this file or this entire directory? log("Unable to convert %s." % quote(fileName)) functions.rejectItem(audioFilePath) else: functions.deleteItem(audioFilePath) if len(commands) > 1: # If we created an intermediate wav file functions.deleteItem(filePathWithoutExtension + ".wav", True)
def extract(archivePaths): """Extract archives using appropriate utility. Takes a list of paths to archives and for each: Creates a directory with the same name as the archive, without extension. Chooses the utility to use for extraction based on the archive's extension. Attempts to extract the archive into the newly created directory. If the extraction fails, the directory is deleted and the archive rejected. If the extraction succeeds, the archive is discarded.""" for archivePath in archivePaths: fileName = os.path.basename(archivePath) with logSection("Extracting %s." % quote(fileName)): destDirectoryPath, ext = os.path.splitext(archivePath) if not os.path.exists(destDirectoryPath): os.mkdir(destDirectoryPath) command = extractorCommands[ext.lower()][:] for (i, arg) in enumerate(command): if arg == "$a": command[i] = archivePath elif arg == "$d": command[i] = destDirectoryPath log(" ".join(command)) try: p = subprocess.Popen(command) p.wait() success = p.returncode == 0 except OSError: log("%s command not found." % command[0]) success = False if not success: log("Unable to extract %s." % quote(archivePath)) functions.deleteItem(destDirectoryPath) functions.rejectItem(archivePath) else: functions.deleteItem(archivePath)
def convert(audioFilePaths): """Convert undesirable audio formats into ogg. Takes a list of audio files and converts each to ogg using appropriate commands. These commands (mac, oggenc, mpc123) must be present.""" for audioFilePath in audioFilePaths: fileName = os.path.basename(audioFilePath) with logSection("Converting %s." % quote(fileName)): filePathWithoutExtension, extension = os.path.splitext(audioFilePath) commands = convertorCommands[extension] success = True for command in commands: cmd = [arg.replace("$$", filePathWithoutExtension) for arg in command] log(" ".join(cmd)) try: p = subprocess.Popen(cmd) p.wait() except OSError: log("% command not found." % cmd[0]) success = False break if p.returncode != 0: success = False break if not success: # FIXME: Should we reject this file or this entire directory? log("Unable to convert %s." % quote(fileName)) functions.rejectItem(audioFilePath) else: functions.deleteItem(audioFilePath) if len(commands) > 1: # If we created an intermediate wav file functions.deleteItem(filePathWithoutExtension + ".wav", True)
def run(self, release): """Gather release data and find a consensus.""" data = [] for track in release.tracks: with logSection("\nActing on track %s." % quote(track.fileName)): for (getter, weight) in self.getters: flowcontrol.checkpoint() log(" ") data.append((getter(track), weight, getter.__name__, quote(track.fileName))) self.logResults(data) consenus = self.findConsensus(data) log("\n\n\n") if consenus: release.storeData(self.fieldName, consenus) return True else: return False