Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
0
def commit(target=".", message=None, logfile=None):
    svn = SVN()
    status = svn.status(target, quiet=True)
    if not status:
        print "nothing to commit"
        return
    info = svn.info2(target)
    url = info.get("URL")
    if url is None:
        raise Error, "working copy URL not provided by svn info"
    mirrored = mirror.using_on(url)
    if mirrored:
        newurl = mirror.switchto_parent(svn, url, target)
        print "relocated to", newurl
    # we can't use the svn object here because svn --non-interactive option
    # hides VISUAL
    opts = []
    if message is not None:
        opts.append("-m \"%s\"" % message)
    if logfile is not None:
        opts.append("-F \"%s\"" % logfile)
    mopts = " ".join(opts)
    os.system("svn ci %s %s" % (mopts, target))
    if mirrored:
        print "use \"repsys switch\" in order to switch back to mirror "\
                "later"
Exemplo n.º 4
0
def commit(target=".", message=None, logfile=None):
    svn = SVN()
    status = svn.status(target, quiet=True)
    if not status:
        print "nothing to commit"
        return
    info = svn.info2(target)
    url = info.get("URL")
    if url is None:
        raise Error, "working copy URL not provided by svn info"
    mirrored = mirror.using_on(url)
    if mirrored:
        newurl = mirror.switchto_parent(svn, url, target)
        print "relocated to", newurl
    # we can't use the svn object here because svn --non-interactive option
    # hides VISUAL
    opts = []
    if message is not None:
        opts.append("-m \"%s\"" % message)
    if logfile is not None:
        opts.append("-F \"%s\"" % logfile)
    mopts = " ".join(opts)
    os.system("svn ci %s %s" % (mopts, target))
    if mirrored:
        print "use \"repsys switch\" in order to switch back to mirror "\
                "later"
Exemplo n.º 5
0
def check_changed(pkgdirurl, all=0, show=0, verbose=0):
    svn = SVN()
    if all:
        baseurl = pkgdirurl
        packages = []
        if verbose:
            print "Getting list of packages...",
            sys.stdout.flush()
        packages = [x[:-1] for x in svn.ls(baseurl)]
        if verbose:
            print "done"
        if not packages:
            raise Error, "couldn't get list of packages"
    else:
        baseurl, basename = os.path.split(pkgdirurl)
        packages = [basename]
    clean = []
    changed = []
    nopristine = []
    nocurrent = []
    for package in packages:
        pkgdirurl = os.path.join(baseurl, package)
        current = layout.checkout_url(pkgdirurl)
        pristine = layout.checkout_url(pkgdirurl, pristine=True)
        if verbose:
            print "Checking package %s..." % package,
            sys.stdout.flush()
        if not svn.ls(current, noerror=1):
            if verbose:
                print "NO CURRENT"
            nocurrent.append(package)
        elif not svn.ls(pristine, noerror=1):
            if verbose:
                print "NO PRISTINE"
            nopristine.append(package)
        else:
            diff = svn.diff(pristine, current)
            if diff:
                changed.append(package)
                if verbose:
                    print "CHANGED"
                if show:
                    print diff
            else:
                if verbose:
                    print "clean"
                clean.append(package)
    if verbose:
        if not packages:
            print "No packages found!"
        elif all:
            print "Total clean packages: %s" % len(clean)
            print "Total CHANGED packages: %d" % len(changed)
            print "Total NO CURRENT packages: %s" % len(nocurrent)
            print "Total NO PRISTINE packages: %s" % len(nopristine)
    return {"clean": clean,
            "changed": changed,
            "nocurrent": nocurrent,
            "nopristine": nopristine}
Exemplo n.º 6
0
def get_submit_info(path):
    path = os.path.abspath(path)

    # First, look for SPECS and SOURCES directories.
    found = False
    while path != "/":
        if os.path.isdir(path):
            specsdir = os.path.join(path, "SPECS")
            sourcesdir = os.path.join(path, "SOURCES")
            if os.path.isdir(specsdir) and os.path.isdir(sourcesdir):
                found = True
                break
        path = os.path.dirname(path)
    if not found:
        raise Error, "SPECS and/or SOURCES directories not found"

    # Then, check if this is really a subversion directory.
    if not os.path.isdir(os.path.join(path, ".svn")):
        raise Error, "subversion directory not found"

    svn = SVN()

    # Now, extract the package name.
    info = svn.info2(path)
    url = info.get("URL")
    if url is None:
        raise Error, "missing URL from svn info %s" % path
    toks = url.split("/")
    if len(toks) < 2 or toks[-1] != "current":
        raise Error, "unexpected URL received from 'svn info'"
    name = toks[-2]
    url = "/".join(toks[:-1])

    # Finally, guess revision.
    max = -1
    files = []
    files.extend(glob.glob("%s/*" % specsdir))
    files.extend(glob.glob("%s/*" % sourcesdir))
    for file in files:
        try:
            info = svn.info2(file)
        except Error:
            # possibly not tracked
            continue
        if info is None:
            continue
        rawrev = info.get("Last Changed Rev")
        if rawrev:
            rev = int(rawrev)
            if rev > max:
                max = rev
    if max == -1:
        raise Error, "revision tag not found in 'svn info' output"

    if mirror.using_on(url):
        url = mirror.switchto_parent_url(url)

    return name, url, max
Exemplo n.º 7
0
def get_submit_info(path):
    path = os.path.abspath(path)

    # First, look for SPECS and SOURCES directories.
    found = False
    while path != "/":
        if os.path.isdir(path):
            specsdir = os.path.join(path, "SPECS")
            sourcesdir = os.path.join(path, "SOURCES")
            if os.path.isdir(specsdir) and os.path.isdir(sourcesdir):
                found = True
                break
        path = os.path.dirname(path)
    if not found:
        raise Error, "SPECS and/or SOURCES directories not found"

    # Then, check if this is really a subversion directory.
    if not os.path.isdir(os.path.join(path, ".svn")):
        raise Error, "subversion directory not found"
    
    svn = SVN()

    # Now, extract the package name.
    info = svn.info2(path)
    url = info.get("URL")
    if url is None:
        raise Error, "missing URL from svn info %s" % path
    toks = url.split("/")
    if len(toks) < 2 or toks[-1] != "current":
        raise Error, "unexpected URL received from 'svn info'"
    name = toks[-2]
    url = "/".join(toks[:-1])

    # Finally, guess revision.
    max = -1
    files = []
    files.extend(glob.glob("%s/*" % specsdir))
    files.extend(glob.glob("%s/*" % sourcesdir))
    for file in files:
        try:
            info = svn.info2(file)
        except Error:
            # possibly not tracked
            continue
        if info is None:
            continue
        rawrev = info.get("Last Changed Rev")
        if rawrev:
            rev = int(rawrev)
            if rev > max:
                max = rev
    if max == -1:
        raise Error, "revision tag not found in 'svn info' output"

    if mirror.using_on(url):
        url = mirror.switchto_parent_url(url)
    
    return name, url, max
Exemplo n.º 8
0
def switch(mirrorurl=None):
    svn  = SVN()
    topdir = _getpkgtopdir()
    info = svn.info2(topdir)
    wcurl = info.get("URL")
    if wcurl is None:
        raise Error, "working copy URL not provided by svn info"
    newurl = mirror.autoswitch(svn, topdir, wcurl, mirrorurl)
    print "switched to", newurl
Exemplo n.º 9
0
def switch(mirrorurl=None):
    svn = SVN()
    topdir = _getpkgtopdir()
    info = svn.info2(topdir)
    wcurl = info.get("URL")
    if wcurl is None:
        raise Error, "working copy URL not provided by svn info"
    newurl = mirror.autoswitch(svn, topdir, wcurl, mirrorurl)
    print "switched to", newurl
Exemplo n.º 10
0
def rpmlog(pkgdirurl, revision, size, template, oldlog, usespec, sort):
    another = None
    if usespec:
        svn = SVN()
        specurl = layout.package_spec_url(pkgdirurl)
        rawspec = svn.cat(specurl, rev=revision)
        spec, another = split_spec_changelog(StringIO(rawspec))
    newlog = get_changelog(
        pkgdirurl, another=another, rev=revision, size=size, sort=sort, template=template, oldlog=oldlog
    )
    sys.stdout.writelines(newlog)
Exemplo n.º 11
0
def import_binaries(topdir, pkgname):
    """Import all binaries from a given package checkout

    @topdir: the path to the svn checkout
    """
    sourcesdir = os.path.join(topdir, "SOURCES")
    binaries = find_binaries([sourcesdir])
    for path in binaries:
        upload_binary(topdir, os.path.basename(path))
    update_sources(topdir, added=binaries)
    svn = SVN()
    svn.add(sources_path(topdir))
Exemplo n.º 12
0
def rpmlog(pkgdirurl, revision, size, template, oldlog, usespec, sort, fullnames):
    another = None
    if usespec:
        svn = SVN()
        specurl = layout.package_spec_url(pkgdirurl)
        rawspec = svn.cat(specurl, rev=revision)
        spec, another = split_spec_changelog(StringIO(rawspec))
    newlog = get_changelog(pkgdirurl, another=another, rev=revision,
            size=size, sort=sort, template=template, oldlog=oldlog, fullnames=fullnames)
    # make sure stdout support unicode, otherwise it'll croak when encountered
    if not "UTF-8" in sys.stdout.encoding:
        sys.stdout = open(sys.stdout.fileno(), mode="w", encoding="UTF-8")
    sys.stdout.writelines(newlog)
Exemplo n.º 13
0
def checkout(pkgdirurl, path=None, revision=None, branch=None,
        distro=None, spec=False):
    o_pkgdirurl = pkgdirurl
    pkgdirurl = layout.package_url(o_pkgdirurl, distro=distro)
    append = None
    if spec:
        append = "SPECS"
    current = layout.checkout_url(pkgdirurl, branch=branch,
            append_path=append)
    if path is None:
        path = layout.package_name(pkgdirurl)
    mirror.info(current)
    svn = SVN()
    svn.checkout(current, path, rev=revision, show=1)
Exemplo n.º 14
0
def checkout(pkgdirurl, path=None, revision=None, branch=None,
        distro=None, spec=False):
    o_pkgdirurl = pkgdirurl
    pkgdirurl = layout.package_url(o_pkgdirurl, distro=distro)
    append = None
    if spec:
        append = "SPECS"
    current = layout.checkout_url(pkgdirurl, branch=branch,
            append_path=append)
    if path is None:
        path = layout.package_name(pkgdirurl)
    mirror.info(current, write=True)
    svn = SVN()
    svn.checkout(current, path, rev=revision, show=1)
Exemplo n.º 15
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)
Exemplo n.º 16
0
def get_url_revision(url, retrieve=True):
    """Get the revision from a given URL

    If the URL contains an explicit revision number (URL@REV), just use it
    without even checking if the revision really exists.

    The parameter retrieve defines whether it must ask the SVN server for
    the revision number or not when it is not found in the URL.
    """
    url, rev = split_url_revision(url)
    if rev is None and retrieve:
        # if no revspec was found, ask the server
        svn = SVN()
        rev = svn.revision(url)
    return rev
Exemplo n.º 17
0
def rev_touched_url(url, rev):
    svn = SVN()
    info = svn.info2(url)
    if info is None:
        raise Error, "can't fetch svn info about the URL: %s" % url
    root = info["Repository Root"]
    urlpath = url[len(root):]
    touched = False
    entries = svn.log(root, start=rev, limit=1)
    entry = entries[0]
    for change in entry.changed:
        path = change.get("path")
        if path and path.startswith(urlpath):
            touched = True
    return touched
Exemplo n.º 18
0
def get_url_revision(url, retrieve=True):
    """Get the revision from a given URL

    If the URL contains an explicit revision number (URL@REV), just use it
    without even checking if the revision really exists.

    The parameter retrieve defines whether it must ask the SVN server for
    the revision number or not when it is not found in the URL.
    """
    url, rev = split_url_revision(url)
    if rev is None and retrieve:
        # if no revspec was found, ask the server
        svn = SVN()
        rev = svn.revision(url)
    return rev
Exemplo n.º 19
0
def rev_touched_url(url, rev):
    svn = SVN()
    info = svn.info2(url)
    if info is None:
        raise Error, "can't fetch svn info about the URL: %s" % url
    root = info["Repository Root"]
    urlpath = url[len(root):]
    touched = False
    entries = svn.log(root, start=rev, limit=1)
    entry = entries[0]
    for change in entry.changed:
        path = change.get("path")
        if path and path.startswith(urlpath):
            touched = True
    return touched
Exemplo n.º 20
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)
Exemplo n.º 21
0
def rpmlog(pkgdirurl, revision, size, template, oldlog, usespec, sort):
    another = None
    if usespec:
        svn = SVN()
        specurl = layout.package_spec_url(pkgdirurl)
        rawspec = svn.cat(specurl, rev=revision)
        spec, another = split_spec_changelog(StringIO(rawspec))
    newlog = get_changelog(pkgdirurl,
                           another=another,
                           rev=revision,
                           size=size,
                           sort=sort,
                           template=template,
                           oldlog=oldlog)
    sys.stdout.writelines(newlog)
Exemplo n.º 22
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)
Exemplo n.º 23
0
Arquivo: log.py Projeto: 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)
Exemplo n.º 24
0
def patch_spec(pkgdirurl, patchfile, log=""):
    #FIXME use get_spec
    svn = SVN()
    tmpdir = tempfile.mktemp()
    try:
        geturl = layout.checkout_url(pkgdirurl, append_path="SPECS")
        svn.checkout(geturl, tmpdir)
        speclist = glob.glob(os.path.join(tmpdir, "*.spec"))
        if not speclist:
            raise Error, "no spec files found"
        spec = speclist[0]
        status, output = execcmd(["patch", spec, patchfile])
        if status != 0:
            raise Error, "can't apply patch:\n%s\n" % output
        else:
            svn.commit(tmpdir, log="")
    finally:
        if os.path.isdir(tmpdir):
            shutil.rmtree(tmpdir)
Exemplo n.º 25
0
def sync(dryrun=False, download=False):
    svn = SVN()
    topdir = _getpkgtopdir()
    # run svn info because svn st does not complain when topdir is not an
    # working copy
    svn.info(topdir or ".")
    specsdir = os.path.join(topdir, "SPECS/")
    sourcesdir = os.path.join(topdir, "SOURCES/")
    for path in (specsdir, sourcesdir):
        if not os.path.isdir(path):
            raise Error, "%s directory not found" % path
    specs = glob.glob(os.path.join(specsdir, "*.spec"))
    if not specs:
        raise Error, "no .spec files found in %s" % specsdir
    specpath = specs[0] # FIXME better way?
    try:
        rpm.addMacro("_topdir", os.path.abspath(topdir))
        spec = rpm.TransactionSet().parseSpec(specpath)
    except rpm.error, e:
        raise Error, "could not load spec file: %s" % e
Exemplo n.º 26
0
def sync(dryrun=False, download=False):
    svn = SVN()
    topdir = _getpkgtopdir()
    # run svn info because svn st does not complain when topdir is not an
    # working copy
    svn.info(topdir or ".")
    specsdir = os.path.join(topdir, "SPECS/")
    sourcesdir = os.path.join(topdir, "SOURCES/")
    for path in (specsdir, sourcesdir):
        if not os.path.isdir(path):
            raise Error, "%s directory not found" % path
    specs = glob.glob(os.path.join(specsdir, "*.spec"))
    if not specs:
        raise Error, "no .spec files found in %s" % specsdir
    specpath = specs[0]  # FIXME better way?
    try:
        rpm.addMacro("_topdir", os.path.abspath(topdir))
        spec = rpm.TransactionSet().parseSpec(specpath)
    except rpm.error, e:
        raise Error, "could not load spec file: %s" % e
Exemplo n.º 27
0
def check_changed(pkgdirurl, all=0, show=0, verbose=0):
    svn = SVN()
    if all:
        baseurl = pkgdirurl
        packages = []
        if verbose:
            print "Getting list of packages...",
            sys.stdout.flush()
        packages = [x[:-1] for x in svn.ls(baseurl)]
        if verbose:
            print "done"
        if not packages:
            raise Error, "couldn't get list of packages"
    else:
        baseurl, basename = os.path.split(pkgdirurl)
        packages = [basename]
    clean = []
    changed = []
    nopristine = []
    nocurrent = []
    for package in packages:
        pkgdirurl = os.path.join(baseurl, package)
        current = layout.checkout_url(pkgdirurl)
        pristine = layout.checkout_url(pkgdirurl, pristine=True)
        if verbose:
            print "Checking package %s..." % package,
            sys.stdout.flush()
        if not svn.ls(current, noerror=1):
            if verbose:
                print "NO CURRENT"
            nocurrent.append(package)
        elif not svn.ls(pristine, noerror=1):
            if verbose:
                print "NO PRISTINE"
            nopristine.append(package)
        else:
            diff = svn.diff(pristine, current)
            if diff:
                changed.append(package)
                if verbose:
                    print "CHANGED"
                if show:
                    print diff
            else:
                if verbose:
                    print "clean"
                clean.append(package)
    if verbose:
        if not packages:
            print "No packages found!"
        elif all:
            print "Total clean packages: %s" % len(clean)
            print "Total CHANGED packages: %d" % len(changed)
            print "Total NO CURRENT packages: %s" % len(nocurrent)
            print "Total NO PRISTINE packages: %s" % len(nopristine)
    return {"clean": clean,
            "changed": changed,
            "nocurrent": nocurrent,
            "nopristine": nopristine}
Exemplo n.º 28
0
def detectVCS(url):
    if ':' in url:
        protocol,uri = url.split(":")
        if "svn" in protocol:
            return SVN(url=url)
        elif "git" in protocol:
            return GIT(url=url)
        elif "http" in protocol:
            if uri.endswith(".git"):
                return GIT(url=url)
            elif "svn" in uri:
                return SVN(url=url)
        raise Error("Unknown protocol %s for %s" % (protocol, url))
    elif os.path.exists(url) and os.path.isdir(url):
        while True:
            url = os.path.abspath(url)
            for vcs in (SVN, GIT):
                vcsdir = os.path.join(url, vcs.vcs_dirname)
                if os.path.exists(vcsdir) and os.path.isdir(vcsdir):
                    return vcs(path=url)
            url = os.path.dirname(url)
            if url == "/":
                break
    raise Error("No supported repository found at path: %s" % url)
Exemplo n.º 29
0
def patch_spec(pkgdirurl, patchfile, log=""):
    #FIXME use get_spec
    svn = SVN()
    tmpdir = tempfile.mktemp()
    try:
        geturl = layout.checkout_url(pkgdirurl, append_path="SPECS")
        svn.checkout(geturl, tmpdir)
        speclist = glob.glob(os.path.join(tmpdir, "*.spec"))
        if not speclist:
            raise Error, "no spec files found"
        spec = speclist[0]
        status, output = execcmd(["patch", spec, patchfile])
        if status != 0:
            raise Error, "can't apply patch:\n%s\n" % output
        else:
            svn.commit(tmpdir, log="")
    finally:
        if os.path.isdir(tmpdir):
            shutil.rmtree(tmpdir)
Exemplo n.º 30
0
def svn2rpm(pkgdirurl, rev=None, size=None, submit=False,
        template=None, macros=[], exported=None):
    concat = config.get("log", "concat", "").split()
    revoffset = get_revision_offset()
    svn = SVN()
    pkgreleasesurl = layout.checkout_url(pkgdirurl, releases=True)
    pkgcurrenturl = layout.checkout_url(pkgdirurl)
    releaseslog = svn.log(pkgreleasesurl, noerror=1)
    currentlog = svn.log(pkgcurrenturl, limit=size, start=rev,
            end=revoffset)

    # sort releases by copyfrom-revision, so that markreleases for same
    # revisions won't look empty
    releasesdata = []
    if releaseslog:
        for relentry in releaseslog[::-1]:
            try:
                (version, release, relrevision) = \
                        parse_markrelease_log(relentry)
            except InvalidEntryError:
                continue
            releasesdata.append((relrevision, -relentry.revision, relentry, 
                version, release))
        releasesdata.sort()

    # collect valid releases using the versions provided by the changes and
    # the packages
    prevrevision = 0
    releases = []
    for (relrevision, dummy, relentry, version, release) in releasesdata:
        if prevrevision == relrevision: 
            # ignore older markrelease of the same revision, since they
            # will have no history
            continue
        entries = [entry for entry in currentlog
                    if relrevision >= entry.revision and
                      (prevrevision < entry.revision)]
        if not entries:
            #XXX probably a forced release, without commits in current/,
            # check if this is the right behavior
            sys.stderr.write("warning: skipping (possible) release "
                    "%s-%s@%s, no commits since previous markrelease (r%r)\n" %
                    (version, release, relrevision, prevrevision))
            continue

        release = make_release(author=relentry.author,
                revision=relentry.revision, date=relentry.date,
                lines=relentry.lines, entries=entries,
                version=version, release=release)
        releases.append(release)
        prevrevision = relrevision
            
    # look for commits that have been not submitted (released) yet
    # this is done by getting all log entries newer (greater revision no.)
    # than releasesdata[-1] (in the case it exists)
    if releasesdata:
        latest_revision = releasesdata[-1][0] # the latest copied rev
    else:
        latest_revision = 0
    notsubmitted = [entry for entry in currentlog 
                    if entry.revision > latest_revision]
    if notsubmitted:
        # if they are not submitted yet, what we have to do is to add
        # a release/version number from getrelease()
        version, release = getrelease(pkgdirurl, macros=macros,
                exported=exported)
        toprelease = make_release(entries=notsubmitted, released=False,
                        version=version, release=release)
        releases.append(toprelease)

    data = dump_file(releases[::-1], currentlog=currentlog, template=template)
    return data
Exemplo n.º 31
0
def mark_release(pkgdirurl, version, release, revision):
    svn = SVN()
    releasesurl = "/".join([pkgdirurl, "releases"])
    versionurl = "/".join([releasesurl, version])
    releaseurl = "/".join([versionurl, release])
    if svn.ls(releaseurl, noerror=1):
        raise Error, "release already exists"
    svn.mkdir(releasesurl, noerror=1, log="Created releases directory.")
    svn.mkdir(versionurl,
              noerror=1,
              log="Created directory for version %s." % version)
    pristineurl = layout.checkout_url(pkgdirurl, pristine=True)
    svn.remove(pristineurl,
               noerror=1,
               log="Removing previous pristine/ directory.")
    currenturl = layout.checkout_url(pkgdirurl)
    svn.copy(currenturl,
             pristineurl,
             log="Copying release %s-%s to pristine/ directory." %
             (version, release))
    markreleaselog = create_markrelease_log(version, release, revision)
    svn.copy(currenturl, releaseurl, rev=revision, log=markreleaselog)
Exemplo n.º 32
0
def create_package(pkgdirurl, log="", verbose=0):
    svn = SVN()
    tmpdir = tempfile.mktemp()
    try:
        basename = layout.package_name(pkgdirurl)
        if verbose:
            print "Creating package directory...",
        sys.stdout.flush()
        ret = svn.mkdir(pkgdirurl,
                        log="Created package directory for '%s'." % basename)
        if verbose:
            print "done"
            print "Checking it out...",
        svn.checkout(pkgdirurl, tmpdir)
        if verbose:
            print "done"
            print "Creating package structure...",
        svn.mkdir(os.path.join(tmpdir, "current"))
        svn.mkdir(os.path.join(tmpdir, "current", "SPECS"))
        svn.mkdir(os.path.join(tmpdir, "current", "SOURCES"))
        if verbose:
            print "done"
            print "Committing...",
        svn.commit(tmpdir,
                   log="Created package structure for '%s'." % basename)
        print "done"
    finally:
        if os.path.isdir(tmpdir):
            shutil.rmtree(tmpdir)
Exemplo n.º 33
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)
Exemplo n.º 34
0
def put_srpm(srpmfile,
             markrelease=False,
             striplog=True,
             branch=None,
             baseurl=None,
             baseold=None,
             logmsg=None,
             rename=True):
    svn = SVN()
    srpm = SRPM(srpmfile)
    tmpdir = tempfile.mktemp()
    if baseurl:
        pkgurl = mirror._joinurl(baseurl, srpm.name)
    else:
        pkgurl = layout.package_url(srpm.name, distro=branch, mirrored=False)
    print "Importing package to %s" % pkgurl
    try:
        if srpm.epoch:
            version = "%s:%s" % (srpm.epoch, srpm.version)
        else:
            version = srpm.version
        versionurl = "/".join([pkgurl, "releases", version])
        releaseurl = "/".join([versionurl, srpm.release])
        currenturl = "/".join([pkgurl, "current"])
        currentdir = os.path.join(tmpdir, "current")
        #FIXME when pre-commit hook fails, there's no clear way to know
        # what happened
        ret = svn.mkdir(pkgurl, noerror=1, log="Created package directory")
        if ret or not svn.ls(currenturl, noerror=1):
            svn.checkout(pkgurl, tmpdir)
            svn.mkdir(os.path.join(tmpdir, "releases"))
            svn.mkdir(currentdir)
            svn.mkdir(os.path.join(currentdir, "SPECS"))
            svn.mkdir(os.path.join(currentdir, "SOURCES"))
            #svn.commit(tmpdir,log="Created package structure.")
            version_exists = 1
        else:
            if svn.ls(releaseurl, noerror=1):
                raise Error, "release already exists"
            svn.checkout("/".join([pkgurl, "current"]), tmpdir)
            svn.mkdir(versionurl,
                      noerror=1,
                      log="Created directory for version %s." % version)
            currentdir = tmpdir

        specsdir = os.path.join(currentdir, "SPECS")
        sourcesdir = os.path.join(currentdir, "SOURCES")

        unpackdir = tempfile.mktemp()
        os.mkdir(unpackdir)
        try:
            srpm.unpack(unpackdir)

            uspecsdir = os.path.join(unpackdir, "SPECS")
            usourcesdir = os.path.join(unpackdir, "SOURCES")

            uspecsentries = os.listdir(uspecsdir)
            usourcesentries = os.listdir(usourcesdir)
            specsentries = os.listdir(specsdir)
            sourcesentries = os.listdir(sourcesdir)

            # Remove old entries
            for entry in [x for x in specsentries if x not in uspecsentries]:
                if entry == ".svn":
                    continue
                entrypath = os.path.join(specsdir, entry)
                os.unlink(entrypath)
                svn.remove(entrypath)
            for entry in [
                    x for x in sourcesentries if x not in usourcesentries
            ]:
                if entry == ".svn":
                    continue
                entrypath = os.path.join(sourcesdir, entry)
                os.unlink(entrypath)
                svn.remove(entrypath)

            # Copy all files
            execcmd(["cp", "-rf", uspecsdir, currentdir])
            execcmd(["cp", "-rf", usourcesdir, currentdir])

            # Add new entries
            for entry in [x for x in uspecsentries if x not in specsentries]:
                entrypath = os.path.join(specsdir, entry)
                svn.add(entrypath)
            for entry in [
                    x for x in usourcesentries if x not in sourcesentries
            ]:
                entrypath = os.path.join(sourcesdir, entry)
                svn.add(entrypath)
        finally:
            if os.path.isdir(unpackdir):
                shutil.rmtree(unpackdir)

        specs = glob.glob(os.path.join(specsdir, "*.spec"))
        if not specs:
            raise Error, "no spec file found on %s" % specsdir
        if len(specs) > 1:
            raise Error, "more than one spec file found on %s" % specsdir
        specpath = specs[0]
        if rename:
            specfile = os.path.basename(specpath)
            specname = specfile[:-len(".spec")]
            if specname != srpm.name:
                newname = srpm.name + ".spec"
                newpath = os.path.join(specsdir, newname)
                sys.stderr.write("warning: renaming spec file to '%s' "
                                 "(use -n to disable it)\n" % (newname))
                os.rename(specpath, newpath)
                try:
                    svn.remove(specpath)
                except Error:
                    # file not tracked
                    svn.revert(specpath)
                svn.add(newpath)
                specpath = newpath

        if striplog:
            specpath = specpath
            fspec = open(specpath)
            spec, chlog = log.split_spec_changelog(fspec)
            fspec.close()
            fspec = open(specpath, "w")
            fspec.writelines(spec)
            fspec.close()
            chlog.seek(0, os.SEEK_END)
            if chlog.tell() != 0:
                chlog.seek(0)
                #FIXME move it to layout.py
                oldurl = baseold or config.get("log", "oldurl")
                pkgoldurl = mirror._joinurl(oldurl, srpm.name)
                svn.mkdir(pkgoldurl,
                          noerror=1,
                          log="created old log directory for %s" % srpm.name)
                logtmp = tempfile.mktemp()
                try:
                    svn.checkout(pkgoldurl, logtmp)
                    miscpath = os.path.join(logtmp, "log")
                    fmisc = open(miscpath, "w+")
                    fmisc.writelines(chlog)
                    fmisc.close()
                    svn.add(miscpath)
                    svn.commit(logtmp,
                               log="imported old log for %s" % srpm.name)
                finally:
                    if os.path.isdir(logtmp):
                        shutil.rmtree(logtmp)
        svn.commit(tmpdir, log=logmsg or ("imported package %s" % srpm.name))
    finally:
        if os.path.isdir(tmpdir):
            shutil.rmtree(tmpdir)

    # Do revision and pristine tag copies
    pristineurl = layout.checkout_url(pkgurl, pristine=True)
    svn.remove(pristineurl,
               noerror=1,
               log="Removing previous pristine/ directory.")
    currenturl = layout.checkout_url(pkgurl)
    svn.copy(currenturl,
             pristineurl,
             log="Copying release %s-%s to pristine/ directory." %
             (version, srpm.release))
    if markrelease:
        svn.copy(currenturl,
                 releaseurl,
                 log="Copying release %s-%s to releases/ directory." %
                 (version, srpm.release))
Exemplo n.º 35
0
def mirror_relocate(oldparent, newparent, url, wcpath):
    svn = SVN()
    newurl = relocate_path(oldparent, newparent, url)
    svn.switch(newurl, url, path=wcpath, relocate=True)
    return newurl
Exemplo n.º 36
0
def create_package(pkgdirurl, log="", verbose=0):
    svn = SVN()
    tmpdir = tempfile.mktemp()
    try:
        basename = layout.package_name(pkgdirurl)
        if verbose:
            print "Creating package directory...",
        sys.stdout.flush()
        ret = svn.mkdir(pkgdirurl,
                        log="Created package directory for '%s'." % basename)
        if verbose:
            print "done"
            print "Checking it out...",
        svn.checkout(pkgdirurl, tmpdir)
        if verbose:
            print "done"
            print "Creating package structure...",
        svn.mkdir(os.path.join(tmpdir, "current"))
        svn.mkdir(os.path.join(tmpdir, "current", "SPECS"))
        svn.mkdir(os.path.join(tmpdir, "current", "SOURCES"))
        if verbose:
            print "done"
            print "Committing...",
        svn.commit(tmpdir,
                   log="Created package structure for '%s'." % basename)
        print "done"
    finally:
        if os.path.isdir(tmpdir):
            shutil.rmtree(tmpdir)
Exemplo n.º 37
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
Exemplo n.º 38
0
def mark_release(pkgdirurl, version, release, revision):
    svn = SVN()
    releasesurl = "/".join([pkgdirurl, "releases"])
    versionurl = "/".join([releasesurl, version])
    releaseurl = "/".join([versionurl, release])
    if svn.ls(releaseurl, noerror=1):
        raise Error, "release already exists"
    svn.mkdir(releasesurl, noerror=1,
              log="Created releases directory.")
    svn.mkdir(versionurl, noerror=1,
              log="Created directory for version %s." % version)
    pristineurl = layout.checkout_url(pkgdirurl, pristine=True)
    svn.remove(pristineurl, noerror=1,
               log="Removing previous pristine/ directory.")
    currenturl = layout.checkout_url(pkgdirurl)
    svn.copy(currenturl, pristineurl,
             log="Copying release %s-%s to pristine/ directory." %
                 (version, release))
    markreleaselog = create_markrelease_log(version, release, revision)
    svn.copy(currenturl, releaseurl, rev=revision,
             log=markreleaselog)
Exemplo n.º 39
0
def editlog(pkgdirurl, revision):
    svn = SVN()
    svn.propedit("svn:log", pkgdirurl, rev=revision)
Exemplo n.º 40
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
Exemplo n.º 41
0
def editlog(pkgdirurl, revision):
    svn = SVN()
    svn.propedit("svn:log", pkgdirurl, rev=revision)
Exemplo n.º 42
0
def mirror_relocate(oldparent, newparent, url, wcpath):
    svn = SVN()
    newurl = relocate_path(oldparent, newparent, url)
    svn.switch(newurl, url, path=wcpath, relocate=True)
    return newurl
Exemplo n.º 43
0
def svn2rpm(pkgdirurl,
            rev=None,
            size=None,
            submit=False,
            template=None,
            macros=[],
            exported=None,
            create=False):
    concat = config.get("log", "concat", "").split()
    revoffset = get_revision_offset()
    svn = SVN()
    pkgreleasesurl = layout.checkout_url(pkgdirurl, releases=True)
    pkgcurrenturl = layout.checkout_url(pkgdirurl)
    releaseslog = svn.log(pkgreleasesurl, noerror=1)
    currentlog = svn.log(pkgcurrenturl, limit=size, start=rev, end=revoffset)

    # sort releases by copyfrom-revision, so that markreleases for same
    # revisions won't look empty
    releasesdata = []
    if releaseslog:
        for relentry in releaseslog[::-1]:
            try:
                (version, release, relrevision) = \
                        parse_markrelease_log(relentry)
            except InvalidEntryError:
                continue
            releasesdata.append(
                (relrevision, -relentry.revision, relentry, version, release))
        releasesdata.sort()

    # collect valid releases using the versions provided by the changes and
    # the packages
    prevrevision = 0
    releases = []
    for (relrevision, dummy, relentry, version, release) in releasesdata:
        if prevrevision == relrevision:
            # ignore older markrelease of the same revision, since they
            # will have no history
            continue
        entries = [
            entry for entry in currentlog
            if relrevision >= entry.revision and (
                prevrevision < entry.revision)
        ]
        if not entries:
            #XXX probably a forced release, without commits in current/,
            # check if this is the right behavior
            sys.stderr.write(
                "warning: skipping (possible) release "
                "%s-%s@%s, no commits since previous markrelease (r%r)\n" %
                (version, release, relrevision, prevrevision))
            continue

        release = make_release(author=relentry.author,
                               revision=relentry.revision,
                               date=relentry.date,
                               lines=relentry.lines,
                               entries=entries,
                               version=version,
                               release=release)
        releases.append(release)
        prevrevision = relrevision

    # look for commits that have been not submitted (released) yet
    # this is done by getting all log entries newer (greater revision no.)
    # than releasesdata[-1] (in the case it exists)
    if releasesdata:
        latest_revision = releasesdata[-1][0]  # the latest copied rev
    else:
        latest_revision = 0
    notsubmitted = [
        entry for entry in currentlog if entry.revision > latest_revision
    ]
    if notsubmitted:
        # if they are not submitted yet, what we have to do is to add
        # a release/version number from getrelease()
        version, release = getrelease(pkgdirurl,
                                      macros=macros,
                                      exported=exported,
                                      create=create)
        toprelease = make_release(entries=notsubmitted,
                                  released=False,
                                  version=version,
                                  release=release)
        releases.append(toprelease)

    data = dump_file(releases[::-1], currentlog=currentlog, template=template)
    return data
Exemplo n.º 44
0
def parse_options():
    parser = OptionParser(help=HELP)
    parser.defaults["revision"] = None
    parser.add_option("-t", dest="target", default=None)
    parser.add_option("-l", action="callback", callback=list_targets)
    parser.add_option("-r", dest="revision", type="string", nargs=1)
    parser.add_option("-s",
                      dest="submithost",
                      type="string",
                      nargs=1,
                      default=None)
    parser.add_option("-i", dest="sid", type="string", nargs=1, default=None)
    parser.add_option("-a", dest="atonce", action="store_true", default=False)
    parser.add_option("--distro", dest="distro", type="string", default=None)
    parser.add_option("--define", action="append", default=[])
    opts, args = parser.parse_args()
    if not args:
        name, url, rev = get_submit_info(".")
        args = ["%s@%s" % (url, str(rev))]
        print("Submitting %s at revision %s" % (name, rev))
        print("URL: %s" % url)
    if opts.revision is not None:
        # backwards compatibility with the old -r usage
        if len(args) == 1:
            args[0] = args[0] + "@" + opts.revision
        else:
            raise Error("can't use -r REV with more than one package name")
    del opts.revision
    if len(args) == 2:
        # prevent from using the old <name> <rev> syntax
        try:
            rev = int(args[1])
        except ValueError:
            # ok, it is a package name, let it pass
            pass
        else:
            raise Error("the format <name> <revision> is deprecated, "\
                    "use <name>@<revision> instead")
    # expand group aliases
    expanded = []
    for nameurl in args:
        expanded.extend(expand_group(nameurl))
    if expanded != args:
        print("Submitting: %s" % " ".join(expanded))
        args = expanded
    # generate URLs for package names:
    opts.urls = [
        mirror.strip_username(
            layout.package_url(nameurl, distro=opts.distro, mirrored=False))
        for nameurl in args
    ]
    # find the revision if not specified:
    newurls = []
    for url in opts.urls:
        if not "@" in url:
            print("Fetching revision...")
            courl = layout.checkout_url(url)
            log = SVN().log(courl, limit=1)
            if not log:
                raise Error("can't find a revision for %s" % courl)
            ci = log[0]
            print("URL:", url)
            print("Commit:", end=' ')
            print("%d | %s" % (ci.revision, ci.author), end=' ')
            if ci.lines:
                line = " ".join(ci.lines).strip()
                if len(line) > 57:
                    line = line[:57] + "..."
                print("| %s" % line, end=' ')
            print()
            url = url + "@" + str(ci.revision)
        newurls.append(url)
    opts.urls[:] = newurls
    # choose a target if not specified:
    if opts.target is None and opts.distro is None:
        target = layout.distro_branch(opts.urls[0]) or DEFAULT_TARGET
        print("Implicit target: %s" % target)
        opts.target = target
    del opts.distro
    return opts
Exemplo n.º 45
0
def put_srpm(srpmfile, markrelease=False, striplog=True, branch=None,
        baseurl=None, baseold=None, logmsg=None, rename=True):
    svn = SVN()
    srpm = SRPM(srpmfile)
    tmpdir = tempfile.mktemp()
    if baseurl:
        pkgurl = mirror._joinurl(baseurl, srpm.name)
    else:
        pkgurl = layout.package_url(srpm.name, distro=branch,
                mirrored=False)
    print "Importing package to %s" % pkgurl
    try:
        if srpm.epoch:
            version = "%s:%s" % (srpm.epoch, srpm.version)
        else:
            version = srpm.version
        versionurl = "/".join([pkgurl, "releases", version])
        releaseurl = "/".join([versionurl, srpm.release])
        currenturl = "/".join([pkgurl, "current"])
        currentdir = os.path.join(tmpdir, "current")
        #FIXME when pre-commit hook fails, there's no clear way to know
        # what happened
        ret = svn.mkdir(pkgurl, noerror=1, log="Created package directory")
        if ret or not svn.ls(currenturl, noerror=1):
            svn.checkout(pkgurl, tmpdir)
            svn.mkdir(os.path.join(tmpdir, "releases"))
            svn.mkdir(currentdir)
            svn.mkdir(os.path.join(currentdir, "SPECS"))
            svn.mkdir(os.path.join(currentdir, "SOURCES"))
            #svn.commit(tmpdir,log="Created package structure.")
            version_exists = 1
        else:
            if svn.ls(releaseurl, noerror=1):
                raise Error, "release already exists"
            svn.checkout("/".join([pkgurl, "current"]), tmpdir)
            svn.mkdir(versionurl, noerror=1,
                      log="Created directory for version %s." % version)
            currentdir = tmpdir
         
        specsdir = os.path.join(currentdir, "SPECS")
        sourcesdir = os.path.join(currentdir, "SOURCES")

        unpackdir = tempfile.mktemp()
        os.mkdir(unpackdir)
        try:
            srpm.unpack(unpackdir)

            uspecsdir = os.path.join(unpackdir, "SPECS")
            usourcesdir = os.path.join(unpackdir, "SOURCES")
            
            uspecsentries = os.listdir(uspecsdir)
            usourcesentries = os.listdir(usourcesdir)
            specsentries = os.listdir(specsdir)
            sourcesentries = os.listdir(sourcesdir)

            # Remove old entries
            for entry in [x for x in specsentries
                             if x not in uspecsentries]:
                if entry == ".svn":
                    continue
                entrypath = os.path.join(specsdir, entry)
                os.unlink(entrypath)
                svn.remove(entrypath)
            for entry in [x for x in sourcesentries
                             if x not in usourcesentries]:
                if entry == ".svn":
                    continue
                entrypath = os.path.join(sourcesdir, entry)
                os.unlink(entrypath)
                svn.remove(entrypath)

            # Copy all files
            execcmd(["cp", "-rf", uspecsdir, currentdir])
            execcmd(["cp", "-rf", usourcesdir, currentdir])
            
            # Add new entries
            for entry in [x for x in uspecsentries
                             if x not in specsentries]:
                entrypath = os.path.join(specsdir, entry)
                svn.add(entrypath)
            for entry in [x for x in usourcesentries
                             if x not in sourcesentries]:
                entrypath = os.path.join(sourcesdir, entry)
                svn.add(entrypath)
        finally:
            if os.path.isdir(unpackdir):
                shutil.rmtree(unpackdir)

        specs = glob.glob(os.path.join(specsdir, "*.spec"))
        if not specs:
            raise Error, "no spec file found on %s" % specsdir
        if len(specs) > 1:
            raise Error, "more than one spec file found on %s" % specsdir
        specpath = specs[0]
        if rename:
            specfile = os.path.basename(specpath)
            specname = specfile[:-len(".spec")]
            if specname != srpm.name:
                newname = srpm.name + ".spec"
                newpath = os.path.join(specsdir, newname)
                sys.stderr.write("warning: renaming spec file to '%s' "
                        "(use -n to disable it)\n" % (newname))
                os.rename(specpath, newpath)
                try:
                    svn.remove(specpath)
                except Error:
                    # file not tracked
                    svn.revert(specpath)
                svn.add(newpath)
                specpath = newpath

        if striplog:
            specpath = specpath
            fspec = open(specpath)
            spec, chlog = log.split_spec_changelog(fspec)
            fspec.close()
            fspec = open(specpath, "w")
            fspec.writelines(spec)
            fspec.close()
            chlog.seek(0, os.SEEK_END)
            if chlog.tell() != 0:
                chlog.seek(0)
                #FIXME move it to layout.py
                oldurl = baseold or config.get("log", "oldurl")
                pkgoldurl = mirror._joinurl(oldurl, srpm.name)
                svn.mkdir(pkgoldurl, noerror=1,
                        log="created old log directory for %s" % srpm.name)
                logtmp = tempfile.mktemp()
                try:
                    svn.checkout(pkgoldurl, logtmp)
                    miscpath = os.path.join(logtmp, "log")
                    fmisc = open(miscpath, "w+")
                    fmisc.writelines(chlog)
                    fmisc.close()
                    svn.add(miscpath)
                    svn.commit(logtmp,
                            log="imported old log for %s" % srpm.name)
                finally:
                    if os.path.isdir(logtmp):
                        shutil.rmtree(logtmp)
        svn.commit(tmpdir,
                log=logmsg or ("imported package %s" % srpm.name))
    finally:
        if os.path.isdir(tmpdir):
            shutil.rmtree(tmpdir)

    # Do revision and pristine tag copies
    pristineurl = layout.checkout_url(pkgurl, pristine=True)
    svn.remove(pristineurl, noerror=1,
               log="Removing previous pristine/ directory.")
    currenturl = layout.checkout_url(pkgurl)
    svn.copy(currenturl, pristineurl,
             log="Copying release %s-%s to pristine/ directory." %
                 (version, srpm.release))
    if markrelease:
        svn.copy(currenturl, releaseurl,
                 log="Copying release %s-%s to releases/ directory." %
                     (version, srpm.release))