Esempio n. 1
0
    def test_not_a_dir__classify__empty_iter(self):
        #Arrange:
        clsfr = FilesClassifier(self.__files_selector_mock)

        #Act:
        clsfr.classify(__file__)

        #Assert:
        msg = "expected no elemnts in clsfr"
        self.assertEqual(len(clsfr._FilesClassifier__files_dict), 0, msg)
Esempio n. 2
0
    def test_only_files__classify__iter_not_empty(self):
        #Arrange:
        FilesSelectorMock.files = ["file1.txt", "file2.txt"]
        clsfr = FilesClassifier(self.__files_selector_mock)

        #Act:
        clsfr.classify(os.getcwd())

        #Assert:
        msg = "expected 1 key in clsfr"
        self.assertEqual(len(clsfr._FilesClassifier__files_dict), 1, msg)
Esempio n. 3
0
    def test_two_calls__classify_by_day__no_duplication(self):
        #Arrange:
        # This test makes sure internal clean before classify.
        expected_keys = 8
        expected_values = 9
        fs = DateFilesSelector()
        clsfr = FilesClassifier(fs)

        #Act:
        clsfr.classify(self.__rootdir)
        clsfr.classify(self.__rootdir)

        #Assert:
        msg = "expected {} keys in clsfr".format(expected_keys)
        self.assertEqual(len(clsfr._FilesClassifier__files_dict),
                         expected_keys, msg)
        total = sum(1 for _ in clsfr)
        msg = "expected {} values in clsfr".format(expected_values)
        self.assertEqual(expected_values, total, msg)
Esempio n. 4
0
    def test_files_and_dirs__classify_by_year__iter_not_empty(self):
        #Arrange:
        # The package comes with 9 files divided to 3 different years.
        # Which means in this test there will be 3 keys.
        expected_keys = 3
        expected_values = 9
        fs = DateFilesSelector("year")
        clsfr = FilesClassifier(fs)

        #Act:
        clsfr.classify(self.__rootdir)

        #Assert:
        msg = "expected {} keys in clsfr".format(expected_keys)
        self.assertEqual(len(clsfr._FilesClassifier__files_dict),
                         expected_keys, msg)
        total = sum(1 for _ in clsfr)
        msg = "expected {} values in clsfr".format(expected_values)
        self.assertEqual(expected_values, total, msg)
Esempio n. 5
0
    def test_files_and_dirs__classify_by_day__iter_not_empty(self):
        #Arrange:
        # The package comes with 9 files where 2 of them has exactly the same
        # modified date (a03.txt & a01.txt).
        # Which means in this test there will be 8 elements
        # because the test classify by modified day.
        expected_keys = 8
        expected_values = 9
        fs = DateFilesSelector()
        clsfr = FilesClassifier(fs)

        #Act:
        clsfr.classify(self.__rootdir)

        #Assert:
        msg = "expected {} keys in clsfr".format(expected_keys)
        self.assertEqual(len(clsfr._FilesClassifier__files_dict),
                         expected_keys, msg)
        total = sum(1 for _ in clsfr)
        msg = "expected {} values in clsfr".format(expected_values)
        self.assertEqual(expected_values, total, msg)
Esempio n. 6
0
rootdir = args.root_dir
strategy = args.strategy

if ((not os.path.isdir(rootdir)) or (not os.path.exists(rootdir))):
    raise FileNotFoundError("No such directory: " + rootdir)
else:
    rootdir = os.path.abspath(rootdir)

outdir = rootdir  #set default
if args.outdir:
    outdir = args.outdir

if (not os.path.exists(outdir)):
    print("Outdir " + outdir + " does not exist. Trying to create...")
    try:
        os.makedirs(outdir)
    except OSError as e:
        raise
else:
    outdir = os.path.abspath(outdir)

fs = ExifDateFilesSelector(args.strategy)
clsfr = FilesClassifier(fs)
clsfr.classify(rootdir)

for dir_name, file_path in clsfr:
    print("{} {}".format(dir_name, file_path))
    destination_dir = outdir + "\\" + dir_name
    base_name = os.path.basename(file_path)
    os.renames(file_path, destination_dir + "\\" + base_name)