def test_find_ffile(self, filelist): assert PathHelper.find_first_dir_with_file( "dir1", "*le") == os.path.abspath(os.path.dirname(filelist[9])) assert PathHelper.find_first_dir_with_file( "dir1", "ff*") == os.path.abspath(os.path.dirname(filelist[8])) assert PathHelper.find_first_dir_with_file("dir1/foo", "ff*") is None
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)
def _build_rpm(cls, srpm, workdir, results_dir, rpm_results_dir, builder_options=None): """ Build RPM using rpmbuild. :param srpm: abs path to SRPM :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 rpm_results_dir: path directory to where RPMs will be placed. :return: abs paths to built RPMs. """ logger.info("Building RPMs") output = os.path.join(results_dir, "build.log") cmd = [cls.CMD, '--rebuild', srpm] if builder_options is not None: cmd.extend(builder_options) ret = ProcessHelper.run_subprocess_cwd_env(cmd, env={'HOME': workdir}, output_file=output) build_log_path = os.path.join(rpm_results_dir, 'build.log') if ret == 0: return [f for f in PathHelper.find_all_files(workdir, '*.rpm') if not f.endswith('.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.extend(os.path.join(rpm_results_dir, os.path.basename(l)) for l in logs) raise BinaryPackageBuildError("Building RPMs failed!", results_dir, logfile=logfile)
def _build_rpm(cls, srpm, workdir, results_dir, rpm_results_dir, builder_options=None): """ Build RPM using rpmbuild. :param srpm: abs path to SRPM :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 rpm_results_dir: path directory to where RPMs will be placed. :return: abs paths to built RPMs. """ logger.info("Building RPMs") output = os.path.join(results_dir, "build.log") cmd = [cls.CMD, '--rebuild', srpm] if builder_options is not None: cmd.extend(builder_options) ret = ProcessHelper.run_subprocess_cwd_env(cmd, env={'HOME': workdir}, output_file=output) build_log_path = os.path.join(rpm_results_dir, 'build.log') if ret == 0: return [f for f in PathHelper.find_all_files(workdir, '*.rpm') if not f.endswith('.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.extend([os.path.join(rpm_results_dir, os.path.basename(l)) for l in logs]) raise BinaryPackageBuildError("Building RPMs failed!", results_dir, logfile=logfile)
def run_check(cls, results_dir, **kwargs): """Compares old and new RPMs using pkgdiff""" csmock_report = {} old_pkgs = results_store.get_old_build().get('srpm', None) new_pkgs = results_store.get_new_build().get('srpm', None) results_dir = os.path.join(results_dir, cls.CMD) os.makedirs(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
def run_check(cls, results_dir, **kwargs): """Compares old and new RPMs using pkgdiff""" 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 as e: raise CheckerNotFoundError( "Checker '{}' was not found or installed.".format( cls.name)) from e 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
def _build_rpm(cls, srpm, results_dir, rpm_results_dir, root=None, arch=None, builder_options=None): """ Build RPM using mock. :param srpm: full path to the srpm. :param results_dir: abs path to dir where the log should be placed. :param rpm_results_dir: directory where rpms will be placed. :param root: path to where chroot should be built. :param arch: target architectures for the build. :param builder_options: builder_options for mock. :return abs paths to RPMs. """ logger.info("Building RPMs") output = os.path.join(results_dir, "mock_output.log") cmd = [cls.CMD, '--old-chroot', '--rebuild', srpm, '--resultdir', results_dir] if root is not None: cmd.extend(['--root', root]) if arch is not None: cmd.extend(['--arch', arch]) if builder_options is not None: cmd.extend(builder_options) ret = ProcessHelper.run_subprocess(cmd, output_file=output) if ret == 0: return [f for f in PathHelper.find_all_files(results_dir, '*.rpm') if not f.endswith('.src.rpm')] else: logfile = Mock.get_mock_logfile_path(ret, rpm_results_dir, tmp_path=results_dir) logs = [l for l in PathHelper.find_all_files(results_dir, '*.log')] cls.logs.extend(os.path.join(rpm_results_dir, os.path.basename(l)) for l in logs) raise BinaryPackageBuildError("Building RPMs failed!", rpm_results_dir, logfile=logfile)
def test_find_pythoon(self, filelist): assert PathHelper.find_first_dir_with_file( "dir1", "pythooon") == os.path.abspath( os.path.dirname(filelist[4])) assert PathHelper.find_first_dir_with_file( os.path.curdir, "py*n") == os.path.abspath(os.path.dirname(filelist[4])) assert PathHelper.find_first_dir_with_file( "dir1/bar", "pythooon") is None
def test_find_file(self, filelist): assert PathHelper.find_first_dir_with_file( "dir1", "file") == os.path.abspath( os.path.dirname(filelist[9])) assert PathHelper.find_first_dir_with_file( os.path.curdir, "file") == os.path.abspath(os.path.dirname(filelist[0])) assert PathHelper.find_first_dir_with_file( "dir1/baz", "file") is None
def test_find_ffile(self, filelist): assert PathHelper.find_first_dir_with_file( "dir1", "*le") == os.path.abspath( os.path.dirname(filelist[9])) assert PathHelper.find_first_dir_with_file( "dir1", "ff*") == os.path.abspath( os.path.dirname(filelist[8])) assert PathHelper.find_first_dir_with_file( "dir1/foo", "ff*") is None
def test_find_pythoon(self, filelist): assert PathHelper.find_first_dir_with_file( "dir1", "pythooon") == os.path.abspath(os.path.dirname(filelist[4])) assert PathHelper.find_first_dir_with_file( os.path.curdir, "py*n") == os.path.abspath(os.path.dirname(filelist[4])) assert PathHelper.find_first_dir_with_file("dir1/bar", "pythooon") is None
def test_find_file(self, filelist): assert PathHelper.find_first_dir_with_file( "dir1", "file") == os.path.abspath(os.path.dirname(filelist[9])) assert PathHelper.find_first_dir_with_file( os.path.curdir, "file") == os.path.abspath(os.path.dirname(filelist[0])) assert PathHelper.find_first_dir_with_file("dir1/baz", "file") is None
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)
def _build_rpm(cls, srpm, results_dir, rpm_results_dir, root=None, arch=None, builder_options=None): """Builds RPMs using mock. Args: srpm: Path to SRPM. results_dir: Path to directory where logs will be placed. rpm_results_dir: Path to directory where rpms will be placed. root: Path to where chroot will be built arch: Target architectures for the build. builder_options: Additional options for mock. Returns: Tuple where first element is list of paths to built RPMs and the second element is list of paths to logs. """ logger.info("Building RPMs") output = os.path.join(results_dir, "mock_output.log") cmd = [ cls.CMD, '--old-chroot', '--rebuild', srpm, '--resultdir', results_dir ] if root is not None: cmd.extend(['--root', root]) if arch is not None: cmd.extend(['--arch', arch]) if builder_options is not None: cmd.extend(builder_options) if not check_mock_privileges(): cmd = ['pkexec'] + cmd ret = ProcessHelper.run_subprocess(cmd, output_file=output) logs = [] for log in PathHelper.find_all_files(results_dir, '*.log'): logs.append(os.path.join(rpm_results_dir, os.path.basename(log))) if ret == 0: return [ f for f in PathHelper.find_all_files(results_dir, '*.rpm') if not f.endswith('.src.rpm') ], logs else: logfile = get_mock_logfile_path(ret, rpm_results_dir, tmp_path=results_dir) raise BinaryPackageBuildError("Building RPMs failed!", rpm_results_dir, logfile=logfile, logs=logs)
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])
def get_all_log_files(self): """ Function returns all log_files created by rebase-helper First if debug log file and second is report summary log file :return: """ log_list = [] if PathHelper.file_available(self.debug_log_file): log_list.append(self.debug_log_file) if PathHelper.file_available(self.report_log_file): log_list.append(self.report_log_file) return log_list
def get_all_log_files(self): """ Function returns all log_files created by rebase-helper First if debug log file and second is report summary log file :return: """ log_list = [] if PathHelper.file_available(self.debug_log_file): log_list.append(self.debug_log_file) if PathHelper.file_available(self.report_log_file): log_list.append(self.report_log_file) return log_list
def _build_rpm(cls, srpm, results_dir, rpm_results_dir, root=None, arch=None, builder_options=None): """ Build RPM using mock. :param srpm: full path to the srpm. :param results_dir: abs path to dir where the log should be placed. :param rpm_results_dir: directory where rpms will be placed. :param root: path to where chroot should be built. :param arch: target architectures for the build. :param builder_options: builder_options for mock. :return abs paths to RPMs. """ logger.info("Building RPMs") output = os.path.join(results_dir, "mock_output.log") cmd = [ cls.CMD, '--old-chroot', '--rebuild', srpm, '--resultdir', results_dir ] if root is not None: cmd.extend(['--root', root]) if arch is not None: cmd.extend(['--arch', arch]) if builder_options is not None: cmd.extend(builder_options) ret = ProcessHelper.run_subprocess(cmd, output_file=output) if ret == 0: return [ f for f in PathHelper.find_all_files(results_dir, '*.rpm') if not f.endswith('.src.rpm') ] else: logfile = MockBuildTool.get_mock_logfile_path(ret, rpm_results_dir, tmp_path=results_dir) logs = [l for l in PathHelper.find_all_files(results_dir, '*.log')] cls.logs.extend( [os.path.join(rpm_results_dir, os.path.basename(l)) for l in logs]) raise BinaryPackageBuildError("Building RPMs failed!", rpm_results_dir, logfile=logfile)
def build(cls, spec, results_dir, **kwargs): """ Build SRPM with chosen SRPM Build Tool :param spec: SpecFile object :param results_dir: absolute path to DIR where results should be stored :return: absolute path to SRPM, list with absolute paths to logs """ srpm_results_dir = os.path.join(results_dir, "SRPM") sources = spec.get_sources() patches = [p.get_path() for p in spec.get_patches()] with RpmbuildTemporaryEnvironment(sources, patches, spec.get_path(), srpm_results_dir) as tmp_env: srpm_builder_options = cls.get_srpm_builder_options(**kwargs) env = tmp_env.env() tmp_dir = tmp_env.path() tmp_spec = env.get(RpmbuildTemporaryEnvironment.TEMPDIR_SPEC) tmp_results_dir = env.get( RpmbuildTemporaryEnvironment.TEMPDIR_RESULTS) srpm = cls._build_srpm(tmp_spec, tmp_dir, tmp_results_dir, srpm_results_dir, srpm_builder_options=srpm_builder_options) logger.info("Building SRPM finished successfully") # srpm path in results_dir srpm = os.path.join(srpm_results_dir, os.path.basename(srpm)) logger.verbose("Successfully built SRPM: '%s'", str(srpm)) # gather logs logs = [l for l in PathHelper.find_all_files(srpm_results_dir, '*.log')] logger.verbose("logs: '%s'", str(logs)) return dict(srpm=srpm, logs=logs)
def build(cls, spec, results_dir, srpm, **kwargs): """ Builds the RPMs using rpmbuild :param spec: SpecFile object :param results_dir: absolute path to DIR where results should be stored :param srpm: absolute path to SRPM :return: dict with: 'rpm' -> list with absolute paths to RPMs 'logs' -> list with absolute paths to build_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 RpmbuildTemporaryEnvironment(sources, patches, spec.get_path(), rpm_results_dir) as tmp_env: env = tmp_env.env() tmp_dir = tmp_env.path() tmp_results_dir = env.get(RpmbuildTemporaryEnvironment.TEMPDIR_RESULTS) rpms = cls._build_rpm(srpm, tmp_dir, tmp_results_dir, rpm_results_dir, builder_options=cls.get_builder_options(**kwargs)) logger.info("Building RPMs finished successfully") # RPMs paths in results_dir 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)
def build(cls, spec, results_dir, srpm, **kwargs): """ Builds the RPMs using rpmbuild :param spec: SpecFile object :param results_dir: absolute path to DIR where results should be stored :param srpm: absolute path to SRPM :return: dict with: 'rpm' -> list with absolute paths to RPMs 'logs' -> list with absolute paths to build_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 RpmbuildTemporaryEnvironment(sources, patches, spec.get_path(), rpm_results_dir) as tmp_env: env = tmp_env.env() tmp_dir = tmp_env.path() tmp_results_dir = env.get(RpmbuildTemporaryEnvironment.TEMPDIR_RESULTS) rpms = cls._build_rpm(srpm, tmp_dir, tmp_results_dir, rpm_results_dir, builder_options=cls.get_builder_options(**kwargs)) logger.info("Building RPMs finished successfully") # RPMs paths in results_dir 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)
def build(cls, spec, results_dir, **kwargs): """ Build SRPM with chosen SRPM Build Tool :param spec: SpecFile object :param results_dir: absolute path to DIR where results should be stored :return: absolute path to SRPM, list with absolute paths to logs """ srpm_results_dir = os.path.join(results_dir, "SRPM") sources = spec.get_sources() patches = [p.get_path() for p in spec.get_patches()] with MockTemporaryEnvironment(sources, patches, spec.get_path(), srpm_results_dir) as tmp_env: srpm_builder_options = cls.get_srpm_builder_options(**kwargs) env = tmp_env.env() tmp_dir = tmp_env.path() tmp_spec = env.get(MockTemporaryEnvironment.TEMPDIR_SPEC) tmp_results_dir = env.get( MockTemporaryEnvironment.TEMPDIR_RESULTS) srpm = cls._build_srpm(tmp_spec, tmp_dir, tmp_results_dir, srpm_results_dir, srpm_builder_options=srpm_builder_options) logger.info("Building SRPM finished successfully") # srpm path in results_dir srpm = os.path.join(srpm_results_dir, os.path.basename(srpm)) logger.verbose("Successfully built SRPM: '%s'", str(srpm)) # gather logs logs = [l for l in PathHelper.find_all_files(srpm_results_dir, '*.log')] logger.verbose("logs: '%s'", str(logs)) return dict(srpm=srpm, logs=logs)
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)
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)
def _build_rpm(cls, srpm, workdir, results_dir, rpm_results_dir, builder_options=None): """Builds RPMs using rpmbuild Args: srpm: Path to SRPM. workdir: Path to working directory with rpmbuild directory structure. results_dir: Path to directory where logs will be placed. rpm_results_dir: Path to directory where RPMs will be placed. builder_options: Additional options for rpmbuild. Returns: Tuple, the first element is a list of paths to built RPMs, the second is a list of paths to logs. """ logger.info("Building RPMs") output = os.path.join(results_dir, "build.log") cmd = [cls.CMD, '--rebuild', srpm] if builder_options is not None: cmd.extend(builder_options) ret = ProcessHelper.run_subprocess_cwd_env(cmd, env={'HOME': workdir}, output_file=output) build_log_path = os.path.join(rpm_results_dir, 'build.log') logs = [] for log in PathHelper.find_all_files(results_dir, '*.log'): logs.append(os.path.join(rpm_results_dir, os.path.basename(log))) if ret == 0: return [ f for f in PathHelper.find_all_files(workdir, '*.rpm') if not f.endswith('.src.rpm') ], logs # An error occurred, raise an exception raise BinaryPackageBuildError("Building RPMs failed!", results_dir, logfile=build_log_path, logs=logs)
def _build_env_exit_callback(self, results_dir, **kwargs): """ The function that is called just before the destruction of the TemporaryEnvironment. It copies packages and logs into the results directory. :param results_dir: absolute path to results directory :return: """ os.makedirs(results_dir) log_message = "Copying '%s' '%s' to '%s'" # copy logs for log in PathHelper.find_all_files(kwargs[self.TEMPDIR_RESULTS], '*.log'): logger.debug(log_message, 'log', log, results_dir) shutil.copy(log, results_dir) # copy packages for package in PathHelper.find_all_files(kwargs[self.TEMPDIR], '*.rpm'): logger.debug(log_message, 'package', package, results_dir) shutil.copy(package, results_dir)
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)
def get_checker_outputs(self): checkers = {} for check, data in six.iteritems(results_store.get_checkers()): if data: for log in six.iterkeys(data): if PathHelper.file_available(log): checkers[check] = log else: checkers[check] = None return checkers
def _build_env_exit_callback(self, results_dir, **kwargs): """ The function that is called just before the destruction of the TemporaryEnvironment. It copies packages and logs into the results directory. :param results_dir: absolute path to results directory :return: """ log_message = "Copying '%s' '%s' to '%s'" # copy logs for log in PathHelper.find_all_files(kwargs[self.TEMPDIR_RESULTS], '*.log'): logger.debug(log_message, 'log', log, results_dir) shutil.copy(log, results_dir) # copy packages for package in PathHelper.find_all_files(kwargs[self.TEMPDIR], '*.rpm'): logger.debug(log_message, 'package', package, results_dir) shutil.copy(package, results_dir)
def get_checker_outputs(self): checkers = {} for check, data in results_store.get_checkers().items(): if data: for log in data: if PathHelper.file_available(log): checkers[check] = log else: checkers[check] = None return checkers
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)
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)
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)
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
def get_rpm_packages(self, dirname): """ Function returns RPM packages stored in dirname/old and dirname/new directories :param dirname: directory where are stored old and new RPMS :return: """ found = True for version in ['old', 'new']: data = {} data['name'] = self.spec_file.get_package_name() if version == 'old': spec_version = self.spec_file.get_version() else: spec_version = self.rebase_spec_file.get_version() data['version'] = spec_version data['rpm'] = PathHelper.find_all_files(os.path.join(os.path.realpath(dirname), version, 'RPM'), '*.rpm') if not data['rpm']: logger.error('Your path %s%s/RPM does not contain any RPM packages', dirname, version) found = False results_store.set_build_data(version, data) if not found: return False return True
def get_rpm_packages(self, dirname): """ Function returns RPM packages stored in dirname/old and dirname/new directories :param dirname: directory where are stored old and new RPMS :return: """ found = True for version in ['old', 'new']: data = {} data['name'] = self.spec_file.get_package_name() if version == 'old': spec_version = self.spec_file.get_version() else: spec_version = self.rebase_spec_file.get_version() data['version'] = spec_version data['rpm'] = PathHelper.find_all_files(os.path.join(os.path.realpath(dirname), version, 'RPM'), '*.rpm') if not data['rpm']: logger.error('Your path %s%s/RPM does not contain any RPM packages', dirname, version) found = False results_store.set_build_data(version, data) if not found: return False return True
def __enter__(self): self._env[self.TEMPDIR] = PathHelper.get_temp_dir() logger.debug("Created environment in '%s'", self.path()) return self
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])
def test_find_without_recursion(self, filelist): assert PathHelper.find_first_file(os.path.curdir, "*.spec") == os.path.abspath(filelist[-1])
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))
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)
def __enter__(self): self._env[self.TEMPDIR] = PathHelper.get_temp_dir() logger.debug("Created environment in '%s'", self.path()) return self
def test_find_without_recursion(self, filelist): assert PathHelper.find_first_file( os.path.curdir, "*.spec") == os.path.abspath(filelist[-1])
def __init__(self, filename): self.tmp = PathHelper.get_temp_dir() TarArchiveType.extract(TarArchiveType.open(filename), '', self.tmp) self.data = TarGzArchiveType.open( os.path.join(self.tmp, 'data.tar.gz'))