diff options
author | davidovski <david@davidovski.xyz> | 2022-01-02 18:29:01 +0000 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2022-01-02 18:29:01 +0000 |
commit | 15924240bee27f17a65e77dd56cdfb91404bc9b1 (patch) | |
tree | 6214c395c9d6ad8a8a2db70b0723fc8b59e02681 /src | |
parent | 313d7d23237c142a833e4f0e05593f50f8805b3e (diff) |
removed auto-importing keys
Diffstat (limited to 'src')
-rw-r--r-- | src/verbs/install.py | 48 | ||||
-rw-r--r-- | src/verbs/sync.py | 46 | ||||
-rw-r--r-- | src/xi.py | 2 |
3 files changed, 48 insertions, 48 deletions
diff --git a/src/verbs/install.py b/src/verbs/install.py index 7b6fd7d..929f8c4 100644 --- a/src/verbs/install.py +++ b/src/verbs/install.py @@ -179,34 +179,28 @@ def find_all_dependencies(package_names, options, config): # probably better way to implement this obligatory wildcard # 100% sure there is a better way of doing this than installing all packages from a repo # maybe some sort of package grouping (or empty package with deps on all needed) - if dep[-2:] == "/*": - repo = dep[:-2] - repo_dir = os.path.join(config["dir"]["packages"], repo) - files = os.listdir(repo_dir) - return files + dep_checksum, dep_sources, dep_repo = find_package(dep, config["repos"], config["dir"]["packages"], config["sources"]) + + if dep_checksum is not None: + info = retrieve_package_info( + dep_sources, dep_checksum, dep, config, + verbose=options["v"], skip_verification=options["u"] + ) + + if len(info) > 0: + if not dep in all_deps: + all_deps.append(dep) + deps = resolve_dependencies(info) + for dep in deps: + if not dep in all_deps: + if is_installed(dep, config, options["r"]): + if options["v"]: print(colors.YELLOW + f"Package {dep} has already been installed") + else: + to_check.append(dep) + elif options["v"]: + util.print_reset(colors.CLEAR_LINE + colors.RED + f"Failed to retrieve info for {dep}") else: - dep_checksum, dep_sources, dep_repo = find_package(dep, config["repos"], config["dir"]["packages"], config["sources"]) - - if dep_checksum is not None: - info = retrieve_package_info( - dep_sources, dep_checksum, dep, config, - verbose=options["v"], skip_verification=options["u"] - ) - - if len(info) > 0: - if not dep in all_deps: - all_deps.append(dep) - deps = resolve_dependencies(info) - for dep in deps: - if not dep in all_deps: - if is_installed(dep, config, options["r"]): - if options["v"]: print(colors.YELLOW + f"Package {dep} has already been installed") - else: - to_check.append(dep) - elif options["v"]: - util.print_reset(colors.CLEAR_LINE + colors.RED + f"Failed to retrieve info for {dep}") - else: - if options["v"]: util.print_reset(colors.CLEAR_LINE + colors.RED + f"Failed to find package {dep}") + if options["v"]: util.print_reset(colors.CLEAR_LINE + colors.RED + f"Failed to find package {dep}") if len(all_deps) > 0: util.loading_bar(len(all_deps), len(all_deps) + len(to_check), "Resolved dependencies") diff --git a/src/verbs/sync.py b/src/verbs/sync.py index 07ed2ec..13093c5 100644 --- a/src/verbs/sync.py +++ b/src/verbs/sync.py @@ -83,27 +83,6 @@ def save_package(package, info, location): return exists -###### !!! ####### -# THIS SHOULD BE A USER ACTION -# security problem to automatically decide to verify keys -# users should do this manually whenever they add a new source -###### !!! ####### -def import_key(source, url, config, verbose=False): - keyname = "xi.pub" - - keychain_dir = config["dir"]["keychain"] - util.mkdir(keychain_dir) - key_path = os.path.join(keychain_dir, source + ".pub") - - if os.path.exists(key_path): - if verbose: - print(colors.LIGHT_BLACK + f"Skipping already imported key from {source}") - return 0 - - else: - key_path = util.curl_to_file(url + keyname if url[-1] == "/" else f"/{keyname}", key_path) - return 1 - def test_source(source, url): # requesting a resource may not be the best way to do this, caching etc start = time.time() @@ -188,3 +167,28 @@ def sync(args, options, config): #for source, url in sources: #compelted += 1 #util.loading_bar(completed, total, f"Importing keys") + +def import_key(name, url, config, verbose=False, root="/"): + keychain_dir = util.add_path(root, config["dir"]["keychain"]) + util.mkdir(keychain_dir) + key_path = os.path.join(keychain_dir, name + ".pub") + + if os.path.exists(key_path): + print(colors.RED + f"Skipping existing key with name {name}") + else: + try: + key_path = util.curl_to_file(url, key_path) + print(colors.GREEN + f"Imported {name}.pub") + except Exception as e: + print(colors.RED + f"Failed to import key:", colors.DARK_RED + str(e)) + +def keyimport(args, options, config): + if len(args) > 1: + alias = args[0] + url = args[1] + + import_key(alias, url, config, verbose=options["v"], root=options["r"]) + + else: + print(colors.RED + "Usage: keyimport <alias> <url>") + @@ -10,9 +10,11 @@ from verbs.info import info from verbs.remove import remove from verbs.install import install from verbs.update import update +from verbs.sync import keyimport verbs = { v: globals()[v] for v in [ "search", + "keyimport", "file", "info", "update", |