1 | #!/usr/bin/python |
---|
2 | from RepSys import Error, config |
---|
3 | from RepSys.command import * |
---|
4 | from RepSys.rpmutil import get_spec, get_submit_info |
---|
5 | from RepSys.util import get_auth, execcmd, get_helper |
---|
6 | import urllib |
---|
7 | import getopt |
---|
8 | import sys |
---|
9 | import re |
---|
10 | |
---|
11 | #try: |
---|
12 | # import NINZ.client |
---|
13 | #except ImportError: |
---|
14 | # NINZ = None |
---|
15 | |
---|
16 | import xmlrpclib |
---|
17 | |
---|
18 | HELP = """\ |
---|
19 | Usage: repsys submit [OPTIONS] [URL [REVISION]] |
---|
20 | |
---|
21 | Submits the package from URL to the submit host. |
---|
22 | |
---|
23 | Options: |
---|
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 | |
---|
34 | Examples: |
---|
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 | |
---|
42 | def 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 | |
---|
75 | def 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 | |
---|
104 | def main(): |
---|
105 | do_command(parse_options, submit) |
---|
106 | |
---|
107 | # vim:et:ts=4:sw=4 |
---|