Example #1
0
    def testNoOptionsSpecified(self):
        argumentsList = ["organize"]

        loader = OptionsLoader()
        options = loader.loadFromArguments(argumentsList)
        
        self.verifyOptionsAreDefaultValues(options)
Example #2
0
def Main():
    # Parse command line arguments into program options
    optionsLoader = OptionsLoader()
    options = optionsLoader.loadFromArguments(sys.argv)

    view = ConsoleView()

    if options.startGuiMode:
        print "Gui mode not implemented yet."
        return
    
    directory = options.rootDirectory
    if not os.path.isdir(directory):
        view.displayLine("Directory not found")
        return

    view.displayLine("Directory to organize is {0}".format(directory))
    view.displayLine("Retrieving all MP3 files...")
    
    fileSource = FileSource(directory, options.followSymbolicLinks)
    filter = Mp3FileFilter(fileSource)
    mp3files = filter.getFiles()

    view.displayLine("Directory contains {0} MP3 files".format(len(mp3files)))
    
    tempFolder = os.path.join(directory, str(uuid.uuid4()))
    view.displayLine("Moving files to temporary location {0}...".format(tempFolder))

    mover = FileMover(mp3files, tempFolder)
    tempFiles = mover.move()

    view.displayLine("Finding non MP3 files...")

    nonMp3FilesFilter = NonMp3FileFilter(fileSource)
    nonMp3Files = nonMp3FilesFilter.getFiles()

    if options.backupLocation is not None and os.path.isdir(options.backupLocation):
        view.displayLine("Backing up {0} non-MP3 files to {1}".format(len(nonMp3Files), options.backupLocation))
        backupMover = FileMover(nonMp3Files, options.backupLocation)
        backupMover.move()
    else:
        view.displayLine("Directory contains {0} non-MP3 files. Deleting...".format(len(nonMp3Files)))
        for file in nonMp3Files:
            os.remove(file)

    view.displayLine("Organizing files...")

    organizer = Organizer(tempFiles, directory)
    organizer.organize()

    view.displayLine("Removing empty directories...")

    dirRemover = EmptyDirectoryRemover(directory)
    dirRemover.remove()

    view.displayLine("Done!")
Example #3
0
    def testGuiModeOption(self):
        expectedFlagValue = True
        shortArguments = ["organize", "-g"]
        longArguments = ["organize", "--gui"]
        loader = OptionsLoader()

        options = loader.loadFromArguments(shortArguments)
        self.assertEqual(expectedFlagValue, options.startGuiMode, "Gui Mode flag not activated")

        options = loader.loadFromArguments(longArguments)
        self.assertEqual(expectedFlagValue, options.startGuiMode, "Gui Mode flag not activated")
Example #4
0
    def testFollowLinksOption(self):
        expectedFlagValue = True
        shortArguments = ["organize", "-f"]
        longArguments = ["organize", "--followLinks"]
        loader = OptionsLoader()

        options = loader.loadFromArguments(shortArguments)
        self.assertEqual(expectedFlagValue, options.followSymbolicLinks, "Follow Symbolic Links flag not activated")

        options = loader.loadFromArguments(longArguments)
        self.assertEqual(expectedFlagValue, options.followSymbolicLinks, "Follow Symbolic Links flag not activated")
Example #5
0
    def testBackupOption(self):
        expectedDirectoryValue = "~/backups/"
        shortArguments = ["organize", "-b", expectedDirectoryValue]
        longArguments = ["organize", "--backup", expectedDirectoryValue]
        loader = OptionsLoader()

        options = loader.loadFromArguments(shortArguments)
        self.assertEqual(expectedDirectoryValue, options.backupLocation, "Backup directory option value mismatch")

        options = loader.loadFromArguments(longArguments)
        self.assertEqual(expectedDirectoryValue, options.backupLocation, "Backup directory option value mismatch")
Example #6
0
    def testDirectoryOption(self):
        expectedDirectoryValue = "~/music/"
        shortArguments = ["organize", "-d", expectedDirectoryValue]
        longArguments = ["organize", "--directory", expectedDirectoryValue]
        loader = OptionsLoader()

        options = loader.loadFromArguments(shortArguments)
        self.assertEqual(expectedDirectoryValue, options.rootDirectory, "Root directory option value mismatch")

        options = loader.loadFromArguments(longArguments)
        self.assertEqual(expectedDirectoryValue, options.rootDirectory, "Root directory option value mismatch")
Example #7
0
    def testAllOptionsSpecified(self):
        expectedDirectory = "~/downloads/music"
        expectedBackupDirectory = "~/backups"
        expectedGuiModeFlag = True
        expectedFollowLinksFlag = True

        argumentsList = ["organize", "-gf", "-d", expectedDirectory, "-b", expectedBackupDirectory]

        loader = OptionsLoader()
        options = loader.loadFromArguments(argumentsList)

        self.assertEqual(expectedGuiModeFlag, options.startGuiMode, "Gui Mode flag not activated")
        self.assertEqual(expectedFollowLinksFlag, options.followSymbolicLinks, "Follow Symbolic Links flag not activated")
        self.assertEqual(expectedDirectory, options.rootDirectory, "Root directory option value mismatch")
        self.assertEqual(expectedBackupDirectory, options.backupLocation, "Backup directory option value mismatch")