How to use the rebasehelper.helpers.process_helper.ProcessHelper 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 / plugins / build_tools / srpm / rpmbuild.py View on Github external
Returns:
            Tuple, the first element is path to SRPM, the second is a list of paths
            to logs.

        """
        logger.info("Building SRPM")
        spec_loc, spec_name = os.path.split(spec)
        output = os.path.join(results_dir, "build.log")

        cmd = [cls.CMD, '-bs', spec_name]

        if srpm_builder_options is not None:
            cmd.extend(srpm_builder_options)

        ret = ProcessHelper.run_subprocess_cwd_env(cmd,
                                                   cwd=spec_loc,
                                                   env={'HOME': workdir},
                                                   output_file=output)

        build_log_path = os.path.join(srpm_results_dir, 'build.log')
        logs = []
        for l in PathHelper.find_all_files(results_dir, '*.log'):
            logs.append(os.path.join(srpm_results_dir, os.path.basename(l)))

        if ret == 0:
            return PathHelper.find_first_file(workdir, '*.src.rpm'), logs
        # An error occurred, raise an exception
        raise SourcePackageBuildError("Building SRPM failed!", logfile=build_log_path, logs=logs)
github rebase-helper / rebase-helper / rebasehelper / helpers / git_helper.py View on Github external
def run_mergetool(cls, repo):
        # we can't use GitPython here, as it doesn't allow
        # for the command to attach to stdout directly
        cwd = os.getcwd()
        try:
            os.chdir(repo.working_tree_dir)
            ProcessHelper.run_subprocess(['git', 'mergetool'])
        finally:
            os.chdir(cwd)
github rebase-helper / rebase-helper / rebasehelper / helpers / rpm_helper.py View on Github external
Args:
            spec_path (str): Absolute path to the SPEC file.
            assume_yes (bool): Whether to automatically answer 'yes' to all questions.

        Returns:
            int: Exit code of the subprocess run.

        """
        cmd = ['dnf', 'builddep', spec_path]
        if os.geteuid() != 0:
            logger.warning("Authentication required to install build dependencies using '%s'", ' '.join(cmd))
            cmd = ['pkexec'] + cmd
        if assume_yes:
            cmd.append('-y')
        return ProcessHelper.run_subprocess(cmd)
github rebase-helper / rebase-helper / rebasehelper / plugins / checkers / abipkgdiff.py View on Github external
def is_available(cls):
        try:
            return ProcessHelper.run_subprocess([cls.CMD, '--help'], output_file=ProcessHelper.DEV_NULL) == 3
        except (IOError, OSError):
            return False
github rebase-helper / rebase-helper / rebasehelper / plugins / checkers / licensecheck.py View on Github external
def is_available(cls):
        try:
            return ProcessHelper.run_subprocess([cls.CMD, '--help'], output_file=ProcessHelper.DEV_NULL) == 0
        except (IOError, OSError):
            return False
github rebase-helper / rebase-helper / rebasehelper / plugins / checkers / csmock.py View on Github external
csmock_report = {}

        old_pkgs = results_store.get_old_build().get('srpm', None)
        new_pkgs = results_store.get_new_build().get('srpm', None)
        cls.results_dir = os.path.join(results_dir, cls.CMD)
        cls.prepare_results_dir()
        arguments = ['--force', '-a', '-r', 'fedora-rawhide-x86_64', '--base-srpm']
        if old_pkgs and new_pkgs:
            cmd = [cls.CMD]
            cmd.extend(arguments)
            cmd.append(old_pkgs)
            cmd.append(new_pkgs)
            cmd.extend(['-o', results_dir])
            output = io.StringIO()
            try:
                ProcessHelper.run_subprocess(cmd, output_file=output)
            except OSError:
                raise CheckerNotFoundError("Checker '{}' was not found or installed.".format(cls.name))
        csmock_report['error'] = PathHelper.find_all_files_current_dir(results_dir, '*.err')
        csmock_report['txt'] = PathHelper.find_all_files_current_dir(results_dir, '*.txt')
        csmock_report['log'] = PathHelper.find_all_files_current_dir(results_dir, '*.log')
        csmock_report['path'] = cls.get_checker_output_dir_short()
        return csmock_report
github rebase-helper / rebase-helper / rebasehelper / plugins / checkers / abipkgdiff.py View on Github external
old_name = RpmHelper.split_nevra(os.path.basename(pkg))['name']
            find = [x for x in rest_pkgs_new if RpmHelper.split_nevra(os.path.basename(x))['name'] == old_name]
            if not find:
                logger.warning('New version of package %s was not found!', old_name)
                continue
            new_pkg = find[0]
            debug = cls._find_debuginfo(debug_new, new_pkg)
            if debug:
                command.append('--d2')
                command.append(debug)
            command.append(pkg)
            command.append(new_pkg)
            logger.verbose('Package name for ABI comparison %s', old_name)
            output = os.path.join(cls.results_dir, old_name + '.txt')
            try:
                ret_code = ProcessHelper.run_subprocess(command, output_file=output)
            except OSError:
                raise CheckerNotFoundError("Checker '{}' was not found or installed.".format(cls.name))

            if int(ret_code) & cls.ABIDIFF_ERROR and int(ret_code) & cls.ABIDIFF_USAGE_ERROR:
                raise RebaseHelperError('Execution of {} failed.\nCommand line is: {}'.format(cls.CMD, cmd))
            ret_codes[old_name] = int(ret_code)
        return dict(packages=cls.parse_abi_logs(ret_codes),
                    abi_changes=any(x & cls.ABIDIFF_ABI_CHANGE for x in ret_codes.values()),
                    abi_incompatible_changes=any(x & cls.ABIDIFF_ABI_INCOMPATIBLE_CHANGE for x in ret_codes.values()),
                    path=cls.get_checker_output_dir_short(),
                    ret_codes=ret_codes)
github rebase-helper / rebase-helper / rebasehelper / plugins / checkers / pkgdiff.py View on Github external
cls.prepare_results_dir()
        cls.pkgdiff_results_full_path_html = os.path.join(cls.results_dir, cls.pkgdiff_results_filename + '.html')

        cmd = [cls.CMD]
        cmd.append('-hide-unchanged')
        for version in ['old', 'new']:
            old = results_store.get_build(version)
            if old:
                file_name = cls._create_xml(version, input_structure=old)
                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('')
github rebase-helper / rebase-helper / rebasehelper / plugins / spec_hooks / ruby_helper.py View on Github external
def _build_source_from_instructions(cls, instructions, source, logfile):
        """Run instructions to create source archive"""
        logger.info("Attempting to create source '%s' using instructions in comments", source)
        with TemporaryEnvironment() as tmp:
            script = os.path.join(tmp.path(), 'script.sh')
            with open(script, 'w') as f:
                f.write('#!/bin/sh -x\n')
                f.write('{}\n'.format('\n'.join(instructions)))
                f.write('cp "{}" "{}"\n'.format(source, os.getcwd()))
            os.chmod(script, 0o755)
            result = ProcessHelper.run_subprocess_cwd(script, tmp.path(), output_file=logfile, shell=True)
        if result == 0 and os.path.isfile(source):
            logger.info('Source creation succeeded.')
        else:
            logger.info('Source creation failed.')
github rebase-helper / rebase-helper / rebasehelper / helpers / process_helper.py View on Github external
def run_subprocess(cmd, input_file=None, output_file=None, ignore_stderr=False):
        """Runs the specified command in a subprocess.

        Args:
            cmd (iterable): A sequence of program arguments.
            input_file (str, typing.BytesIO): File to read the input from.
            output_file (str, typing.BytesIO): File to write the output of the command to.
            ignore_stderr (bool): Whether to ignore stderr output.

        Returns:
            int: Exit code of the subprocess.

        """
        return ProcessHelper.run_subprocess_cwd(cmd,
                                                input_file=input_file,
                                                output_file=output_file,
                                                ignore_stderr=ignore_stderr)