def test_untag_frontend_cli_files_long(self):
     opts = RunOptions(["untag", "tag 1", "tag 2", "--files", "foo", "bar"])
     self.assertEqual(Action.untag, opts.action)
     self.assertEqual(["tag 1", "tag 2"], opts.tags)
     self.assertEqual(False, opts.needs_tags(), "needs tags")
     self.assertEqual(["foo", "bar"], opts.files, "needs files")
     self.assertEqual(FrontendType.cli, opts.frontend)
 def test_query(self):
     opts = RunOptions(["query", "tag 1", "tag 2"])
     self.assertEqual(Action.query, opts.action)
     self.assertEqual(["tag 1", "tag 2"], opts.tags)
     self.assertEqual(False, opts.needs_tags(), "needs tags")
     self.assertEqual(FrontendType.cli, opts.frontend)
     self.assertEqual(MatchType.all, opts.match_type)
Exemple #3
0
def _check_tags(core: TieCore, front_end: Frontend, run_options: RunOptions):
    if run_options.needs_tags():
        if run_options.action == Action.untag:
            _check_tags_untag(core, front_end, run_options)
        else:
            run_options.tags = front_end.get_tags(
                core.list_all_tags(), run_options.allows_tag_creation())
        if len(run_options.tags) == 0:
            raise ParseError("Cannot execute command \"" +
                             run_options.action.name +
                             "\" with empty tags list")
Exemple #4
0
 def test_index(self):
     core = TieCoreTestImpl(Action.index, [], ["testfile1", "testfile2"])
     tie_main.run(core,
                  RunOptions(["index", "-f", "testfile1",
                              "testfile2"]), self.frontend)
     self.assertTrue(core.was_called_correctly(),
                     "core was called incorrectly")
Exemple #5
0
def _check_tags_untag(core, front_end: Frontend, run_options: RunOptions):
    present_tags = core.list(run_options.files)
    if len(present_tags) == 0:
        raise ParseError("Cannot execute command \"" +
                         run_options.action.name +
                         "\": No tags present on selected files")
    run_options.tags = front_end.get_tags(sorted(list(present_tags)), False)
Exemple #6
0
    def test_untag_interactive(self):
        user_choice = ["foo", "bar"]
        present_tags = ["foo", "bar", "bas"]

        class FrontendAnon(FrontendAdapter):
            def __init__(self):
                super().__init__()
                self.provided_options = []

            def get_tags(self, available_tags: List[str],
                         allow_custom_tags) -> List[str]:
                self.provided_options = available_tags
                return user_choice

        class TieCoreTestInteractiveUntag(TieCoreAdapter):
            def __init__(self):
                self.untagged_file = ""
                self.removed_tags = ""

            def list(self, files: List[str]) -> List[str]:
                return present_tags

            def untag(self, file: str, tags: List[str]):
                self.untagged_file = file
                self.removed_tags = tags

        frontend = FrontendAnon()
        core = TieCoreTestInteractiveUntag()
        tie_main.run(core, RunOptions(["untag", "-f", "testfile1"]), frontend)
        self.assertEqual(sorted(present_tags), frontend.provided_options,
                         "wrong options were provided")
        self.assertEqual(user_choice, core.removed_tags,
                         "wrong tags were removed")
Exemple #7
0
def _setup_tag_invalid_meta_data_file(confirm_nuke):
    exif = ExifEditor(Configuration())
    index = Index(TEST_INDEX_LOCATION, exif)
    core = TieCoreImpl(exif, index)
    cli.run_cmd(["cp", READ_FILE, WRITE_FILE])
    frontend = FrontendTest(confirm_nuke, [])
    tie_main.run(core, RunOptions(["tag", "foo", WRITE_FILE]), frontend)
Exemple #8
0
 def test_tag_white_space(self):
     # Duplicates in constructor calls account for repeated calls to method
     core = TieCoreTestImpl(Action.tag, ["foo"],
                            [WHITE_SPACE_FILE_MD, WHITE_SPACE_FILE_MD])
     tie_main.run(core,
                  RunOptions(["tag", "foo", "-f",
                              WHITE_SPACE_FILE_MD]), self.frontend)
     self.assertTrue(core.was_called_correctly(),
                     "core was called incorrectly")
Exemple #9
0
 def test_untag(self):
     # Duplicates in constructor calls account for repeated calls to method
     core = TieCoreTestImpl(
         Action.untag, ["foo", "bar", "foo", "bar"],
         ["testfile1", "testfile1", "testfile2", "testfile2"])
     tie_main.run(
         core,
         RunOptions(["untag", "foo", "bar", "-f", "testfile1",
                     "testfile2"]), self.frontend)
     self.assertTrue(core.was_called_correctly(),
                     "core was called incorrectly")
Exemple #10
0
    def test_untag_interactive_multiple_files(self):
        user_choice = ["foo", "bas"]
        file_1 = "file1"
        file_2 = "file2"

        class FrontendAnon(FrontendAdapter):
            def __init__(self):
                super().__init__()
                self.provided_options = []

            def get_tags(self, available_tags: List[str],
                         allow_custom_tags) -> List[str]:
                self.provided_options = available_tags
                return user_choice

        class TieCoreTestInteractiveUntag(TieCoreAdapter):
            def __init__(self):
                super().__init__()
                self.untagged_files = list()
                self.removed_tags = list()

            def list(self, files: List[str]) -> List[str]:
                return ["foo", "bar", "bas", "bam"]

            def untag(self, file: str, tags: List[str]):
                self.untagged_files.append(file)
                for t in tags:
                    self.removed_tags.append(t)

        frontend = FrontendAnon()
        core = TieCoreTestInteractiveUntag()
        tie_main.run(core, RunOptions(["untag", "-f", file_1, file_2]),
                     frontend)
        self.assertEqual(sorted(["foo", "bar", "bas",
                                 "bam"]), frontend.provided_options,
                         "wrong options were provided")
        self.assertEqual([file_1, file_2], core.untagged_files,
                         "wrong files untagged")
        self.assertEqual(["foo", "bas", "foo", "bas"], core.removed_tags,
                         "wrong tags were removed")
Exemple #11
0
def main(*args):
    try:
        setup_sys_path()

        configuration = config.load_user_config()

        run_options = RunOptions(list(args[1:]))

        frontend_type = run_options.frontend
        front_end = ff.from_type(frontend_type)

        index_root_dir = configuration.index_path
        exif = ExifEditor(configuration)
        index = Index(index_root_dir, exif)

        core = TieCoreImpl(exif, index)

        if run_options.action == Action.help:
            print_usage()
        else:
            tie_main.run(core, run_options, front_end)

    except ParseError as parse_error:
        printerr("Error: " + parse_error.msg)
        sys.exit(EXIT_CODE_PARSE_ERROR)
    except InvalidMetaDataError as meta_data_error:
        printerr("Error: " + meta_data_error.msg)
        sys.exit(EXIT_CODE_INVALID_META_DATA)
    except KeyboardInterrupt:
        printerr("Application aborted by user")
        sys.exit(EXIT_CODE_INVALID_META_DATA)
    except FileNotFoundError:
        # No need to print it. this is already done by subprocess
        sys.exit(EXIT_CODE_FILE_NOT_FOUND)
    except CalledProcessError:
        # No need to print it. this is already done by subprocess
        sys.exit(EXIT_CODE_UNKNOWN_SUBPROCESS_ERROR)
Exemple #12
0
 def test_query_no_tags_frontend_batch(self):
     opts = RunOptions(["query", "-F", "batch"])
     self.assertEqual(FrontendType.batch, opts.frontend)
     self.assertEqual(MatchType.all, opts.match_type)
Exemple #13
0
 def test_list_no_files_option(self):
     opts = RunOptions(["l", "foo"])
     self.assertEqual(Action.list, opts.action)
     self.assertEqual(["foo"], opts.files)
Exemple #14
0
 def test_query_no_tags(self):
     opts = RunOptions(["query"])
     self.assertEqual(Action.query, opts.action)
     self.assertEqual(True, opts.needs_tags(), "needs tags")
     self.assertEqual(FrontendType.cli, opts.frontend)
     self.assertEqual(MatchType.all, opts.match_type)
Exemple #15
0
 def test_list_files_two_args(self):
     opts = RunOptions(["list", "foo", "bar"])
     self.assertEqual(Action.list, opts.action)
     self.assertEqual(False, opts.needs_tags(), "needs tags")
     self.assertEqual(["foo", "bar"], opts.files, "needs files")
     self.assertEqual(FrontendType.cli, opts.frontend)
Exemple #16
0
 def test_list_no_files(self):
     self.assertRaises(ParseError, lambda: RunOptions(["list"]))
Exemple #17
0
 def test_query_match_type_arg_missing(self):
     self.assertRaises(
         ParseError,
         lambda: RunOptions(["query", "tag 1", "tag 2", "--match-type"]))
Exemple #18
0
 def test_query_with_files_arg(self):
     self.assertRaises(
         ParseError, lambda: RunOptions([
             "query", "tag 1", "tag 2", "-m", "any", "--files", "foo.jpg"
         ]))
Exemple #19
0
 def test_query_match_any_long(self):
     opts = RunOptions(["query", "tag 1", "tag 2", "--match-type", "any"])
     self.assertEqual(MatchType.any, opts.match_type)
Exemple #20
0
 def test_index_no_files(self):
     self.assertRaises(ParseError, lambda: RunOptions(["index"]))
Exemple #21
0
 def test_query_frontend_arg_missing(self):
     self.assertRaises(
         ParseError,
         lambda: RunOptions(["query", "tag 1", "tag 2", "--frontend"]))
Exemple #22
0
 def test_invalid_action(self):
     self.assertRaises(ParseError, lambda: RunOptions(["blubb"]))
Exemple #23
0
 def test_list_files_arg_missing(self):
     self.assertRaises(ParseError, lambda: RunOptions(["list", "--files"]))
Exemple #24
0
 def test_invalid_action_more_args(self):
     self.assertRaises(ParseError, lambda: RunOptions(["blubb", "bbla"]))
Exemple #25
0
 def test_list_frontend_gtk_files_long(self):
     opts = RunOptions(["list", "--frontend", "gtk", "--files", "foo"])
     self.assertEqual(Action.list, opts.action)
     self.assertEqual(False, opts.needs_tags(), "needs tags")
     self.assertEqual(["foo"], opts.files, "needs files")
     self.assertEqual(FrontendType.gtk, opts.frontend)
Exemple #26
0
 def test_invalid_option(self):
     self.assertRaises(ParseError,
                       lambda: RunOptions(["index", "--brr", "bar"]))
Exemple #27
0
 def test_list_short(self):
     opts = RunOptions(["l", "--files", "foo"])
     self.assertEqual(Action.list, opts.action)
     self.assertEqual(["foo"], opts.files)
Exemple #28
0
 def test_invalid_frontend(self):
     self.assertRaises(
         ParseError, lambda: RunOptions(["tag", "foo", "-F", "gt", "bar"]))
Exemple #29
0
 def test_list_frontend_gtk_files_short(self):
     opts = RunOptions(["list", "-F", "gtk", "-f", "bar"])
     self.assertEqual(Action.list, opts.action)
     self.assertEqual(False, opts.needs_tags(), "needs tags")
     self.assertEqual(["bar"], opts.files, "needs files")
     self.assertEqual(FrontendType.gtk, opts.frontend)
Exemple #30
0
 def test_no_action(self):
     self.assertRaises(ParseError, lambda: RunOptions(["--files", "foo"]))