Пример #1
0
    def prepare(self):
        """prepare task. Prebuild the package and run rpmbuild -bp on it."""
        srpm = self.prebuild()
        utils.safe_makedirs(self.results_dir)
        shutil.copy(srpm, self.results_dir)
        for dname in ['BUILD', 'tmp']:
            utils.safe_makedirs(os.path.join(self.results_dir, dname))
        rpm_cmd = (["rpm"] +
                   self.get_rpmbuild_defines(prebuild=False) +
                   ["-i", srpm])
        ret = utils.unchecked_call(rpm_cmd)
        if ret != 0:
            raise Error("Unable to unpack SRPM: rpm -i returned %d" % ret)

        rpmbuild_cmd = (["rpmbuild", "-bp", "--nodeps"] +
                        self.get_rpmbuild_defines(prebuild=False) +
                        glob.glob(os.path.join(self.results_dir, "*.spec")))
        if self.buildopts['target_arch'] is not None:
            rpmbuild_cmd += ["--target", self.buildopts['target_arch']]
        ret = utils.unchecked_call(rpmbuild_cmd)
        if ret != 0:
            raise Error(
                "Unable to prepare the package: rpmbuild -bp returned %d" % ret)
        log.info("Files prepared in: " +
                     os.path.join(self.results_dir, "BUILD"))
Пример #2
0
    def prepare(self):
        """prepare task. Prebuild the package and run rpmbuild -bp on it."""
        srpm = self.prebuild()
        utils.safe_makedirs(self.results_dir)
        shutil.copy(srpm, self.results_dir)
        for dname in ['BUILD', 'tmp']:
            utils.safe_makedirs(os.path.join(self.results_dir, dname))
        rpm_cmd = (["rpm"] +
                   self.get_rpmbuild_defines(prebuild=False) +
                   ["-i", srpm])
        ret = utils.unchecked_call(rpm_cmd)
        if ret != 0:
            raise Error("Unable to unpack SRPM: rpm -i returned %d" % ret)

        rpmbuild_cmd = (["rpmbuild", "-bp", "--nodeps"] +
                        self.get_rpmbuild_defines(prebuild=False) +
                        glob.glob(os.path.join(self.results_dir, "*.spec")))
        if self.buildopts['target_arch'] is not None:
            rpmbuild_cmd += ["--target", self.buildopts['target_arch']]
        ret = utils.unchecked_call(rpmbuild_cmd)
        if ret != 0:
            raise Error(
                "Unable to prepare the package: rpmbuild -bp returned %d" % ret)
        log.info("Files prepared in: " +
                     os.path.join(self.results_dir, "BUILD"))
Пример #3
0
 def tag_build(self, tag, build, force=False):
     tag_pkg_subcmd = ["tag-pkg", tag, build]
     if force:
         tag_pkg_subcmd.append("--force")
     err = utils.unchecked_call(self.koji_cmd + tag_pkg_subcmd)
     if err:
         raise KojiError("koji tag-pkg failed with exit code " + str(err))
Пример #4
0
    def rpmbuild(self):
        """rpmbuild task.
        Build the package using rpmbuild on the local machine.

        """
        srpm = self.prebuild()
        utils.safe_makedirs(self.results_dir)
        shutil.copy(srpm, self.results_dir)
        for d in ['BUILD', 'tmp']:
            utils.safe_makedirs(os.path.join(self.results_dir, d))
        cmd = (["rpmbuild"] +
               self.get_rpmbuild_defines(prebuild=False) +
               ["--rebuild", srpm])
        if self.buildopts['target_arch'] is not None:
            cmd += ["--target", self.buildopts['target_arch']]
        err = utils.unchecked_call(cmd)

        # TODO Parse rpmbuild output instead of using glob
        if err:
            raise OSGBuildError('Making RPM failed (command was: ' +
                                " ".join(cmd) +')')
        else:
            rpms = [x for x in glob.glob(os.path.join(self.results_dir, "*.rpm"))
                    if not fnmatch.fnmatch(x, '*.src.rpm')]
            if not rpms:
                raise OSGBuildError("No RPMs found. Making RPMs failed?")
            log.info("The following RPM(s) have been created:\n" +
                         "\n".join(rpms))
Пример #5
0
    def rpmbuild(self):
        """rpmbuild task.
        Build the package using rpmbuild on the local machine.

        """
        srpm = self.prebuild()
        utils.safe_makedirs(self.results_dir)
        shutil.copy(srpm, self.results_dir)
        for d in ['BUILD', 'tmp']:
            utils.safe_makedirs(os.path.join(self.results_dir, d))
        cmd = (["rpmbuild"] +
               self.get_rpmbuild_defines(prebuild=False) +
               ["--rebuild", srpm])
        if self.buildopts['target_arch'] is not None:
            cmd += ["--target", self.buildopts['target_arch']]
        err = utils.unchecked_call(cmd)

        # TODO Parse rpmbuild output instead of using glob
        if err:
            raise OSGBuildError('Making RPM failed (command was: ' +
                                " ".join(cmd) +')')
        else:
            rpms = [x for x in glob.glob(os.path.join(self.results_dir, "*.rpm"))
                    if not fnmatch.fnmatch(x, '*.src.rpm')]
            if not rpms:
                raise OSGBuildError("No RPMs found. Making RPMs failed?")
            log.info("The following RPM(s) have been created:\n" +
                         "\n".join(rpms))
Пример #6
0
    def build(self, url, target, scratch=False, **kwargs):
        """build package at url for target.

        Using **kwargs so signature is same as KojiLibInter.build.
        kwargs recognized: no_wait, regen_repos, background, arch_override

        """
        log.debug("building " + url)
        no_wait = kwargs.get('no_wait', False)
        regen_repos = kwargs.get('regen_repos', False)
        background = kwargs.get('background', False)
        arch_override = kwargs.get('arch_override', None)
        build_subcmd = ["build", target, url]
        if scratch:
            build_subcmd += ["--scratch"]
        if no_wait:
            build_subcmd += ["--nowait"]
        if background:
            build_subcmd += ["--background"]
        if arch_override:
            build_subcmd += ["--arch-override=" + arch_override]
        log.info("Calling koji to build the package for target %s", target)

        if not self.dry_run:
            err = utils.unchecked_call(self.koji_cmd + build_subcmd)
        else:
            print " ".join(self.koji_cmd + build_subcmd)
            err = 0

        if err:
            raise KojiError("koji build failed with exit code " + str(err))
        if regen_repos and not scratch:
            build_tag = self.get_build_and_dest_tags(target)[0]
            regen_repo_subcmd = ["regen-repo", build_tag]
            if no_wait:
                regen_repo_subcmd += ["--nowait"]
            log.info("Calling koji to regen " + build_tag)
            if not self.dry_run:
                err2 = utils.unchecked_call(self.koji_cmd + regen_repo_subcmd)
            else:
                print " ".join(self.koji_cmd + regen_repo_subcmd)
                err2 = 0
            if err2:
                raise KojiError("koji regen-repo failed with exit code " +
                                str(err2))
Пример #7
0
    def mock_config(self, arch, tag, dist, outpath, name):
        """Request a mock config from koji-hub"""
        mock_config_subcmd = [
            "mock-config", "--arch=" + arch, "--tag=" + tag,
            "--distribution=" + dist, "--topurl=" + KOJI_HUB + "/mnt/koji",
            "-o", outpath, name
        ]

        err = utils.unchecked_call(self.koji_cmd + mock_config_subcmd)
        if err:
            raise KojiError("koji mock-config failed with exit code " +
                            str(err))
Пример #8
0
    def rebuild(self, resultdir, srpm):
        """Use mock to build RPMs from an SRPM"""
        rebuild_cmd = self.mock_cmd + ['--resultdir',
                                       resultdir,
                                       '--no-cleanup-after',
                                       'rebuild',
                                       srpm]
        if self.target_arch:
            rebuild_cmd += ['--arch', self.target_arch]
        # ccache on el6 tries to install the el5 package for ccache and dies
        if str(self.buildopts['redhat_release']) == '6':
            rebuild_cmd += ['--disable-plugin=ccache']
        ret = utils.unchecked_call(rebuild_cmd)
        if ret:
            raise MockError('Mock build failed (command was: ' + ' '.join(rebuild_cmd) + ')')
        
        # TODO: Parse the mock logs/output instead of using glob.
        rpms = [x for x in glob(os.path.join(resultdir, "*.rpm")) if not fnmatch(x, "*.src.rpm")]

        return rpms
Пример #9
0
    def rebuild(self, resultdir, srpm):
        """Use mock to build RPMs from an SRPM"""
        rebuild_cmd = self.mock_cmd + [
            '--resultdir', resultdir, '--no-cleanup-after', 'rebuild', srpm
        ]
        if self.target_arch:
            rebuild_cmd += ['--arch', self.target_arch]
        # ccache on el6 tries to install the el5 package for ccache and dies
        if str(self.buildopts['redhat_release']) == '6':
            rebuild_cmd += ['--disable-plugin=ccache']
        ret = utils.unchecked_call(rebuild_cmd)
        if ret:
            raise MockError('Mock build failed (command was: ' +
                            ' '.join(rebuild_cmd) + ')')

        # TODO: Parse the mock logs/output instead of using glob.
        rpms = [
            x for x in glob(os.path.join(resultdir, "*.rpm"))
            if not fnmatch(x, "*.src.rpm")
        ]

        return rpms
Пример #10
0
    def quilt(self):
        """quilt task. Prebuild the package (except for making the SRPM)
        and run 'quilt setup' on the spec file.

        """
        if not utils.which("quilt"):
            raise ProgramNotFoundError("quilt")

        if self.buildopts['autoclean']:
            if os.path.exists(self.quilt_dir):
                log.debug("autoclean removing " + self.quilt_dir)
                shutil.rmtree(self.quilt_dir)

        utils.safe_makedirs(self.quilt_dir)
        spec_filename = self.prebuild_external_sources(destdir=self.quilt_dir)

        os.chdir(self.quilt_dir)
        ret = utils.unchecked_call(["quilt", "-v", "setup", spec_filename])
        if ret != 0:
            raise Error("Error running 'quilt setup' on the spec file.")

        log.info("quilt files ready in %s", self.quilt_dir)
Пример #11
0
    def quilt(self):
        """quilt task. Prebuild the package (except for making the SRPM)
        and run 'quilt setup' on the spec file.

        """
        if not utils.which("quilt"):
            raise ProgramNotFoundError("quilt")

        if self.buildopts['autoclean']:
            if os.path.exists(self.quilt_dir):
                log.debug("autoclean removing " + self.quilt_dir)
                shutil.rmtree(self.quilt_dir)

        utils.safe_makedirs(self.quilt_dir)
        spec_filename = self.prebuild_external_sources(destdir=self.quilt_dir)

        os.chdir(self.quilt_dir)
        ret = utils.unchecked_call(["quilt", "-v", "setup", spec_filename])
        if ret != 0:
            raise Error("Error running 'quilt setup' on the spec file.")

        log.info("quilt files ready in %s", self.quilt_dir)
Пример #12
0
def verify_rpm(srpm):
    """Verify that srpm is indeed an RPM. Raise Error if not."""
    cmd = ["rpm", "-qp", "--nomanifest", srpm]
    err = utils.unchecked_call(cmd)
    if err:
        raise Error("rpm: %s does not look like an RPM" % srpm)
Пример #13
0
def main(argv=sys.argv):
    parser = OptionParser("""
    %prog [options] <upstream-url>

%prog should be called from an SVN checkout and given the URL of an upstream SRPM.
will create and populate the appropriate directories in SVN as well as
downloading and putting the SRPM into the upstream cache.
""")
    try:
        parser.set_defaults(extra_action=None)

        parser.add_option(
            "-d", "--diff-spec", "-2", action="store_const", dest='extra_action', const=EXTRA_ACTION_DIFF_SPEC,
            help="Perform a two-way diff between the new upstream spec file and the OSG spec file. "
            "The new upstream spec file will be written to SPEC.new, and the OSG spec file will be "
            "written to SPEC.old; the differences will be written to SPEC. You will have to edit "
            "SPEC to resolve the differences.")
        parser.add_option(
            "-e", "--extract-spec", action="store_const", dest='extra_action', const=EXTRA_ACTION_EXTRACT_SPEC,
            help="Extract the spec file from the SRPM and put it into an osg/ subdirectory.")
        parser.add_option(
            "--loglevel",
            help="The level of logging the script should do. "
            "Valid values are DEBUG,INFO,WARNING,ERROR,CRITICAL")
        parser.add_option(
            "-o", "--output",
            help="The filename the upstream-url should be saved as.")
        parser.add_option(
            "-p", "--provider",
            help="Who provided the SRPM being imported. For example, 'epel'. "
            "This is used to name the .source file in the 'upstream' directory. "
            "If unspecified, guess based on the URL, and use 'developer' as the fallback.")
        parser.add_option(
            "-3", "--diff3-spec", action="store_const", dest='extra_action', const=EXTRA_ACTION_DIFF3_SPEC,
            help="Perform a three-way diff between the original upstream spec file, the OSG spec file, "
            "and the new upstream spec file. These spec files will be written to SPEC.orig, "
            "SPEC.old, and SPEC.new, respectively; a merged result will be written to SPEC."
            "You will have to edit SPEC to resolve merge conflicts.")
        parser.add_option(
            "-u", "--upstream", default=DEFAULT_UPSTREAM_ROOT,
            help="The base directory to put the upstream sources under. "
            "Default: %default")
        parser.add_option(
            "-U", "--update", action="store_const", dest='extra_action', const=EXTRA_ACTION_UPDATE,
            help="If there is an osg/ directory, do a 3-way diff like --diff3-spec.  Otherwise just update"
            " the .source file in the 'upstream' directory."
        )
        parser.add_option(
            "--nosha1sum", action="store_false", dest="want_sha1sum", default=True,
            help="Do not add a 'sha1sum' parameter to the .source file. "
                 ".source files with sha1sums need osg-build 1.14+ to use."
        )

        options, pos_args = parser.parse_args(argv[1:])

        if options.loglevel:
            try:
                loglevel = int(getattr(logging, options.loglevel.upper()))
            except (TypeError, AttributeError):
                raise UsageError("Invalid log level")
        else:
            loglevel = DEFAULT_LOG_LEVEL
        logging.basicConfig(format=" >> %(message)s", level=loglevel)

        try:
            upstream_url = pos_args[0]
        except IndexError:
            raise UsageError("Required argument <upstream-url> not provided")

        if utils.unchecked_call("svn info &>/dev/null", shell=True):
            raise Error("Must be called from an svn checkout!")

        if not re.match(r'(http|https|ftp):', upstream_url):
            raise UsageError("upstream-url is not a valid url")

        outfile = options.output or os.path.basename(upstream_url)
        sha1sum = fetch_sources.download_uri(upstream_url, outfile)
        if not options.want_sha1sum:
            sha1sum = None
        verify_rpm(outfile)
        srpm = move_to_cache(outfile, options.upstream)
        make_svn_tree(srpm, upstream_url, options.extra_action, options.provider, sha1sum)

    except UsageError as e:
        parser.print_help()
        print(str(e), file=sys.stderr)
        return 2
    except SystemExit as e:
        return e.code
    except KeyboardInterrupt:
        print("Interrupted", file=sys.stderr)
        return 3
    except Error as e:
        logging.critical(str(e))
        logging.debug(e.traceback)
    except Exception as e:
        logging.critical("Unhandled exception: %s", str(e))
        logging.critical(traceback.format_exc())
        return 1

    return 0
Пример #14
0
def svn_safe_add(path):
    """Add path to SVN if it's not already in there. Return True on success."""
    if is_untracked_path(path):
        ret = utils.unchecked_call(["svn", "add", path])
        return ret == 0
Пример #15
0
def verify_rpm(srpm):
    """Verify that srpm is indeed an RPM. Raise Error if not."""
    cmd = ["rpm", "-qp", "--nomanifest", srpm]
    err = utils.unchecked_call(cmd)
    if err:
        raise Error("rpm: %s does not look like an RPM" % srpm)
Пример #16
0
def main(argv=sys.argv):
    parser = OptionParser("""
    %prog [options] <upstream-url>

%prog should be called from an SVN checkout and given the URL of an upstream SRPM.
will create and populate the appropriate directories in SVN as well as
downloading and putting the SRPM into the upstream cache.
""")
    try:
        parser.set_defaults(extra_action=None)

        parser.add_option(
            "-d",
            "--diff-spec",
            "-2",
            action="store_const",
            dest='extra_action',
            const=EXTRA_ACTION_DIFF_SPEC,
            help=
            "Perform a two-way diff between the new upstream spec file and the OSG spec file. "
            "The new upstream spec file will be written to SPEC.new, and the OSG spec file will be "
            "written to SPEC.old; the differences will be written to SPEC. You will have to edit "
            "SPEC to resolve the differences.")
        parser.add_option(
            "-e",
            "--extract-spec",
            action="store_const",
            dest='extra_action',
            const=EXTRA_ACTION_EXTRACT_SPEC,
            help=
            "Extract the spec file from the SRPM and put it into an osg/ subdirectory."
        )
        parser.add_option("--loglevel",
                          help="The level of logging the script should do. "
                          "Valid values are DEBUG,INFO,WARNING,ERROR,CRITICAL")
        parser.add_option(
            "-o",
            "--output",
            help="The filename the upstream-url should be saved as.")
        parser.add_option(
            "-p",
            "--provider",
            help="Who provided the SRPM being imported. For example, 'epel'. "
            "This is used to name the .source file in the 'upstream' directory. "
            "If unspecified, guess based on the URL, and use 'developer' as the fallback."
        )
        parser.add_option(
            "-3",
            "--diff3-spec",
            action="store_const",
            dest='extra_action',
            const=EXTRA_ACTION_DIFF3_SPEC,
            help=
            "Perform a three-way diff between the original upstream spec file, the OSG spec file, "
            "and the new upstream spec file. These spec files will be written to SPEC.orig, "
            "SPEC.old, and SPEC.new, respectively; a merged result will be written to SPEC."
            "You will have to edit SPEC to resolve merge conflicts.")
        parser.add_option(
            "-u",
            "--upstream",
            default=DEFAULT_UPSTREAM_ROOT,
            help="The base directory to put the upstream sources under. "
            "Default: %default")
        parser.add_option(
            "-U",
            "--update",
            action="store_const",
            dest='extra_action',
            const=EXTRA_ACTION_UPDATE,
            help=
            "If there is an osg/ directory, do a 3-way diff like --diff3-spec.  Otherwise just update"
            " the .source file in the 'upstream' directory.")
        parser.add_option(
            "--nosha1sum",
            action="store_false",
            dest="want_sha1sum",
            default=True,
            help="Do not add a 'sha1sum' parameter to the .source file. "
            ".source files with sha1sums need osg-build 1.14+ to use.")

        options, pos_args = parser.parse_args(argv[1:])

        if options.loglevel:
            try:
                loglevel = int(getattr(logging, options.loglevel.upper()))
            except (TypeError, AttributeError):
                raise UsageError("Invalid log level")
        else:
            loglevel = DEFAULT_LOG_LEVEL
        logging.basicConfig(format=" >> %(message)s", level=loglevel)

        try:
            upstream_url = pos_args[0]
        except IndexError:
            raise UsageError("Required argument <upstream-url> not provided")

        if utils.unchecked_call("svn info &>/dev/null", shell=True):
            raise Error("Must be called from an svn checkout!")

        if not re.match(r'(http|https|ftp):', upstream_url):
            raise UsageError("upstream-url is not a valid url")

        outfile = options.output or os.path.basename(upstream_url)
        sha1sum = fetch_sources.download_uri(upstream_url, outfile)
        if not options.want_sha1sum:
            sha1sum = None
        verify_rpm(outfile)
        srpm = move_to_cache(outfile, options.upstream)
        make_svn_tree(srpm, upstream_url, options.extra_action,
                      options.provider, sha1sum)

    except UsageError as e:
        parser.print_help()
        print(str(e), file=sys.stderr)
        return 2
    except SystemExit as e:
        return e.code
    except KeyboardInterrupt:
        print("Interrupted", file=sys.stderr)
        return 3
    except Error as e:
        logging.critical(str(e))
        logging.debug(e.traceback)
    except Exception as e:
        logging.critical("Unhandled exception: %s", str(e))
        logging.critical(traceback.format_exc())
        return 1

    return 0
Пример #17
0
def svn_safe_add(path):
    """Add path to SVN if it's not already in there. Return True on success."""
    if is_untracked_path(path):
        ret = utils.unchecked_call(["svn", "add", path])
        return ret == 0