summaryrefslogtreecommitdiff
path: root/src/verbs
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2021-12-07 18:55:10 +0000
committerdavidovski <david@davidovski.xyz>2021-12-07 18:55:10 +0000
commitc7eb41091b9df6f08dbcaed38deca354fb797d50 (patch)
treed4db02ab6d2ef5295a34328fd66f26a2dbf8597e /src/verbs
parent77b06090f69264bcc93911664bea2810cd4571ba (diff)
added update command
Diffstat (limited to 'src/verbs')
-rw-r--r--src/verbs/install.py43
-rw-r--r--src/verbs/update.py58
2 files changed, 78 insertions, 23 deletions
diff --git a/src/verbs/install.py b/src/verbs/install.py
index 6c8c9fd..2e63dd4 100644
--- a/src/verbs/install.py
+++ b/src/verbs/install.py
@@ -114,6 +114,7 @@ def retrieve_package(sources, package_info, package_name, config,
package_dir = util.add_path(cache_dir, source)
util.mkdir(package_dir)
+ # TODO if exists maybe just use cached version
status, package_path = util.curl_to_file(package_url, util.add_path(package_dir, package_name + ".xipkg"), text=package_name + ".xipkg")
if status == 200:
@@ -228,7 +229,7 @@ def install_package(package_name, package_path, package_info,
config, root="/"):
# TODO loading bar here
- util.extract_tar(package_path, root)
+ files = util.extract_tar(package_path, root)
save_installed_info(package_name, package_info, repo, source_url, key, config, root=root)
# untar and move into root
# then add entry in the config["dir"]["installed"]
@@ -262,6 +263,23 @@ def save_installed_info(package_name, package_info,
pass
+def install_single(package, options, config, verbose=False, unsafe=False):
+
+ checksum, sources, repo = find_package(package, config["repos"],
+ config["dir"]["packages"], config["sources"])
+
+ info = retrieve_package_info(
+ sources, checksum, package, config,
+ verbose=verbose, skip_verification=unsafe
+ )
+
+ package_path, source, key = retrieve_package(sources,
+ info, package, config,
+ verbose=verbose, skip_verification=unsafe)
+
+ install_package(package, package_path, info,
+ repo, sources[source], key,
+ config, root=options["r"])
def install(args, options, config):
if not options["l"]:
@@ -276,10 +294,7 @@ def install(args, options, config):
packages_dir = config["dir"]["packages"]
to_install = args if options["n"] else find_all_dependencies(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")
@@ -289,26 +304,8 @@ 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"])
-
- info = retrieve_package_info(
- sources, checksum, package, config,
- verbose=v, skip_verification=unsafe
- )
-
- package_path, source, key = retrieve_package(sources,
- 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"])
+ install_single(package, options, config, verbose=v, unsafe=unsafe)
util.fill_line(f"Installed {package}", colors.BG_CYAN + colors.LIGHT_BLACK, end="\n")
else:
diff --git a/src/verbs/update.py b/src/verbs/update.py
new file mode 100644
index 0000000..1cba192
--- /dev/null
+++ b/src/verbs/update.py
@@ -0,0 +1,58 @@
+import os
+import util
+import colors
+import time
+
+from verbs.install import find_package, install_single
+from verbs.sync import sync
+
+VERSION_COMPARED = "CHECKSUM"
+
+def get_installed_versions(config, root="/"):
+ packages = {}
+
+ installed_dir = util.add_path(root, config["dir"]["installed"])
+ if os.path.exists(installed_dir):
+ files = os.listdir(installed_dir)
+ for package in files:
+ with open(util.add_path(installed_dir, package, "info")) as file:
+ for line in file:
+ if line.startswith(VERSION_COMPARED):
+ packages[package] = line.strip().split("=")[-1]
+
+ return packages
+
+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)
+ return checksum
+
+def update(args, options, config):
+ if not options["l"]:
+ sync(args, options, config)
+
+ v = options["v"]
+
+ updates = [package for package,checksum in get_installed_versions(config, options["r"]).items() if not checksum == get_available_version(package, config, options["r"])]
+
+ if len(args) > 0:
+ 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, unsafe=options["u"])
+ util.fill_line(f"Updated {package}", colors.BG_CYAN + colors.LIGHT_BLACK, end="\n")
+ else:
+ print(colors.LIGHT_RED + "Nothing to do")
+
+