def _get_last_release(self, spec: RPMSpec): """ This method tries to read the latest state from the state database - if that is not available, the .spec file is parsed as a fallback. Arguments: RPMSpec spec: rpm spec object Returns: str: last known release """ assert isinstance(spec, RPMSpec) ktr = Kentauros() logger = KtrLogger(LOG_PREFIX) saved_state = ktr.state_read(self.cpkg.get_conf_name()) if saved_state is None: logger.dbg("Package " + self.cpkg.get_conf_name() + " not yet in state database.") logger.dbg("Falling back to legacy release detection.") old_release = spec.get_release() elif "rpm_last_release" not in saved_state: logger.dbg("Package " + self.cpkg.get_conf_name() + " has no release set in state database.") logger.dbg("Falling back to legacy release detection.") old_release = spec.get_release() else: old_release = saved_state["rpm_last_release"] return old_release
def __init__(self, pkg_name: str): assert isinstance(pkg_name, str) ktr = Kentauros() self.name = pkg_name self.kpkg = ktr.get_package(pkg_name) assert self.kpkg is not None assert isinstance(self.kpkg, Package) self.atype = None
def status_string(self) -> str: ktr = Kentauros() rev = self.rev() if rev == "": rev = ktr.state_read(self.spkg.get_conf_name())["bzr_last_rev"] string = ("bzr source module:\n" + " Last Revision: {}\n".format(rev) + " Current branch: {}\n".format(self.get_branch())) return string
def import_status(self): """ This method imports a package's and all its sub-module's status to the package database. """ ktr = Kentauros() conf_name = self.kpkg.get_conf_name() modules = self.kpkg.get_modules() ktr.state_write(conf_name, self.kpkg.status()) for module in modules: ktr.state_write(conf_name, module.imports())
def update_status(self): """ This method writes a package's and all its sub-module's status to the package database. It is executed after actions. """ ktr = Kentauros() conf_name = self.kpkg.get_conf_name() modules = self.kpkg.get_modules() ktr.state_write(conf_name, self.kpkg.status()) for module in modules: ktr.state_write(conf_name, module.status())
def status_string(self) -> str: ktr = Kentauros() commit = self.commit() date = self.date() if commit == "": commit = ktr.state_read(self.spkg.get_conf_name())["git_last_commit"] if date == "": date = ktr.state_read(self.spkg.get_conf_name())["git_last_date"] string = ("git source module:\n" + " Current branch: {}\n".format(self.get_branch()) + " Last Commit: {}\n".format(commit) + " Last Commit Date: {}\n".format(date)) return string
def run(): """ This function is corresponding to (one of) the "main" function of the `kentauros` package and is the entry point used by the `ktr.py` script from git and the script installed at installation. """ ktr = Kentauros() logger = KtrLogger(LOG_PREFIX) print_parameters() # if no action is specified: exit if ktr.cli.get_action() is None: logger.log("No action specified. Exiting.") logger.log("Use 'ktr --help' for more information.") print_flush() return if not ktr_bootstrap(): raise SystemExit() packages = list() # if only specified packages are to be processed: process packages from CLI only if not ktr.cli.get_packages_all(): packages = ktr.cli.get_packages().copy() for pkg in packages: pkg_conf_path = os.path.join(ktr.conf.get_confdir(), pkg + ".conf") if not os.path.exists(pkg_conf_path): logger.err("Package configuration for '" + pkg + "' could not be found.") packages.remove(pkg) # if all package are to be processed: get package configs present in the package configuration # directory else: pkg_conf_paths = glob.glob(os.path.join(ktr.conf.get_confdir(), "*.conf")) for pkg_conf_path in pkg_conf_paths: packages.append(os.path.basename(pkg_conf_path).replace(".conf", "")) if not packages: logger.log("No packages have been specified or found. Exiting.") print_flush() raise SystemExit() packages.sort() # log list of found packages logger.log_list("Packages", packages) print_flush() # generate package objects for name in packages: assert isinstance(name, str) try: pkg = Package(name) ktr.add_package(name, pkg) except PackageError: logger.log("Package with configuration file '" + name + "' is invalid, skipping.") continue actions_success = list() actions_failure = list() # run action for every specified package for name in ktr.get_package_names(): assert isinstance(name, str) if ktr.state_read(name) is None: logger.log("Importing new package into the database.") import_action = ImportAction(name) import_action.execute() action_type = ktr.cli.get_action() action = ACTION_DICT[action_type](name) success = action.execute() if success: actions_success.append(name) else: actions_failure.append(name) print_flush() if actions_success: logger.log_list("Successful actions", actions_success) if actions_failure: logger.log_list("Failed actions", actions_failure) print_flush() raise SystemExit()