def install_committed(path_to_archive, engine, force=False, quiet=False): """ Installs the committed dataset """ with ZipFile(os.path.normpath(path_to_archive), 'r') as archive: try: workdir = mkdtemp(dir=os.path.dirname(path_to_archive)) engine.data_path = os.path.join(workdir) script_object = get_script_provenance( path_to_archive=path_to_archive) metadata_info = get_metadata(path_to_archive=path_to_archive) installation_details(metadata_info=metadata_info, quiet=quiet) if not force: confirm = input( "Please enter either y to continue with installation or n to exit:" ) while not (confirm.lower() in ['y', 'n']): print("Please enter either y or n:") confirm = input() else: confirm = 'y' if confirm.lower() == 'y': for filename in archive.namelist(): if filename.startswith(script_object.name + '/'): archive.extract(filename, workdir) engine.script_table_registry = OrderedDict() script_object.download(engine) return engine except Exception as e: print(e) return None finally: engine.data_path = None rmtree(workdir)
def name_matches(scripts, arg): """Check for a match of the script in available scripts if all, return the entire script list if the exact script is available, return that script if no exact script name detected, match the argument with keywords title and name of all scripts and return the closest matches """ if not arg: raise ValueError("No dataset name specified") if arg.endswith(".zip"): script = get_script_provenance(arg) return [script] arg = arg.strip().lower() matches = [] if arg == "all": return scripts for script in scripts: if arg == script.name.lower(): local_version = script.version if arg in RETRIEVER_DATASETS: upstream_version = get_script_version_upstream( arg, repo=RETRIEVER_REPOSITORY) else: upstream_version = get_script_version_upstream(arg) if not upstream_version or parse_version( local_version) >= parse_version(upstream_version): return [script] prompt = ( "A newer version of {dataset} is available. Would you like to download " "it? (y/N): ".format(dataset=arg)) should_download = input(prompt) while not (should_download.lower() in ["y", "n", ""]): print("Please enter either y or n.") should_download = input() if should_download.lower() == "y": if arg in RETRIEVER_DATASETS: read_script = get_script_upstream( arg, repo=RETRIEVER_REPOSITORY) else: read_script = get_script_upstream(arg) if not read_script: print("Unable to download {dataset}.".format(dataset=arg)) return [script] return [read_script] return [script] if arg in RETRIEVER_DATASETS: read_script = get_script_upstream(arg, repo=RETRIEVER_REPOSITORY) else: read_script = get_script_upstream(arg) if read_script: return [read_script] for script in scripts: script_match_ratio = difflib.SequenceMatcher(None, script.name, arg).ratio() if script_match_ratio > 0.53: matches.append((script.name, script_match_ratio)) matches.sort(key=lambda x: -x[1]) print('\nThe dataset "{}" ' "isn't currently available in the Retriever.".format(arg)) if matches: print("Did you mean:" " \n\t{}".format("\n\t".join([i[0] for i in matches]))) return None