Exemple #1
0
def _run_action(core: TieCore, run_options: RunOptions, frontend: Frontend):
    action = run_options.action
    if action == Action.query:
        _query(core, run_options.tags, run_options.match_type, frontend)
    elif action == Action.list:
        _list(core, run_options.files, frontend)
    else:
        for file in run_options.files:
            try:
                _process_file(core, file, run_options)
            except InvalidMetaDataError as meta_data_error:
                prompt = "Error: Cannot read metadata from file " + file + " - " + meta_data_error.msg \
                         + "\nClear present meta data now?"
                clear = frontend.get_user_confirmation(prompt,
                                                       "WIPE_INVALID_DATA")
                if clear == UserReply.yes:
                    core.clear(file)
                    # Hopefully the file is clean now. If for whatever reason it isn't, this call will raise an
                    # InvalidMetaDataError again. If it does, let it bubble up.
                    _process_file(core, file, run_options)
                elif clear == UserReply.no:
                    printerr("Ignoring unreadable file " + file)
                elif clear == UserReply.cancel:
                    printerr("Operation cancelled.")
                    return
                else:
                    raise ValueError("Unexpected UserReply " + clear.name)
Exemple #2
0
 def _get_user_confirmation_impl(
         self, prompt: str, propose_remember: bool) -> UserConfirmation:
     backup_fd = printing.redirect_stdout()
     try:
         hint = "[y]es, [n]o"
         if propose_remember:
             hint = hint + ", [a]ccept all, [d]eny all"
         hint = hint + ", [c]ancel"
         user_input = input(prompt + " (" + hint + "): ").lower()
         while True:
             if user_input in ['y', 'j']:
                 return UserConfirmation(UserReply.yes, False)
             elif user_input == 'n':
                 return UserConfirmation(UserReply.no, False)
             elif user_input == 'c':
                 return UserConfirmation(UserReply.cancel, False)
             elif propose_remember and user_input == 'a':
                 return UserConfirmation(UserReply.yes, True)
             elif propose_remember and user_input == 'd':
                 return UserConfirmation(UserReply.no, True)
             else:
                 printerr("\nInvalid input \'" + user_input +
                          "\'. Expected: " + hint)
                 user_input = input(prompt + " ").lower()
     finally:
         printing.revert_stdout(backup_fd)
def test_frontend_user_confirm_repeated(fe: Frontend):
    choice1 = fe.get_user_confirmation("Do you really want to confirm 1?",
                                       "q1")
    printerr("Your repeated choice1: " + str(choice1))
    choice2 = fe.get_user_confirmation("Do you really want to confirm 1?",
                                       "q1")
    printerr("Your repeated choice2: " + str(choice2))
    choice3 = fe.get_user_confirmation("Do you really want to confirm 2?",
                                       "q2")
    printerr("Your repeated choice3: " + str(choice3))
    choice4 = fe.get_user_confirmation("Do you really want to confirm 2?",
                                       "q2")
    printerr("Your repeated choice4: " + str(choice4))
Exemple #4
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 #5
0
 def show_message(self, message: str):
     printerr(message)
def test_frontend_get_tags(fe: Frontend, tags_choice: List[str]):
    choice = fe.get_tags(tags_choice, True)
    printerr("Your choice:")
    for t in choice:
        printerr(t)
def test_frontend_user_confirm_simple(fe: Frontend):
    choice = fe.get_user_confirmation("Confirm?")
    printerr("Your choice simple: " + str(choice))
Exemple #8
0
def print_usage():
    printerr(USAGE_STRING)