diff options
author | davidovski <david@davidovski.xyz> | 2021-11-24 22:22:30 +0000 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2021-11-24 22:22:30 +0000 |
commit | 77b06090f69264bcc93911664bea2810cd4571ba (patch) | |
tree | 85f9b27f50de66fbcd9b47c01b8386f80aba769f /src/verbs | |
parent | 52f1d6e6a5b0e0faca2d397114e107900b01b97d (diff) |
cleaned a few things up
Diffstat (limited to 'src/verbs')
-rw-r--r-- | src/verbs/install.py | 60 | ||||
-rw-r--r-- | src/verbs/sync.py | 17 |
2 files changed, 54 insertions, 23 deletions
diff --git a/src/verbs/install.py b/src/verbs/install.py index 0531110..6c8c9fd 100644 --- a/src/verbs/install.py +++ b/src/verbs/install.py @@ -174,28 +174,38 @@ def find_all_dependencies(package_names, options, config): while len(to_check) > 0: util.loading_bar(len(all_deps), len(all_deps) + len(to_check), "Resolving dependencies...") dep = to_check.pop() - - 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}") + + # 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 else: - if options["v"]: util.print_reset(colors.CLEAR_LINE + colors.RED + f"Failed to find package {dep}") + 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 len(all_deps) > 0: util.loading_bar(len(all_deps), len(all_deps) + len(to_check), "Resolved dependencies") @@ -270,6 +280,7 @@ def install(args, options, config): if len(to_install) > 0: + print(colors.CLEAR_LINE + colors.RESET, end="") print(colors.BLUE + "The following packages will be installed:") print(end="\t") for d in to_install: @@ -278,6 +289,7 @@ def install(args, options, config): if util.ask_confirmation(colors.BLUE + "Continue?", no_confirm=options["y"]): + downloaded = [] for package in to_install: checksum, sources, repo = find_package(package, config["repos"], config["dir"]["packages"], config["sources"]) @@ -291,10 +303,14 @@ def install(args, options, config): info, package, config, verbose=v, skip_verification=unsafe) + downloaded.append(package, package_path, info, + repo, sources[source], key + ) install_package(package, package_path, info, repo, sources[source], key, config, root=options["r"]) - print(colors.BG_CYAN + colors.LIGHT_BLACK + f"Installed {package}" + colors.RESET) + util.fill_line(f"Installed {package}", colors.BG_CYAN + colors.LIGHT_BLACK, end="\n") + else: print(colors.RED + "Action cancelled by user") else: diff --git a/src/verbs/sync.py b/src/verbs/sync.py index e71109d..85e3623 100644 --- a/src/verbs/sync.py +++ b/src/verbs/sync.py @@ -59,11 +59,19 @@ def save_package(package, info, location): util.mkdir(location) package_file = os.path.join(location, package) + exists = False + if os.path.exists(package_file): + with open(package_file, "r") as file: + text = file.read() + exists = info["checksum"] in text + content = "" with open(package_file, "w") as file: file.write("checksum=" + info["checksum"] + "\n") file.write("sources=" + " ".join([source for source in info["sources"]])) + return exists + ###### !!! ####### # THIS SHOULD BE A USER ACTION @@ -125,6 +133,8 @@ def sync(args, options, config): v = options["v"] + new = 0 + for repo in repos: if v: print(colors.LIGHT_BLACK + f"downloading package lists for {repo}...") @@ -141,12 +151,17 @@ def sync(args, options, config): total = len(packages.items()) for package,versions in packages.items(): info = validate_package(package, versions, repo, verbose=v) - save_package(package, info, os.path.join(config["dir"]["packages"], repo)) + if not save_package(package, info, os.path.join(config["dir"]["packages"], repo)): + new += 1 done += 1 util.loading_bar(done, total, f"Syncing {repo}") util.loading_bar(total, total, f"Synced {repo}") print(colors.RESET) + + if new > 0: + util.fill_line(f"There are {new} new updates", colors.LIGHT_GREEN) + if "key_authority" in config: imported = 0 |