def build(self) -> bool: """ This method constructs the :py:class:`MockBuilder` instances, which contain the commands for executing the builds, and executes them in turn. It also checks if the executing user is allowed to execute a mock build by checking if ``$USER`` is "root" or if the user is in the "mock" group. If no source packages are found in the specified directory (``PACKDIR``), the build terminates without executing mock. If SRPM packages are found, only the most recent (biggest version number, determined just by sorting!) is built, for all specified chroots. After the last mock invocation, a list of successful and unsuccessful builds is printed. Returns: bool: ``True`` if all builds succeeded, ``False`` if not """ if not self.get_active(): return True ktr = Kentauros() logger = KtrLogger(LOG_PREFIX) package_dir = os.path.join(ktr.conf.get_packdir(), self.bpkg.get_conf_name()) # get all srpms in the package directory srpms = glob.glob(os.path.join(package_dir, self.bpkg.get_name() + "*.src.rpm")) if not srpms: logger.log("No source packages were found. Construct them first.", 2) return False # figure out which srpm to build srpms.sort(reverse=True) srpm = srpms[0] logger.log_list("Specified chroots", self.get_dists()) # generate build queue build_queue = list() mock_cmd = get_mock_cmd() for dist in self.get_dists(): build_queue.append(MockBuild(mock_cmd, srpm, dist)) # run builds in queue builds_success = list() builds_failure = list() for build in build_queue: ret = build.build() if ret: builds_failure.append((build.path, build.dist)) else: builds_success.append((build.path, build.dist)) # remove source package if keep=False is specified if not self.get_keep(): os.remove(srpm) if builds_success: logger.log_list("Build successes", builds_success) if builds_failure: logger.log_list("Build failures", builds_failure) return not builds_failure
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()