示例#1
0
 def test_find_with_recursion(self, filelist):
     assert PathHelper.find_first_file(os.path.curdir, "*.spec",
                                       0) is None
     assert PathHelper.find_first_file(os.path.curdir, "*.spec",
                                       1) is None
     assert PathHelper.find_first_file(os.path.curdir, "*.spec",
                                       2) is None
     assert PathHelper.find_first_file(os.path.curdir, "*.spec",
                                       3) is None
     assert PathHelper.find_first_file(
         os.path.curdir, "*.spec", 4) == os.path.abspath(filelist[-1])
示例#2
0
    def _build_srpm(cls, spec, workdir, results_dir, srpm_results_dir, srpm_builder_options):
        """
        Build SRPM using rpmbuild.

        :param spec: abs path to SPEC file inside the rpmbuild/SPECS in workdir.
        :param workdir: abs path to working directory with rpmbuild directory
                        structure, which will be used as HOME dir.
        :param results_dir: abs path to dir where the log should be placed.
        :param srpm_results_dir: path to directory where SRPM will be placed.
        :param srpm_builder_options: list of additional options to rpmbuild.
        :return: abs path to built SRPM.
        """
        logger.info("Building SRPM")
        spec_loc, spec_name = os.path.split(spec)
        output = os.path.join(results_dir, "build.log")

        cmd = ['rpmbuild', '-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')

        if ret == 0:
            return PathHelper.find_first_file(workdir, '*.src.rpm')
        # An error occurred, raise an exception
        logfile = build_log_path
        logs = [l for l in PathHelper.find_all_files(results_dir, '*.log')]
        cls.logs = [os.path.join(srpm_results_dir, os.path.basename(l)) for l in logs]
        raise SourcePackageBuildError("Building SRPM failed!", logfile=logfile)
示例#3
0
    def _build_srpm(cls, spec, workdir, results_dir, srpm_results_dir,
                    srpm_builder_options):
        """Builds SRPM using mock.

        Args:
            spec: Path to SPEC file to build the SRPM from.
            workdir: Path to working directory with rpmbuild directory structure.
            results_dir: Path to directory where logs will be placed.
            srpm_results_dir: Path to directory where SRPM will be placed.
            srpm_builder_options: Additional mock options.

        Returns:
            Tuple, the first element is path to SRPM, the second is a list of paths
            to logs.

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

        path_to_sources = os.path.join(workdir, 'SOURCES')

        cmd = [cls.CMD, '--old-chroot', '--buildsrpm']
        if srpm_builder_options is not None:
            cmd.extend(srpm_builder_options)
        cmd.extend(['--spec', spec])
        cmd.extend(['--sources', path_to_sources])
        cmd.extend(['--resultdir', results_dir])

        if not check_mock_privileges():
            cmd = ['pkexec'] + cmd

        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')
        mock_log_path = os.path.join(srpm_results_dir, 'mock_output.log')
        root_log_path = os.path.join(srpm_results_dir, 'root.log')
        logs = []
        for log in PathHelper.find_all_files(results_dir, '*.log'):
            logs.append(os.path.join(srpm_results_dir, os.path.basename(log)))

        if ret == 0:
            return PathHelper.find_first_file(workdir, '*.src.rpm'), logs
        if ret == 1:
            if not os.path.exists(build_log_path) and os.path.exists(
                    mock_log_path):
                logfile = mock_log_path
            else:
                logfile = build_log_path
        else:
            logfile = root_log_path
        raise SourcePackageBuildError("Building SRPM failed!",
                                      logfile=logfile,
                                      logs=logs)
示例#4
0
    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
示例#5
0
    def _build_srpm(cls, spec, workdir, results_dir, srpm_results_dir, srpm_builder_options):
        """
        Build SRPM using mock.

        :param spec: abs path to SPEC file inside the rpmbuild/SPECS in workdir.
        :param workdir: abs path to working directory with rpmbuild directory
                        structure, which will be used as HOME dir.
        :param results_dir: abs path to dir where the log should be placed.
        :param srpm_results_dir: path to directory where SRPM will be placed.
        :param srpm_builder_options: list of additional options for mock build tool(eg. '-r fedora-XX-x86_64').
        :return:  abs path to built SRPM.
        """
        logger.info("Building SRPM")
        spec_loc = os.path.dirname(spec)
        output = os.path.join(results_dir, "build.log")

        path_to_sources = os.path.join(workdir, 'SOURCES')

        cmd = ['mock', '--old-chroot', '--buildsrpm']
        if srpm_builder_options is not None:
            cmd.extend(srpm_builder_options)
        cmd.extend(['--spec', spec])
        cmd.extend(['--sources', path_to_sources])
        cmd.extend(['--resultdir', results_dir])

        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')
        mock_log_path = os.path.join(srpm_results_dir, 'mock_output.log')
        root_log_path = os.path.join(srpm_results_dir, 'root.log')

        if ret == 0:
            return PathHelper.find_first_file(workdir, '*.src.rpm')
        if ret == 1:
            if not os.path.exists(build_log_path) and os.path.exists(mock_log_path):
                logfile = mock_log_path
            else:
                logfile = build_log_path
        else:
            logfile = root_log_path
        logs = [l for l in PathHelper.find_all_files(results_dir, '*.log')]
        cls.logs = [os.path.join(srpm_results_dir, os.path.basename(l)) for l in logs]
        raise SourcePackageBuildError("Building SRPM failed!", logfile=logfile)
示例#6
0
    def _build_srpm(cls, spec, workdir, results_dir, srpm_results_dir, srpm_builder_options):
        """
        Build SRPM using mock.

        :param spec: abs path to SPEC file inside the rpmbuild/SPECS in workdir.
        :param workdir: abs path to working directory with rpmbuild directory
                        structure, which will be used as HOME dir.
        :param results_dir: abs path to dir where the log should be placed.
        :param srpm_results_dir: path to directory where SRPM will be placed.
        :param srpm_builder_options: list of additional options for mock build tool(eg. '-r fedora-XX-x86_64').
        :return:  abs path to built SRPM.
        """
        logger.info("Building SRPM")
        spec_loc = os.path.dirname(spec)
        output = os.path.join(results_dir, "build.log")

        path_to_sources = os.path.join(workdir, 'SOURCES')

        cmd = ['mock', '--old-chroot', '--buildsrpm']
        if srpm_builder_options is not None:
            cmd.extend(srpm_builder_options)
        cmd.extend(['--spec', spec])
        cmd.extend(['--sources', path_to_sources])
        cmd.extend(['--resultdir', results_dir])

        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')
        mock_log_path = os.path.join(srpm_results_dir, 'mock_output.log')
        root_log_path = os.path.join(srpm_results_dir, 'root.log')

        if ret == 0:
            return PathHelper.find_first_file(workdir, '*.src.rpm')
        if ret == 1:
            if not os.path.exists(build_log_path) and os.path.exists(mock_log_path):
                logfile = mock_log_path
            else:
                logfile = build_log_path
        else:
            logfile = root_log_path
        logs = [l for l in PathHelper.find_all_files(results_dir, '*.log')]
        cls.logs = [os.path.join(srpm_results_dir, os.path.basename(l)) for l in logs]
        raise SourcePackageBuildError("Building SRPM failed!", logfile=logfile)
示例#7
0
    def build(cls, spec, results_dir, srpm, **kwargs):
        """
        Builds the RPMs using mock

        :param spec: SpecFile object
        :param results_dir: absolute path to directory where results will be stored
        :param srpm: absolute path to SRPM
        :param root: mock root used for building
        :param arch: architecture to build the RPM for
        :return: dict with:
                 'rpm' -> list with absolute paths to RPMs
                 'logs' -> list with absolute paths to logs
        """
        cls.logs = []
        rpm_results_dir = os.path.join(results_dir, "RPM")
        sources = spec.get_sources()
        patches = [p.get_path() for p in spec.get_patches()]
        with MockTemporaryEnvironment(sources, patches, spec.get_path(),
                                      rpm_results_dir) as tmp_env:
            env = tmp_env.env()
            tmp_results_dir = env.get(MockTemporaryEnvironment.TEMPDIR_RESULTS)
            rpms = cls._build_rpm(
                srpm,
                tmp_results_dir,
                rpm_results_dir,
                builder_options=cls.get_builder_options(**kwargs))
            # remove SRPM - side product of building RPM
            tmp_srpm = PathHelper.find_first_file(tmp_results_dir, "*.src.rpm")
            if tmp_srpm is not None:
                os.unlink(tmp_srpm)

        logger.info("Building RPMs finished successfully")

        rpms = [
            os.path.join(rpm_results_dir, os.path.basename(f)) for f in rpms
        ]
        logger.verbose("Successfully built RPMs: '%s'", str(rpms))

        # gather logs
        cls.logs.extend(
            [l for l in PathHelper.find_all_files(rpm_results_dir, '*.log')])
        logger.verbose("logs: '%s'", str(cls.logs))

        return dict(rpm=rpms, logs=cls.logs)
示例#8
0
    def _build_srpm(cls, spec, workdir, results_dir, srpm_results_dir, srpm_builder_options):
        """Builds SRPM using rpmbuild.

        Args:
            spec: Path to SPEC file to build the SRPM from.
            workdir: Path to working directory with rpmbuild directory structure.
            results_dir: Path to directory where logs will be placed.
            srpm_results_dir: Path to directory where SRPM will be placed.
            srpm_builder_options: Additional rpmbuild options.

        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)
示例#9
0
    def _build_srpm(cls, spec, workdir, results_dir, srpm_results_dir,
                    srpm_builder_options):
        """
        Build SRPM using rpmbuild.

        :param spec: abs path to SPEC file inside the rpmbuild/SPECS in workdir.
        :param workdir: abs path to working directory with rpmbuild directory
                        structure, which will be used as HOME dir.
        :param results_dir: abs path to dir where the log should be placed.
        :param srpm_results_dir: path to directory where SRPM will be placed.
        :param srpm_builder_options: list of additional options to rpmbuild.
        :return: abs path to built SRPM.
        """
        logger.info("Building SRPM")
        spec_loc, spec_name = os.path.split(spec)
        output = os.path.join(results_dir, "build.log")

        cmd = ['rpmbuild', '-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')

        if ret == 0:
            return PathHelper.find_first_file(workdir, '*.src.rpm')
        # An error occurred, raise an exception
        logfile = build_log_path
        logs = [l for l in PathHelper.find_all_files(results_dir, '*.log')]
        cls.logs = [
            os.path.join(srpm_results_dir, os.path.basename(l)) for l in logs
        ]
        raise SourcePackageBuildError("Building SRPM failed!", logfile=logfile)
示例#10
0
    def build(cls, spec, results_dir, srpm, **kwargs):
        """
        Builds the RPMs using mock

        :param spec: SpecFile object
        :param results_dir: absolute path to directory where results will be stored
        :param srpm: absolute path to SRPM
        :param root: mock root used for building
        :param arch: architecture to build the RPM for
        :return: dict with:
                 'rpm' -> list with absolute paths to RPMs
                 'logs' -> list with absolute paths to logs
        """
        cls.logs = []
        rpm_results_dir = os.path.join(results_dir, "RPM")
        sources = spec.get_sources()
        patches = [p.get_path() for p in spec.get_patches()]
        with MockTemporaryEnvironment(sources, patches, spec.get_path(), rpm_results_dir) as tmp_env:
            env = tmp_env.env()
            tmp_results_dir = env.get(MockTemporaryEnvironment.TEMPDIR_RESULTS)
            rpms = cls._build_rpm(srpm, tmp_results_dir, rpm_results_dir,
                                  builder_options=cls.get_builder_options(**kwargs))
            # remove SRPM - side product of building RPM
            tmp_srpm = PathHelper.find_first_file(tmp_results_dir, "*.src.rpm")
            if tmp_srpm is not None:
                os.unlink(tmp_srpm)

        logger.info("Building RPMs finished successfully")

        rpms = [os.path.join(rpm_results_dir, os.path.basename(f)) for f in rpms]
        logger.verbose("Successfully built RPMs: '%s'", str(rpms))

        # gather logs
        cls.logs.extend(l for l in PathHelper.find_all_files(rpm_results_dir, '*.log'))
        logger.verbose("logs: '%s'", str(cls.logs))

        return dict(rpm=rpms, logs=cls.logs)
示例#11
0
 def test_find_ffile(self, filelist):
     assert PathHelper.find_first_file(
         "dir1", "*le") == os.path.abspath(filelist[9])
     assert PathHelper.find_first_file(
         "dir1", "ff*") == os.path.abspath(filelist[8])
     assert PathHelper.find_first_file("dir1/foo", "ff*") is None
示例#12
0
 def test_find_pythoon(self, filelist):
     assert PathHelper.find_first_file(
         "dir1", "pythooon") == os.path.abspath(filelist[4])
     assert PathHelper.find_first_file(
         os.path.curdir, "py*n") == os.path.abspath(filelist[4])
     assert PathHelper.find_first_file("dir1/bar", "pythooon") is None
示例#13
0
 def test_find_without_recursion(self, filelist):
     assert PathHelper.find_first_file(
         os.path.curdir, "*.spec") == os.path.abspath(filelist[-1])
示例#14
0
 def test_find_pythoon(self, filelist):
     assert PathHelper.find_first_file(
         "dir1", "pythooon") == os.path.abspath(filelist[4])
     assert PathHelper.find_first_file(
         os.path.curdir, "py*n") == os.path.abspath(filelist[4])
     assert PathHelper.find_first_file("dir1/bar", "pythooon") is None
示例#15
0
 def test_find_ffile(self, filelist):
     assert PathHelper.find_first_file(
         "dir1", "*le") == os.path.abspath(filelist[9])
     assert PathHelper.find_first_file(
         "dir1", "ff*") == os.path.abspath(filelist[8])
     assert PathHelper.find_first_file("dir1/foo", "ff*") is None
示例#16
0
 def test_find_file(self, filelist):
     assert PathHelper.find_first_file(
         "dir1", "file") == os.path.abspath(filelist[9])
     assert PathHelper.find_first_file(
         os.path.curdir, "file") == os.path.abspath(filelist[0])
     assert PathHelper.find_first_file("dir1/baz", "file") is None
示例#17
0
 def _get_spec_file(self):
     """Function gets the spec file from the execution_dir directory"""
     self.spec_file_path = PathHelper.find_first_file(self.execution_dir, '*.spec', 0)
     if not self.spec_file_path:
         raise RebaseHelperError("Could not find any SPEC file in the current directory '%s'" % self.execution_dir)
示例#18
0
 def _get_spec_file(self):
     """Function gets the spec file from the execution_dir directory"""
     self.spec_file_path = PathHelper.find_first_file(self.execution_dir, '*.spec', 0)
     if not self.spec_file_path:
         raise RebaseHelperError("Could not find any SPEC file "
                                 "in the current directory '{}'".format(self.execution_dir))
示例#19
0
 def test_find_without_recursion(self, filelist):
     assert PathHelper.find_first_file(os.path.curdir, "*.spec") == os.path.abspath(filelist[-1])
示例#20
0
 def test_find_with_recursion(self, filelist):
     assert PathHelper.find_first_file(os.path.curdir, "*.spec", 0) is None
     assert PathHelper.find_first_file(os.path.curdir, "*.spec", 1) is None
     assert PathHelper.find_first_file(os.path.curdir, "*.spec", 2) is None
     assert PathHelper.find_first_file(os.path.curdir, "*.spec", 3) is None
     assert PathHelper.find_first_file(os.path.curdir, "*.spec", 4) == os.path.abspath(filelist[-1])
示例#21
0
 def test_find_file(self, filelist):
     assert PathHelper.find_first_file(
         "dir1", "file") == os.path.abspath(filelist[9])
     assert PathHelper.find_first_file(
         os.path.curdir, "file") == os.path.abspath(filelist[0])
     assert PathHelper.find_first_file("dir1/baz", "file") is None