summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/verbs/install.py155
-rw-r--r--src/verbs/update.py16
2 files changed, 84 insertions, 87 deletions
diff --git a/src/verbs/install.py b/src/verbs/install.py
index 9832e2b..b2fdf51 100644
--- a/src/verbs/install.py
+++ b/src/verbs/install.py
@@ -301,7 +301,7 @@ def run_post_install(config, verbose=False, root="/"):
def install_single(package, options, config, post_install=True, verbose=False, unsafe=False):
- checksum, sources, repo = find_package(package, config["repos"],
+ checksum, sources, repo, size, files = find_package(package, config["repos"],
config["dir"]["packages"], config["sources"])
info = retrieve_package_info(
@@ -318,6 +318,85 @@ def install_single(package, options, config, post_install=True, verbose=False, u
config, verbose=verbose, root=options["r"])
+def install_multiple(to_install, args, options, config, terminology=("install", "installed", "installing")):
+ v = options["v"]
+ unsafe = options["u"]
+
+ length = 0
+ total_files = 0
+ infos = []
+ for package in to_install:
+ util.loading_bar(len(infos), len(to_install), "Gathering package infos")
+ checksum, sources, repo, size, filecount = find_package(package, config["repos"],
+ config["dir"]["packages"], config["sources"])
+
+ if checksum != None:
+ info = retrieve_package_info(
+ sources, checksum, package, config,
+ verbose=v, skip_verification=unsafe
+ )
+
+ # TODO make package_size be written in package info or sync list instead
+ length += int(size)
+ total_files += int(filecount)
+
+ infos.append(
+ (package, sources, repo, info)
+ )
+
+ divisor, unit = util.get_unit(length)
+
+ util.loading_bar(len(infos), len(to_install), "Gathered package infos")
+ print(colors.RESET)
+
+ if not options["y"]:
+ print(colors.BLUE + f"The following packages will be {terminology[1]}:")
+ print(end="\t")
+ for d in to_install:
+ print(colors.BLUE if d in args else colors.LIGHT_BLUE, d, end="")
+ print()
+
+ print(colors.BLUE + "Total download size: " + colors.LIGHT_BLUE + str(round(length / divisor, 2)) + unit)
+
+ if options["y"] or util.ask_confirmation(colors.BLUE + "Continue?"):
+ # TODO try catch over each package in each stage so that we can know if there are errors
+
+ downloaded = 0
+ pkg_files = []
+ for package_info in infos:
+ (package, sources, repo, info) = package_info
+
+ package_path, source, key, size = retrieve_package(sources,
+ info, package, config,
+ completed=downloaded, total_download=length,
+ verbose=v, skip_verification=unsafe)
+
+ downloaded += size
+
+ pkg_files.append(
+ (package, package_path, sources[source], key, repo, info)
+ )
+
+ util.loading_bar(int(length/divisor), int(length/divisor), "Downloaded packages", unit=unit)
+ print(colors.RESET)
+
+ extracted = 0
+ for f in pkg_files:
+ util.loading_bar(extracted, total_files, terminology[2].capitalize() + " files")
+
+ (package, package_path, source, key, repo, info) = f
+
+ files = install_package(package, package_path, info,
+ repo, source, key, True,
+ config, verbose=v, root=options["r"])
+ extracted += len(files.split("\n"))
+
+ util.loading_bar(extracted, total_files, terminology[1].capitalize() + " files")
+ print(colors.RESET)
+ else:
+ print(colors.RED + "Action cancelled by user")
+
+
def install(args, options, config):
if not options["l"]:
sync(args, options, config)
@@ -345,79 +424,7 @@ def install(args, options, config):
print()
if len(to_install) > 0:
- length = 0
- total_files = 0
- infos = []
- for package in to_install:
- util.loading_bar(len(infos), len(to_install), "Gathering package infos")
- checksum, sources, repo, size, filecount = find_package(package, config["repos"],
- config["dir"]["packages"], config["sources"])
-
- if checksum != None:
- info = retrieve_package_info(
- sources, checksum, package, config,
- verbose=v, skip_verification=unsafe
- )
-
- # TODO make package_size be written in package info or sync list instead
- length += int(size)
- total_files += int(filecount)
-
- infos.append(
- (package, sources, repo, info)
- )
-
- divisor, unit = util.get_unit(length)
-
- util.loading_bar(len(infos), len(to_install), "Gathered package infos")
- print(colors.RESET)
-
- if not options["y"]:
- print(colors.BLUE + "The following packages will be installed:")
- print(end="\t")
- for d in to_install:
- print(colors.BLUE if d in args else colors.LIGHT_BLUE, d, end="")
- print()
-
- print(colors.BLUE + "Total download size: " + colors.LIGHT_BLUE + str(round(length / divisor, 2)) + unit)
-
- if options["y"] or util.ask_confirmation(colors.BLUE + "Continue?"):
- # TODO try catch over each package in each stage so that we can know if there are errors
-
- downloaded = 0
- pkg_files = []
- for package_info in infos:
- (package, sources, repo, info) = package_info
-
- package_path, source, key, size = retrieve_package(sources,
- info, package, config,
- completed=downloaded, total_download=length,
- verbose=v, skip_verification=unsafe)
-
- downloaded += size
-
- pkg_files.append(
- (package, package_path, sources[source], key, repo, info)
- )
-
- util.loading_bar(int(length/divisor), int(length/divisor), "Downloaded packages", unit=unit)
- print(colors.RESET)
-
- extracted = 0
- for f in pkg_files:
- util.loading_bar(extracted, total_files, "Installing files")
-
- (package, package_path, source, key, repo, info) = f
-
- files = install_package(package, package_path, info,
- repo, source, key, True,
- config, verbose=v, root=options["r"])
- extracted += len(files.split("\n"))
-
- util.loading_bar(extracted, total_files, "Installed files")
- print(colors.RESET)
- else:
- print(colors.RED + "Action cancelled by user")
+ install_multiple(to_install, args, options, config)
else:
print(colors.LIGHT_RED + "Nothing to do")
else:
diff --git a/src/verbs/update.py b/src/verbs/update.py
index 4348637..6fe89f6 100644
--- a/src/verbs/update.py
+++ b/src/verbs/update.py
@@ -3,7 +3,7 @@ import util
import colors
import time
-from verbs.install import find_package, install_single
+from verbs.install import find_package, install_multiple
from verbs.sync import sync
VERSION_COMPARED = "CHECKSUM"
@@ -26,7 +26,7 @@ def get_available_version(package_name, config, root="/"):
repos = config["repos"]
packages_dir = config["dir"]["packages"]
sources = config["sources"]
- checksum, found_sources, requested_repo = find_package(package_name, repos, packages_dir, sources)
+ checksum, found_sources, requested_repo, size, files = find_package(package_name, repos, packages_dir, sources)
return checksum
def update(args, options, config):
@@ -41,17 +41,7 @@ def update(args, options, config):
updates = [update for update in updates if update in args]
if len(updates) > 0:
- print(colors.CLEAR_LINE + colors.RESET, end="")
- print(colors.BLUE + "The following packages will be updated:")
- print(end="\t")
- for d in updates:
- print(colors.BLUE if d in args else colors.LIGHT_BLUE, d, end="")
- print()
-
- if util.ask_confirmation(colors.BLUE + "Continue?", no_confirm=options["y"]):
- for package in updates:
- install_single(package, options, config, verbose=v, post_install=False, unsafe=options["u"])
- util.fill_line(f"Updated {package}", colors.BG_CYAN + colors.LIGHT_BLACK, end="\n")
+ install_multiple(updates, args, options, config, terminology=("update", "updated", "updating"))
else:
print(colors.LIGHT_RED + "Nothing to do")