def manually_add_new_repo(target): """ Allow entry of a new repository manually """ choices = sorted(os.listdir(target)) option = make_simple_choice(choices, "Which Directory?") if option is None: raise NoRepoException() repository_map = get_json_value("repository_map", {}) repository_map[option] = str(Path(target) / option) set_json_value("repository_map", repository_map)
def add_repo_save(repodir, add_word, del_word, file_paths): """ Record a typo correction """ saves = get_json_value("repository_saves", {}) reponame = Path(repodir).name saves[reponame] = { "add_word": add_word, "del_word": del_word, "file_paths": file_paths, "repodir": repodir, } set_json_value("repository_saves", saves)
def get_suggestion(word): """ Use the internet to determine if the provided word is a nonword or a typo """ key = f"suggestion.{word}" existing = get_json_value(key) if existing is not None: if existing.get("no_suggestion"): return None return Suggestion.load(existing) suggestion = search_suggestion(word) if suggestion is None: set_json_value(key, {"no_suggestion": True}) return None set_json_value(key, suggestion.save()) return suggestion
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 remove_repo_for(repo, repodir, confirm=True): """ Remove specified repo """ for name in ("repository_map", "repository_saves"): repository_map = get_json_value(name, {}) try: del repository_map[repo] set_json_value(name, repository_map) except (KeyError, TypeError): continue if confirm: option = make_simple_choice(["Yes", "No"], "Delete the directory?") else: option = "Yes" if option == "Yes": if os.path.isdir(repodir): shutil.rmtree(repodir, ignore_errors=True)
def multiworker_core(interaction, target): """ Support for different kinds of interaction with multiple worker processing """ key = "multiworker_workload" workload = get_json_value(key, deflt=[]) workload = update_workload(workload) handlers = get_handlers() input_queue = get_input_queue() threadpool = get_pool(handlers) controller = Controller( handlers=handlers, input_queue=input_queue, threadpool=threadpool, target=target ) with controller: for task in workload: controller.add(task) result = controller.run(interaction) set_json_value(key, result)
def non_interactive_pickrepo(): """ Select next free repo """ forking = [] return_repo = None with LOCK: repository_forked = get_json_value("repository_forked", {}) for orgrepo in obtain_sources(): _, origrepo = orgrepo.split("/", 1) if origrepo in repository_forked: continue try: orgrepo = get_true_orgrepo(orgrepo) except GithubException: continue _, repo = orgrepo.split("/", 1) if repo in repository_forked: continue if check_forked(orgrepo): repository_forked[origrepo] = True repository_forked[repo] = True set_json_value("repository_forked", repository_forked) continue forking.append(orgrepo) if is_archived(orgrepo): repository_forked[origrepo] = True repository_forked[repo] = True set_json_value("repository_forked", repository_forked) continue repository_forked[origrepo] = True repository_forked[repo] = True set_json_value("repository_forked", repository_forked) return_repo = repo break for orgrepo in forking: fork(orgrepo) return return_repo
def interactive_pickrepo(): """ Select next free repo """ repository_forked = get_json_value("repository_forked", {}) for orgrepo in obtain_sources(): _, origrepo = orgrepo.split("/", 1) if origrepo in repository_forked: continue try: orgrepo = get_true_orgrepo(orgrepo) except GithubException: continue _, repo = orgrepo.split("/", 1) if repo in repository_forked: continue print(f"Checking {orgrepo}") if check_forked(orgrepo): repository_forked[origrepo] = True repository_forked[repo] = True set_json_value("repository_forked", repository_forked) continue print(f"Have not forked {orgrepo}") print(f"Forking {orgrepo}") fork(orgrepo) if is_archived(orgrepo): print(f"Skipping archived repo {orgrepo}") repository_forked[origrepo] = True repository_forked[repo] = True set_json_value("repository_forked", repository_forked) continue repository_forked[origrepo] = True repository_forked[repo] = True set_json_value("repository_forked", repository_forked) return repo return None
def clear_work_queue(target): # pylint: disable=unused-argument """ Remove the current workload to reset """ key = "multiworker_workload" set_json_value(key, [])