diff options
author | Bogdano Arendartchuk <bogdano@mandriva.org> | 2008-11-11 17:21:41 +0000 |
---|---|---|
committer | Bogdano Arendartchuk <bogdano@mandriva.org> | 2008-11-11 17:21:41 +0000 |
commit | 3a7d4937f2fbd7b80f0762258380c82e1cbffe13 (patch) | |
tree | 2c1c1d6e66e065d30c60079c311437f28ccb5157 /RepSys/commands/submit.py | |
parent | 86b2db69c2c1935ec282ef449a42349e5634a228 (diff) | |
parent | bc9f60a727164caf513746b5fc04f999c968f799 (diff) | |
download | mgarepo-3a7d4937f2fbd7b80f0762258380c82e1cbffe13.tar mgarepo-3a7d4937f2fbd7b80f0762258380c82e1cbffe13.tar.gz mgarepo-3a7d4937f2fbd7b80f0762258380c82e1cbffe13.tar.bz2 mgarepo-3a7d4937f2fbd7b80f0762258380c82e1cbffe13.tar.xz mgarepo-3a7d4937f2fbd7b80f0762258380c82e1cbffe13.zip |
make the V1_6_X branch the trunk
Diffstat (limited to 'RepSys/commands/submit.py')
-rw-r--r-- | RepSys/commands/submit.py | 148 |
1 files changed, 106 insertions, 42 deletions
diff --git a/RepSys/commands/submit.py b/RepSys/commands/submit.py index 5c95526..88ff596 100644 --- a/RepSys/commands/submit.py +++ b/RepSys/commands/submit.py @@ -1,5 +1,5 @@ #!/usr/bin/python -from RepSys import Error, config +from RepSys import Error, config, layout from RepSys.command import * from RepSys.rpmutil import get_spec, get_submit_info from RepSys.util import get_auth, execcmd, get_helper @@ -7,19 +7,29 @@ import urllib import getopt import sys import re - -#try: -# import NINZ.client -#except ImportError: -# NINZ = None +import subprocess import xmlrpclib HELP = """\ -Usage: repsys submit [OPTIONS] [URL [REVISION]] +Usage: repsys submit [OPTIONS] [URL[@REVISION] ...] Submits the package from URL to the submit host. +The submit host will try to build the package, and upon successful +completion will 'tag' the package and upload it to the official +repositories. + +The package name can refer to an alias to a group of packages defined in +the section submit-groups of the configuration file. + +The status of the submit can visualized at: + +http://kenobi.mandriva.com/bs/output.php + +If no URL and revision are specified, the latest changed revision in the +package working copy of the current directory will be used. + Options: -t TARGET Submit given package URL to given target -l Just list available targets @@ -28,53 +38,101 @@ Options: -s The host in which the package URL will be submitted (defaults to the host in the URL) -h Show this message + --distro The distribution branch where the packages come from --define Defines one variable to be used by the submit scripts in the submit host Examples: repsys submit - repsys submit foo 14800 - repsys submit https://repos/svn/mdv/cooker/foo 14800 - repsys submit -r 14800 https://repos/svn/mdv/cooker/foo + repsys submit foo + repsys submit 2009.1/foo + repsys submit foo@14800 bar baz@11001 + repsys submit https://repos/svn/mdv/cooker/foo repsys submit -l https://repos + repsys submit 2008.1/my-packages@11011 + repsys submit --define section=main/testing -t 2008.1 """ +DEFAULT_TARGET = "Cooker" + def parse_options(): parser = OptionParser(help=HELP) - parser.defaults["revision"] = "" - parser.add_option("-t", dest="target", default="Cooker") - parser.add_option("-l", dest="list", action="store_true") + 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("--define", action="append") + 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, rev = get_submit_info(".") - try: - yn = raw_input("Submit '%s', revision %d (y/N)? " % (name, rev)) - except KeyboardInterrupt: - yn = "n" - if yn.lower() in ("y", "yes"): - args = name, str(rev) + 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: - print "Cancelled." - sys.exit(1) - elif len(args) > 2: - raise Error, "invalid arguments" - opts.pkgdirurl = default_parent(args[0]) + raise Error, "can't use -r REV with more than one package name" + del opts.revision if len(args) == 2: - opts.revision = re.compile(r".*?(\d+).*").sub(r"\1", args[1]) - elif len(args) == 1 and opts.revision: - # accepts -r 3123 http://foo/bar - pass - elif not opts.list: - raise Error, "provide -l or a revision number" + # 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 + opts.urls = [layout.package_url(nameurl, distro=opts.distro, mirrored=False) + for nameurl in args] + 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 -def submit(pkgdirurl, revision, target, list=0, define=[], submithost=None): - #if not NINZ: - # raise Error, "you must have NINZ installed to use this command" +def expand_group(group): + name, rev = layout.split_url_revision(group) + distro = None + if "/" in name: + distro, name = name.rsplit("/", 1) + found = config.get("submit-groups", name) + packages = [group] + if found: + packages = found.split() + if rev: + packages = [("%s@%s" % (package, rev)) + for package in packages] + if distro: + packages = ["%s/%s" % (distro, package) + for package in packages] + return packages + +def list_targets(option, opt, val, parser): + host = config.get("submit", "host") + if host is None: + raise Error, "no submit host defined in repsys.conf" + createsrpm = get_helper("create-srpm") + #TODO make it configurable + command = "ssh %s %s --list" % (host, createsrpm) + execcmd(command, show=True) + sys.exit(0) + +def submit(urls, target, define=[], submithost=None): if submithost is None: submithost = config.get("submit", "host") if submithost is None: @@ -86,13 +144,20 @@ def submit(pkgdirurl, revision, target, list=0, define=[], submithost=None): del type, user, port, path, rest # runs a create-srpm in the server through ssh, which will make a # copy of the rpm in the export directory - if list: - raise Error, "unable to list targets from svn+ssh:// URLs" createsrpm = get_helper("create-srpm") - command = "ssh %s %s '%s' -r %s -t %s" % ( - submithost, createsrpm, pkgdirurl, revision, target) - if define: - command += " " + " ".join([ "--define " + x for x in define ]) + args = ["ssh", submithost, createsrpm, "-t", target] + for entry in define: + args.append("--define") + args.append(entry) + if len(urls) == 1: + # be compatible with server-side repsys versions older than 1.6.90 + url, rev = layout.split_url_revision(urls[0]) + args.append(url) + args.append("-r") + args.append(str(rev)) + else: + args.extend(urls) + command = subprocess.list2cmdline(args) status, output = execcmd(command) if status == 0: print "Package submitted!" @@ -100,7 +165,6 @@ def submit(pkgdirurl, revision, target, list=0, define=[], submithost=None): sys.stderr.write(output) sys.exit(status) - def main(): do_command(parse_options, submit) |