How to use the rebasehelper.exceptions.RebaseHelperError function in rebasehelper

To help you get started, we’ve selected a few rebasehelper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rebase-helper / rebase-helper / rebasehelper / helpers / koji_helper.py View on Github external
config = koji.read_config(profile)
        session = koji.ClientSession(config['server'], opts=config)
        if not login:
            return session
        try:
            session.gssapi_login()
        except Exception:  # pylint: disable=broad-except
            pass
        else:
            return session
        # fall back to kerberos login (doesn't work with python3)
        exc = (koji.AuthError, koji.krbV.Krb5Error) if koji.krbV else koji.AuthError
        try:
            session.krb_login()
        except exc as e:
            raise RebaseHelperError('Login failed: {}'.format(str(e)))
        else:
            return session
github rebase-helper / rebase-helper / rebasehelper / application.py View on Github external
raise
            except BinaryPackageBuildError as e:
                build_dict['logs'] = e.logs
                build_dict['binary_package_build_error'] = str(e)
                build_dict = self._sanitize_build_dict(build_dict)
                results_store.set_build_data(version, build_dict)

                if e.logfile is None:
                    msg = 'Building {} RPM packages failed; see logs in {} for more information'.format(version,
                                                                                                        results_dir)
                else:
                    msg = 'Building {} RPM packages failed; see {} for more information'.format(version, e.logfile)

                raise RebaseHelperError(msg, logfiles=e.logs)
            except Exception:
                raise RebaseHelperError('Building package failed with unknown reason. '
                                        'Check all available log files.')

        if self.conf.builds_nowait and not self.conf.build_tasks:
            if builder.CREATES_TASKS:
                self.print_task_info(builder)
github rebase-helper / rebase-helper / rebasehelper / application.py View on Github external
def _find_spec_file(self) -> str:
        """Finds a spec file in the execution_dir directory.

        Returns:
            Path to the spec file.

        Raises:
            RebaseHelperError: If no spec file could be found.

        """
        spec_file_path = PathHelper.find_first_file(self.execution_dir, '*.spec', 0)
        if not spec_file_path:
            raise RebaseHelperError("Could not find any SPEC file "
                                    "in the current directory '{}'".format(self.execution_dir))
        return spec_file_path
github rebase-helper / rebase-helper / rebasehelper / application.py View on Github external
else:
            logger.verbose("argument passed as a new source is a version")
            version_string = self.conf.sources
        version, extra_version = SpecFile.split_version_string(version_string, self.spec_file.header.version)
        self.rebase_spec_file.set_version(version)
        self.rebase_spec_file.set_extra_version(extra_version, version != self.spec_file.header.version)

        self._sanitize_sources()

        oldver = parse_version(self.spec_file.header.version)
        newver = parse_version(self.rebase_spec_file.header.version)
        oldex = self.spec_file.parse_release()[2]
        newex = extra_version

        if not self.conf.skip_version_check and (newver < oldver or (newver == oldver and newex == oldex)):
            raise RebaseHelperError("Current version is equal to or newer than the requested version, nothing to do.")

        self.rebase_spec_file.update_changelog(self.conf.changelog_entry)

        # run spec hooks
        plugin_manager.spec_hooks.run(self.spec_file, self.rebase_spec_file, **self.kwargs)

        # spec file object has been sanitized downloading can proceed
        if not self.conf.not_download_sources:
            for spec_file in [self.spec_file, self.rebase_spec_file]:
                spec_file.download_remote_sources()
                # parse spec again with sources downloaded to properly expand %prep section
                spec_file.update()
github rebase-helper / rebase-helper / rebasehelper / application.py View on Github external
def extract_archive(archive_path, destination):
        """
        Extracts given archive into the destination and handle all exceptions.

        :param archive_path: path to the archive to be extracted
        :param destination: path to a destination, where the archive should be extracted to
        :return:
        """
        archive = Archive(archive_path)

        try:
            archive.extract_archive(destination)
        except IOError:
            raise RebaseHelperError("Archive '{}' can not be extracted".format(archive_path))
        except (EOFError, SystemError):
            raise RebaseHelperError("Archive '{}' is damaged".format(archive_path))
github rebase-helper / rebase-helper / rebasehelper / application.py View on Github external
results_store.set_build_data(version, build_dict)
            except RebaseHelperError:  # pylint: disable=try-except-raise
                raise
            except SourcePackageBuildError as e:
                build_dict['logs'] = e.logs
                build_dict['source_package_build_error'] = str(e)
                build_dict = self._sanitize_build_dict(build_dict)
                results_store.set_build_data(version, build_dict)
                if e.logfile:
                    msg = 'Building {} SRPM packages failed; see {} for more information'.format(version, e.logfile)
                else:
                    msg = 'Building {} SRPM packages failed; see logs in {} for more information'.format(version,
                                                                                                         results_dir)
                raise RebaseHelperError(msg, logfiles=e.logs)
            except Exception:
                raise RebaseHelperError('Building package failed with unknown reason. '
                                        'Check all available log files.')
github rebase-helper / rebase-helper / rebasehelper / specfile.py View on Github external
def parse_release(self) -> Tuple[bool, int, Optional[str]]:
        """Parses release string.

        Returns:
            Tuple of is_prerelease, release_number and extra_version.

        Raises:
            RebaseHelperError in case release string is not valid.

        """
        release = self.get_release()
        m = re.match(r'^(0\.)?(\d+)(?:\.(.+))?$', release)
        if not m:
            raise RebaseHelperError('Invalid release string: {}'.format(release))
        return bool(m.group(1)), int(m.group(2)), m.group(3)
github rebase-helper / rebase-helper / rebasehelper / plugins / checkers / pkgdiff.py View on Github external
cmd.append(file_name)
        cmd.append('-extra-info')
        cmd.append(cls.results_dir)
        cmd.append('-report-path')
        cmd.append(cls.pkgdiff_results_full_path_html)
        try:
            ret_code = ProcessHelper.run_subprocess(cmd, output_file=ProcessHelper.DEV_NULL)
        except OSError:
            raise CheckerNotFoundError("Checker '{}' was not found or installed.".format(cls.name))

        # From pkgdiff source code:
        # ret_code 0 means unchanged
        # ret_code 1 means Changed
        # other return codes means error
        if int(ret_code) != 0 and int(ret_code) != 1:
            raise RebaseHelperError('Execution of {} failed.\nCommand line is: {}'.format(cls.CMD, cmd))
        results_dict = cls.process_xml_results(cls.results_dir)
        lines: List[str] = []

        for key, val in results_dict.items():
            if val:
                if lines:
                    lines.append('')
                lines.append('Following files were {}:'.format(key))
                lines.extend(val)

        pkgdiff_report = os.path.join(cls.results_dir, cls.pkgdiff_results_filename + '.txt')
        try:
            with open(pkgdiff_report, "w") as f:
                f.write('\n'.join(lines))
        except IOError:
            raise RebaseHelperError("Unable to write result from {} to '{}'".format(cls.name, pkgdiff_report))
github rebase-helper / rebase-helper / rebasehelper / plugins / checkers / rpmdiff.py View on Github external
for key, val in results_dict.items():
            if val:
                if lines:
                    lines.append('')
                lines.append('Following files were {}:'.format(key))
                lines.extend(val)

        rpmdiff_report = os.path.join(cls.results_dir, 'report.txt')

        counts = {k: len(v) for k, v in results_dict.items()}

        try:
            with open(rpmdiff_report, "w") as f:
                f.write('\n'.join(lines))
        except IOError:
            raise RebaseHelperError("Unable to write result from {} to '{}'".format(cls.name, rpmdiff_report))

        return {'path': cls.get_checker_output_dir_short(), 'files_changes': counts}
github rebase-helper / rebase-helper / rebasehelper / application.py View on Github external
build_dict.update(builder.build(spec, results_dir, **build_dict))
                build_dict = self._sanitize_build_dict(build_dict)
                results_store.set_build_data(version, build_dict)
            except RebaseHelperError:  # pylint: disable=try-except-raise
                raise
            except SourcePackageBuildError as e:
                build_dict['logs'] = e.logs
                build_dict['source_package_build_error'] = str(e)
                build_dict = self._sanitize_build_dict(build_dict)
                results_store.set_build_data(version, build_dict)
                if e.logfile:
                    msg = 'Building {} SRPM packages failed; see {} for more information'.format(version, e.logfile)
                else:
                    msg = 'Building {} SRPM packages failed; see logs in {} for more information'.format(version,
                                                                                                         results_dir)
                raise RebaseHelperError(msg, logfiles=e.logs)
            except Exception:
                raise RebaseHelperError('Building package failed with unknown reason. '
                                        'Check all available log files.')