def handleDirectory(directoryPath): """Take actions based on file types present and the user's configuration.""" filePathsByType = functions.getFilePathsByType(directoryPath) if configuration.ACTIONS["IMAGE"] and "image" in filePathsByType: # Rename/delete image(s) clean.handleImages(filePathsByType["image"]) if configuration.ACTIONS["CLEAN"] and "other" in filePathsByType: # Delete extra files clean.cleanDir(filePathsByType["other"]) if configuration.ACTIONS["EXTRACT"] and "archive" in filePathsByType: # Extract archives extract.extract(filePathsByType["archive"]) # There may be new subdirectories return traverse(directoryPath) # Traverse again if configuration.ACTIONS["CONVERT"] and "bad_audio" in filePathsByType: # Convert audio to Ogg and scan again convert.convert(filePathsByType["bad_audio"]) return handleDirectory(directoryPath) if not "good_audio" in filePathsByType: # Continue if audio present log("\nNo audio found in %s." % quote(directoryPath)) # FIXME: If the user has not requested the metadata process, should this # directory actually be accepted rather than deleted at this point? if directoryPath != configuration.PATHS["CURRENT"]: functions.deleteItem(directoryPath) return if configuration.ACTIONS["SPLIT"] and "cue" in filePathsByType: # Split based on cue and scan again split.split(filePathsByType["cue"], filePathsByType["good_audio"]) return handleDirectory(directoryPath) if configuration.ACTIONS["METADATA"]: # Handle metadata audioPaths = clean.standardizeFilenames(filePathsByType["good_audio"]) metadata.handleMetadata(directoryPath, audioPaths)
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)