コード例 #1
0
def get_old_log(pkgdirurl):
    chlog = StringIO()
    oldurl = config.get("log", "oldurl")
    if oldurl:
        svn = SVN()
        tmpdir = tempfile.mktemp()
        try:
            pkgname = layout.package_name(pkgdirurl)
            pkgoldurl = os.path.join(oldurl, pkgname)
            try:
                # we're using HEAD here because fixes in misc/ (oldurl) may
                # be newer than packages' last changed revision.
                svn.export(pkgoldurl, tmpdir)
            except Error:
                pass
            else:
                logfile = os.path.join(tmpdir, "log")
                if os.path.isfile(logfile):
                    file = open(logfile)
                    chlog.write("\n") # TODO needed?
                    log = file.read()
                    log = escape_macros(log)
                    chlog.write(log)
                    file.close()
        finally:
            if os.path.isdir(tmpdir):
                shutil.rmtree(tmpdir)
    chlog.seek(0)
    return chlog
コード例 #2
0
def get_old_log(pkgdirurl):
    chlog = StringIO()
    oldurl = config.get("log", "oldurl")
    if oldurl:
        svn = SVN(url=oldurl)
        tmpdir = tempfile.mktemp()
        try:
            if oldurl == '.' or oldurl.startswith('./'):
                pkgoldurl = os.path.join(pkgdirurl, oldurl)
            else:
                pkgname = layout.package_name(pkgdirurl)
                pkgoldurl = os.path.join(svn.url, pkgname)
            try:
                # we're using HEAD here because fixes in misc/ (oldurl) may
                # be newer than packages' last changed revision.
                svn.export(pkgoldurl, tmpdir)
            except Error:
                pass
            else:
                logfile = os.path.join(tmpdir, "log")
                if os.path.isfile(logfile):
                    with open(logfile, 'r', encoding='utf-8') as lf:
                        chlog.write("\n")  # TODO needed?
                        log = lf.read()
                        log = escape_macros(log)
                        chlog.write(log)
        finally:
            if os.path.isdir(tmpdir):
                shutil.rmtree(tmpdir)
    chlog.seek(0)
    return chlog
コード例 #3
0
def getrelease(pkgdirurl, rev=None, macros=[], exported=None):
    """Tries to obtain the version-release of the package for a 
    yet-not-markrelease revision of the package.

    Is here where things should be changed if "automatic release increasing" 
    will be used.
    """
    from RepSys.rpmutil import rpm_macros_defs
    svn = SVN()
    pkgcurrenturl = os.path.join(pkgdirurl, "current")
    specurl = os.path.join(pkgcurrenturl, "SPECS")
    if exported is None:
        tmpdir = tempfile.mktemp()
        svn.export(specurl, tmpdir, rev=rev)
    else:
        tmpdir = os.path.join(exported, "SPECS")
    try:
        found = glob.glob(os.path.join(tmpdir, "*.spec"))
        if not found:
            raise Error, "no .spec file found inside %s" % specurl
        specpath = found[0]
        options = rpm_macros_defs(macros)
        command = (("rpm -q --qf '%%{EPOCH}:%%{VERSION}-%%{RELEASE}\n' "
                    "--specfile %s %s") % (specpath, options))
        pipe = subprocess.Popen(command,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE,
                                shell=True)
        pipe.wait()
        output = pipe.stdout.read()
        error = pipe.stderr.read()
        if pipe.returncode != 0:
            raise Error, "Error in command %s: %s" % (command, error)
        releases = output.split()
        try:
            epoch, vr = releases[0].split(":", 1)
            version, release = vr.split("-", 1)
        except ValueError:
            raise Error, "Invalid command output: %s: %s" % \
                    (command, output)
        #XXX check if this is the right way:
        if epoch == "(none)":
            ev = version
        else:
            ev = epoch + ":" + version
        return ev, release
    finally:
        if exported is None and os.path.isdir(tmpdir):
            shutil.rmtree(tmpdir)
コード例 #4
0
def get_spec(pkgdirurl, targetdir=".", submit=False):
    svn = SVN()
    tmpdir = tempfile.mktemp()
    try:
        geturl = layout.checkout_url(pkgdirurl, append_path="SPECS")
        mirror.info(geturl)
        svn.export("'%s'" % geturl, tmpdir)
        speclist = glob.glob(os.path.join(tmpdir, "*.spec"))
        if not speclist:
            raise Error, "no spec files found"
        spec = speclist[0]
        shutil.copy(spec, targetdir)
    finally:
        if os.path.isdir(tmpdir):
            shutil.rmtree(tmpdir)
コード例 #5
0
def getrelease(pkgdirurl, rev=None, macros=[], exported=None):
    """Tries to obtain the version-release of the package for a 
    yet-not-markrelease revision of the package.

    Is here where things should be changed if "automatic release increasing" 
    will be used.
    """
    from RepSys.rpmutil import rpm_macros_defs
    svn = SVN()
    pkgcurrenturl = os.path.join(pkgdirurl, "current")
    specurl = os.path.join(pkgcurrenturl, "SPECS")
    if exported is None:
        tmpdir = tempfile.mktemp()
        svn.export(specurl, tmpdir, rev=rev)
    else:
        tmpdir = os.path.join(exported, "SPECS")
    try:
        found = glob.glob(os.path.join(tmpdir, "*.spec"))
        if not found:
            raise Error, "no .spec file found inside %s" % specurl
        specpath = found[0]
        options = rpm_macros_defs(macros)
        command = (("rpm -q --qf '%%{EPOCH}:%%{VERSION}-%%{RELEASE}\n' "
                   "--specfile %s %s") %
                   (specpath, options))
        pipe = subprocess.Popen(command, stdout=subprocess.PIPE,
                stderr=subprocess.PIPE, shell=True)
        pipe.wait()
        output = pipe.stdout.read()
        error = pipe.stderr.read()
        if pipe.returncode != 0:
            raise Error, "Error in command %s: %s" % (command, error)
        releases = output.split()
        try:
            epoch, vr = releases[0].split(":", 1)
            version, release = vr.split("-", 1)
        except ValueError:
            raise Error, "Invalid command output: %s: %s" % \
                    (command, output)
        #XXX check if this is the right way:
        if epoch == "(none)":
            ev = version
        else:
            ev = epoch + ":" + version
        return ev, release
    finally:
        if exported is None and os.path.isdir(tmpdir):
            shutil.rmtree(tmpdir)
コード例 #6
0
ファイル: log.py プロジェクト: bhdn/repsys
def getrelease(pkgdirurl, rev=None, macros=[], exported=None):
    """Tries to obtain the version-release of the package for a 
    yet-not-markrelease revision of the package.

    Is here where things should be changed if "automatic release increasing" 
    will be used.
    """
    svn = SVN()
    pkgcurrenturl = os.path.join(pkgdirurl, "current")
    specurl = os.path.join(pkgcurrenturl, "SPECS")
    if exported is None:
        tmpdir = tempfile.mktemp()
        svn.export(specurl, tmpdir, rev=rev)
    else:
        tmpdir = os.path.join(exported, "SPECS")
    try:
        found = glob.glob(os.path.join(tmpdir, "*.spec"))
        if not found:
            raise Error, "no .spec file found inside %s" % specurl
        specpath = found[0]
        args = ["rpm", "-q", "--qf", "%{EPOCH}:%{VERSION}-%{RELEASE}\n",
                "--specfile", specpath]
        for pair in macros:
            args.extend(("--define", "%s %s" % pair))
        proc = subprocess.Popen(args, shell=False, stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
        if proc.wait() != 0:
            raise CommandError(args, proc.returncode, proc.stderr.read())
        output = proc.stdout.read()
        releases = output.split()
        try:
            epoch, vr = releases[0].split(":", 1)
            version, release = vr.split("-", 1)
        except ValueError:
            raise Error, "Invalid command output: %s: %s" % \
                    (args, output)
        #XXX check if this is the right way:
        if epoch == "(none)":
            ev = version
        else:
            ev = epoch + ":" + version
        return ev, release
    finally:
        if exported is None and os.path.isdir(tmpdir):
            shutil.rmtree(tmpdir)
コード例 #7
0
def get_srpm(pkgdirurl,
             mode="current",
             targetdirs=None,
             version=None,
             release=None,
             revision=None,
             packager="",
             revname=0,
             svnlog=0,
             scripts=[],
             submit=False,
             template=None,
             distro=None,
             macros=[],
             verbose=0,
             strict=False):
    svn = SVN()
    tmpdir = tempfile.mktemp()
    topdir = "_topdir %s" % tmpdir
    builddir = "_builddir %s/%s" % (tmpdir, "BUILD")
    rpmdir = "_rpmdir %s/%s" % (tmpdir, "RPMS")
    sourcedir = "_sourcedir %s/%s" % (tmpdir, "SOURCES")
    specdir = "_specdir %s/%s" % (tmpdir, "SPECS")
    srcrpmdir = "_srcrpmdir %s/%s" % (tmpdir, "SRPMS")
    patchdir = "_patchdir %s/%s" % (tmpdir, "SOURCES")
    temppath = "_tmppath %s" % (tmpdir)

    rpmdefs = [("--define", expr)
               for expr in (topdir, builddir, rpmdir, sourcedir, specdir,
                            srcrpmdir, patchdir, temppath)]

    try:
        if mode == "version":
            geturl = layout.checkout_url(pkgdirurl,
                                         version=version,
                                         release=release)
        elif mode == "pristine":
            geturl = layout.checkout_url(pkgdirurl, pristine=True)
        elif mode == "current" or mode == "revision":
            #FIXME we should handle revisions specified using @REV
            geturl = layout.checkout_url(pkgdirurl)
        else:
            raise Error, "unsupported get_srpm mode: %s" % mode
        strict = strict or config.getbool("submit", "strict-revision", False)
        if strict and not rev_touched_url(geturl, revision):
            #FIXME would be nice to have the revision number even when
            # revision is None
            raise Error, "the revision %s does not change anything "\
                    "inside %s" % (revision or "HEAD", geturl)
        mirror.info(geturl)
        svn.export(geturl, tmpdir, rev=revision)
        srpmsdir = os.path.join(tmpdir, "SRPMS")
        os.mkdir(srpmsdir)
        specsdir = os.path.join(tmpdir, "SPECS")
        speclist = glob.glob(os.path.join(specsdir, "*.spec"))
        if config.getbool("srpm", "run-prep", False):
            makefile = os.path.join(tmpdir, "Makefile")
            if os.path.exists(makefile):
                execcmd(("make", "-C", tmpdir, "srpm-prep"))
        if not speclist:
            raise Error, "no spec files found"
        spec = speclist[0]
        if svnlog:
            submit = not not revision
            log.specfile_svn2rpm(pkgdirurl,
                                 spec,
                                 revision,
                                 submit=submit,
                                 template=template,
                                 macros=macros,
                                 exported=tmpdir)
        for script in scripts:
            #FIXME revision can be "None"
            status, output = execcmd(script,
                                     tmpdir,
                                     spec,
                                     str(revision),
                                     noerror=1)
            if status != 0:
                raise Error, "script %s failed" % script
        if packager:
            packager = " --define 'packager %s'" % packager

        if distro:
            cmpdistro = distro.lower()
            for target in cgiutil.get_targets():
                if target.name.lower() == cmpdistro:
                    macros.extend(target.macros)
                    break
            else:
                raise Error, "no such submit target in configuration: %s" % (
                    distro)
        sourcecmd = config.get("helper", "rpmbuild", "rpmbuild")
        args = [sourcecmd, "-bs", "--nodeps"]
        for pair in rpmdefs:
            args.extend(pair)
        for pair in macros:
            args.extend(("--define", "%s %s" % pair))
        args.append(spec)
        try:
            execcmd(args)
        except CommandError, e:
            if config.getbool("global", "verbose"):
                cmdline = e.cmdline + "\n"
            else:
                cmdline = ""
            raise Error, ("error while creating the source RPM "
                          "(with %s):\n%s%s" % (sourcecmd, cmdline, e.output))

        # copy the generated SRPMs to their target locations
        targetsrpms = []
        urlrev = None
        if revname:
            urlrev = revision or layout.get_url_revision(geturl)
        if not targetdirs:
            targetdirs = (".", )
        srpms = glob.glob(os.path.join(srpmsdir, "*.src.rpm"))
        if not srpms:
            # something fishy happened
            raise Error, "no SRPMS were found at %s" % srpmsdir
        for srpm in srpms:
            name = os.path.basename(srpm)
            if revname:
                name = "@%s:%s" % (urlrev, name)
            for targetdir in targetdirs:
                newpath = os.path.join(targetdir, name)
                targetsrpms.append(newpath)
                if os.path.exists(newpath):
                    # should we warn?
                    os.unlink(newpath)
                shutil.copy(srpm, newpath)
                if verbose:
                    sys.stderr.write("Wrote: %s\n" % newpath)
        return targetsrpms
コード例 #8
0
def get_srpm(pkgdirurl,
             mode = "current",
             targetdirs = None,
             version = None,
             release = None,
             revision = None,
             packager = "",
             revname = 0,
             svnlog = 0,
             scripts = [], 
             submit = False,
             template = None,
             distro = None,
             macros = [],
             verbose = 0,
             strict = False):
    svn = SVN()
    tmpdir = tempfile.mktemp()
    topdir = "_topdir %s" % tmpdir
    builddir = "_builddir %s/%s" % (tmpdir, "BUILD")
    rpmdir = "_rpmdir %s/%s" % (tmpdir, "RPMS")
    sourcedir = "_sourcedir %s/%s" % (tmpdir, "SOURCES")
    specdir = "_specdir %s/%s" % (tmpdir, "SPECS")
    srcrpmdir = "_srcrpmdir %s/%s" % (tmpdir, "SRPMS")
    patchdir = "_patchdir %s/%s" % (tmpdir, "SOURCES")
    temppath = "_tmppath %s" % (tmpdir)

    rpmdefs = [("--define", expr) for expr in (topdir, builddir, rpmdir,
        sourcedir, specdir, srcrpmdir, patchdir, temppath)]

    try:
        if mode == "version":
            geturl = layout.checkout_url(pkgdirurl, version=version,
                    release=release)
        elif mode == "pristine":
            geturl = layout.checkout_url(pkgdirurl, pristine=True)
        elif mode == "current" or mode == "revision":
            #FIXME we should handle revisions specified using @REV
            geturl = layout.checkout_url(pkgdirurl)
        else:
            raise Error, "unsupported get_srpm mode: %s" % mode
        strict = strict or config.getbool("submit", "strict-revision", False)
        if strict and not rev_touched_url(geturl, revision):
            #FIXME would be nice to have the revision number even when
            # revision is None
            raise Error, "the revision %s does not change anything "\
                    "inside %s" % (revision or "HEAD", geturl)
        mirror.info(geturl)
        svn.export(geturl, tmpdir, rev=revision)
        srpmsdir = os.path.join(tmpdir, "SRPMS")
        os.mkdir(srpmsdir)
        specsdir = os.path.join(tmpdir, "SPECS")
        speclist = glob.glob(os.path.join(specsdir, "*.spec"))
        if config.getbool("srpm", "run-prep", False):
            makefile = os.path.join(tmpdir, "Makefile")
            if os.path.exists(makefile):
                execcmd(("make", "-C", tmpdir, "srpm-prep"))
        if not speclist:
            raise Error, "no spec files found"
        spec = speclist[0]
        if svnlog:
            submit = not not revision
            log.specfile_svn2rpm(pkgdirurl, spec, revision, submit=submit,
                    template=template, macros=macros, exported=tmpdir)
        for script in scripts:
            #FIXME revision can be "None"
            status, output = execcmd(script, tmpdir, spec, str(revision),
                                     noerror=1)
            if status != 0:
                raise Error, "script %s failed" % script
        if packager:
            packager = " --define 'packager %s'" % packager

        if distro:
            cmpdistro = distro.lower()
            for target in cgiutil.get_targets():
                if target.name.lower() == cmpdistro:
                    macros.extend(target.macros)
                    break
            else:
                raise Error, "no such submit target in configuration: %s" % (distro)
        sourcecmd = config.get("helper", "rpmbuild", "rpmbuild")
        args = [sourcecmd, "-bs", "--nodeps"]
        for pair in rpmdefs:
            args.extend(pair)
        for pair in macros:
            args.extend(("--define", "%s %s" % pair))
        args.append(spec)
        try:
            execcmd(args)
        except CommandError, e:
            if config.getbool("global", "verbose"):
                cmdline = e.cmdline + "\n"
            else:
                cmdline = ""
            raise Error, ("error while creating the source RPM "
                        "(with %s):\n%s%s" % (sourcecmd, cmdline, e.output))

        # copy the generated SRPMs to their target locations
        targetsrpms = []
        urlrev = None
        if revname:
            urlrev = revision or layout.get_url_revision(geturl)
        if not targetdirs:
            targetdirs = (".",)
        srpms = glob.glob(os.path.join(srpmsdir, "*.src.rpm"))
        if not srpms:
            # something fishy happened
            raise Error, "no SRPMS were found at %s" % srpmsdir
        for srpm in srpms:
            name = os.path.basename(srpm)
            if revname:
                name = "@%s:%s" % (urlrev, name)
            for targetdir in targetdirs:
                newpath = os.path.join(targetdir, name)
                targetsrpms.append(newpath)
                if os.path.exists(newpath):
                    # should we warn?
                    os.unlink(newpath)
                shutil.copy(srpm, newpath)
                if verbose:
                    sys.stderr.write("Wrote: %s\n" %  newpath)
        return targetsrpms
コード例 #9
0
def getrelease(pkgdirurl, rev=None, macros=[], exported=None, create=False):
    """Tries to obtain the version-release of the package for a 
    yet-not-markrelease revision of the package.

    Is here where things should be changed if "automatic release increasing" 
    will be used.
    """
    svn = SVN()
    pkgcurrenturl = os.path.join(pkgdirurl, "current")
    specurl = os.path.join(pkgcurrenturl, "SPECS")
    srpmurl = os.path.join(pkgcurrenturl, "SRPMS")
    if not create:
        if exported is None:
            tmpdir = tempfile.mktemp()
            svn.export(specurl, tmpdir, rev=rev)
        else:
            tmpdir = os.path.join(exported, "SPECS")
        try:
            found = glob.glob(os.path.join(tmpdir, "*.spec"))
            if not found:
                raise Error("no .spec file found inside %s" % specurl)
            specpath = found[0]
            options = [("--define", expr) for expr in macros]
            command = [
                "rpm", "-q", "--qf", "%{EPOCH}:%{VERSION}-%{RELEASE}\n",
                "--specfile", specpath
            ]
            command.extend(options)
            status, output = execcmd(*command)
            releases = output.split()
            try:
                epoch, vr = releases[0].split(":", 1)
                version, release = vr.split("-", 1)
            except ValueError:
                raise Error("Invalid command output: %s: %s" % \
                        (command, output))
            #XXX check if this is the right way:
            if epoch == "(none)":
                ev = version
            else:
                ev = epoch + ":" + version
            return ev, release
        finally:
            if exported is None and os.path.isdir(tmpdir):
                shutil.rmtree(tmpdir)
    else:
        if exported is None:
            tmpdir = tempfile.mktemp()
            svn.export(specurl, tmpdir, rev=rev)
        else:
            tmpdir = os.path.join(exported, "SRPMS")
        try:
            found = glob.glob(os.path.join(srpmurl, "*.src.rpm"))
            if not found:
                raise Error("no .src.rpm file found inside %s" % srpmurl)
            srpmpath = found[0]
            options = [("--define", expr) for expr in macros]
            command = [
                "rpm", "-q", "--qf", "%{EPOCH}:%{VERSION}-%{RELEASE}\n",
                "--specfile", specpath
            ]
            command.extend(options)
            status, output = execcmd(*command)
            releases = output.split()
            try:
                epoch, vr = releases[0].split(":", 1)
                version, release = vr.split("-", 1)
            except ValueError:
                raise Error("Invalid command output: %s: %s" % \
                        (command, output))
            #XXX check if this is the right way:
            if epoch == "(none)":
                ev = version
            else:
                ev = epoch + ":" + version
            return ev, release
        finally:
            if exported is None and os.path.isdir(tmpdir):
                shutil.rmtree(tmpdir)