def check_websearch(obj, eng): """ Quick initial check to see if a websearch provides a suggestion. """ suggestion = obj.details.get("suggestion_obj") if suggestion is None: return show_word(obj.word, obj.details) if suggestion.is_nonword: if get_confirmation("Web search suggests it is a non-word, agree?"): handle_nonword(obj.word, obj.target, obj.nonword_delegate) eng.halt("found nonword") if suggestion.is_typo: if suggestion.replacement: msgs = [(f"Web search suggests using {prefix}" f"{suggestion.replacement}{suffix}, agree?") for prefix, suffix in [("", ""), (Fore.CYAN, Style.RESET_ALL)]] print(msgs[-1]) if get_confirmation(msgs[0], defaultval=False): fix_word(obj.word, obj.details, suggestion.replacement, obj.repopath) obj.done = True eng.halt("found typo") msgs = [(f"Web search suggests using {prefix}" f"typo{suffix}, agree?") for prefix, suffix in [("", ""), (Fore.RED, Style.RESET_ALL)]] print(msgs[-1]) if get_confirmation(msgs[0], defaultval=False): handle_typo(obj.word, obj.details, obj.repopath) obj.done = True eng.halt("found typo")
def is_nonword(obj, eng): """ Quick initial check to see if it is a nonword. """ show_word(obj.word, obj.details) if get_confirmation("Is non-word?"): handle_nonword(obj.word, obj.target, obj.nonword_delegate) eng.halt("found nonword")
def is_typo(obj, eng): """ Quick initial check to see if it is a typo. """ show_word(obj.word, obj.details) if get_confirmation("Is it typo?"): handle_typo(obj.word, obj.details, obj.repopath) obj.done = True eng.halt("found typo")
def handle_typo(word, details, repopath): # pylint: disable=unused-argument """ Handle a typo """ if get_confirmation(f"Do you want to google {word}"): browser = local[get_browser()] search = f"https://www.google.com.au/search?q={quote(word)}" _ = browser[search] & FG newspell = get_input(f"How do you spell {word}?") if newspell: fix_word(word, details, newspell, repopath)
def handler(): reponame = context.taskjson["reponame"] repository_saves = get_json_value("repository_saves", {}) if reponame in repository_saves: reposave = repository_saves[reponame] suggest_plain = check_if_plain_pr(reposave) add_word = reposave["add_word"] del_word = reposave["del_word"] file_paths = reposave["file_paths"] files = ", ".join(file_paths) print(f"Fix in {reponame}: {del_word} -> {add_word} over {files}") if suggest_plain: submit_plain = get_confirmation( "Analysis suggests plain pr, agree?") else: submit_plain = get_confirmation( "Complex repo submit plain pr anyway?") context.controller.add({ "name": "plain_pr" if submit_plain else "full_pr", "interactive": False, "reponame": reponame, "reposave": reposave, })
def run_invocation(target): """ Execute the invocation """ if target is None: target = Path(os.environ["HOME"]) / "data" else: target = Path(target) if not target.is_dir(): print(f"Target {target} is not a directory.", file=sys.stderr) sys.exit(1) init() prepare() load_recent_non_words(target) validate_versions() try: if get_confirmation("Run webserver?"): webserver_main(target) elif get_confirmation("Run automated multi-queue processing?"): multiworker_main(target) else: manual_menu(target) except UserCancel: print("Quit by user.")
def handler(): target = context.controller.target reponame = context.taskjson["reponame"] repodir = target / reponame repository_map = get_json_value("repository_map", {}) repository_map[reponame] = str(repodir) set_json_value("repository_map", repository_map) display_repo_intro(repodir) context.controller.add({ "name": "collect_nonwords", "interactive": True, "priority": 50, "reponame": reponame, }) if get_confirmation("Do you want to quit?"): context.controller.quit()
def get_confirmation(self, message="Do you want to continue", defaultval=True): return _input.get_confirmation(message=message, defaultval=defaultval)
def check_quit(self, controller): return _input.get_confirmation(message="Do you want to quit?", defaultval=True)