diff --git a/soypak/cli/commands/install.py b/soypak/cli/commands/install.py index 28e4cd9..0a764f5 100644 --- a/soypak/cli/commands/install.py +++ b/soypak/cli/commands/install.py @@ -1,8 +1,9 @@ +import sys import clog import pathlib import argparse import soypak.cli.command as command -import soypak.deps.transaction as transaction # :@Note: future use +import soypak.deps.transaction as transaction import soypak.deps.bottler as bottler @@ -22,22 +23,54 @@ class Install(command.Command): def run(self): - candidates: list[bottler.Soybottle] = [] + candidates: list[bottler.PackageItem] = [] # any preinit before installing should occur here for item in self.rargs: - # has a Debian file been directly passed? - if item.endswith(".bottle") and pathlib.Path(item).resolve().exists(): - _log.debug("Detected a bottle file. Considering sidingloading...") + # has a bottle file been directly passed? + if item.endswith(".bottle"): + _log.debug("Detected a bottle file. Attempting to sideload...", end="").withConsole() + _log.writeLog(header=False) + + # check if the file actually exists on the system + if not pathlib.Path(item).resolve().exists(): + _log.printLog("failed.", level=4) + _log.warn(f"Could not find bottle file {item!r}. Skipping package.").withConsole() + continue + # let's structure the file to be processed. pkg = bottler.loadPackage(item) - if pkg is None: + if isinstance(pkg, Exception): + _log.printLog("failed.", level=4) # :@Ethan: maybe the loadPackage could give us some information. - raise Exception(f"Unable to load {item}.") - _log.debug(f"Sideloading: {item}").withConsole() + _log.error(f"Unable to sideload bottle file {item!r}. The following error was raised: {str(pkg)}") + sys.exit(1) + + _log.printLog("ok.", level=1) + _log.debug(f"Sideloaded: {item}") candidates.append(pkg) + continue # let's check the database for a package by the given name ... + if not candidates: + _log.info("Nothing to install.").withConsole() + sys.exit(0) + + tx = transaction.Transaction(transaction.PkgGoal.PKG_INSTALL) + depends = tx.compute(candidates) + + if len(depends) > 0: + _log.debug("Computed system dependencies required by the packages selected.\n", *depends) + _log.printLog("The following system dependencies have been identified:\n", + *depends, "", level=3, sep=" | ") + + tx.apply() + if not tx.problems(): + ... + # :@TODO: handle all the problems + + # commit the transaction to record + tx.commit()