source: soft/build_system/build_system/repsys/tags/V1_6_13/RepSys/commands/submit.py @ 1

Last change on this file since 1 was 1, checked in by fasma, 12 years ago

Initial Import from Mandriva's soft revision 224062 and package revision 45733

File size: 3.5 KB
Line 
1#!/usr/bin/python
2from RepSys import Error, config
3from RepSys.command import *
4from RepSys.rpmutil import get_spec, get_submit_info
5from RepSys.util import get_auth, execcmd, get_helper
6import urllib
7import getopt
8import sys
9import re
10
11#try:
12#    import NINZ.client
13#except ImportError:
14#    NINZ = None
15
16import xmlrpclib
17
18HELP = """\
19Usage: repsys submit [OPTIONS] [URL [REVISION]]
20
21Submits the package from URL to the submit host.
22
23Options:
24    -t TARGET  Submit given package URL to given target
25    -l         Just list available targets
26    -r REV     Provides a revision number (when not providing as an
27               argument)
28    -s         The host in which the package URL will be submitted
29               (defaults to the host in the URL)
30    -h         Show this message
31    --define   Defines one variable to be used by the submit scripts
32               in the submit host
33
34Examples:
35    repsys submit
36    repsys submit foo 14800
37    repsys submit https://repos/svn/mdv/cooker/foo 14800
38    repsys submit -r 14800 https://repos/svn/mdv/cooker/foo
39    repsys submit -l https://repos
40"""
41
42def parse_options():
43    parser = OptionParser(help=HELP)
44    parser.defaults["revision"] = ""
45    parser.add_option("-t", dest="target", default="Cooker")
46    parser.add_option("-l", dest="list", action="store_true")
47    parser.add_option("-r", dest="revision", type="string", nargs=1)
48    parser.add_option("-s", dest="submithost", type="string", nargs=1,
49            default=None)
50    parser.add_option("--define", action="append")
51    opts, args = parser.parse_args()
52    if not args:
53        name, rev = get_submit_info(".")
54        try:
55            yn = raw_input("Submit '%s', revision %d (y/N)? " % (name, rev))
56        except KeyboardInterrupt:
57            yn = "n"
58        if yn.lower() in ("y", "yes"):
59            args = name, str(rev)
60        else:
61            print "Cancelled."
62            sys.exit(1)
63    elif len(args) > 2:
64        raise Error, "invalid arguments"
65    opts.pkgdirurl = default_parent(args[0])
66    if len(args) == 2:
67        opts.revision = re.compile(r".*?(\d+).*").sub(r"\1", args[1])
68    elif len(args) == 1 and opts.revision:
69        # accepts -r 3123 http://foo/bar
70        pass
71    elif not opts.list:
72        raise Error, "provide -l or a revision number"
73    return opts
74
75def submit(pkgdirurl, revision, target, list=0, define=[], submithost=None):
76    #if not NINZ:
77    #    raise Error, "you must have NINZ installed to use this command"
78    if submithost is None:
79        submithost = config.get("submit", "host")
80        if submithost is None:
81            # extract the submit host from the svn host
82            type, rest = urllib.splittype(pkgdirurl)
83            host, path = urllib.splithost(rest)
84            user, host = urllib.splituser(host)
85            submithost, port = urllib.splitport(host)
86            del type, user, port, path, rest
87    # runs a create-srpm in the server through ssh, which will make a
88    # copy of the rpm in the export directory
89    if list:
90        raise Error, "unable to list targets from svn+ssh:// URLs"
91    createsrpm = get_helper("create-srpm")
92    command = "ssh %s %s '%s' -r %s -t %s" % (
93            submithost, createsrpm, pkgdirurl, revision, target)
94    if define:
95        command += " " + " ".join([ "--define " + x for x in define ])
96    status, output = execcmd(command)
97    if status == 0:
98        print "Package submitted!"
99    else:
100        sys.stderr.write(output)
101        sys.exit(status)
102
103
104def main():
105    do_command(parse_options, submit)
106
107# vim:et:ts=4:sw=4
Note: See TracBrowser for help on using the repository browser.