source: soft/build_system/build_system/repsys/tags/R1_5_3_1-4mdk/RepSys/cgi/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.4 KB
Line 
1#!/usr/bin/python
2from RepSys import Error, config
3from RepSys.rpmutil import get_srpm
4from RepSys.cgiutil import CgiError, get_targets
5import cgi
6import sys
7import os
8
9TEMPLATE = """\
10<html>
11<head>
12<title>Repository package submission system</title>
13</head>
14<body bgcolor="white">
15<table cellspacing=0 cellpadding=0 border=0 width="100%%">
16  <tr bgcolor="#020264"><td align="left" valign="middle"><img src="http://qa.mandriva.com/mandriva.png" hspace=0 border=0 alt=""></td></tr>
17</table>
18<br>
19<hr>
20<center>
21<b>%(message)s</b>
22<br><br>
23<form method="POST" action="">
24<table><tr><td valign="top">
25  Package URL:<br>
26  <input name="packageurl" size="60" value="svn+ssh://cvs.mandriva.com/svn/mdv/cooker/"><br>
27  <small>Ex. svn+ssh://cvs.mandriva.com/svn/mdv/cooker/pkgname</small><br>
28  </td><td valign="top">
29  Revision:<br>
30  <input name="packagerev" size="10" value=""><br>
31  </td></tr></table>
32  <br>
33  Package target:<br>
34  <select name="target" size=5>
35  %(targetoptions)s
36  </select><br>
37  <br>
38  <input type="submit" value="Submit package">
39</form>
40</center>
41<hr/>
42</body>
43</html>
44"""
45
46def get_targetoptions():
47    s = ""
48    selected = " selected"
49    for target in get_targets():
50        s += '<option value="%s"%s>%s</option>' \
51             % (target.name, selected, target.name)
52        selected = ""
53    return s
54 
55def show(msg="", error=0):
56    if error:
57        msg = '<font color="red">%s</font>' % msg
58    print TEMPLATE % {"message":msg, "targetoptions":get_targetoptions()}
59
60def submit_packages(packager):
61    form = cgi.FieldStorage()
62    packageurl = form.getfirst("packageurl", "").strip()
63    packagerev = form.getfirst("packagerev", "").strip()
64    if not packageurl:
65        show()
66    elif not packagerev:
67        raise CgiError, "No revision provided!"
68    else:
69        targetname = form.getfirst("target")
70        if not targetname:
71            raise CgiError, "No target selected!"
72        for target in get_targets():
73            if target.name == targetname:
74                break
75        else:
76            raise CgiError, "Target not found!"
77        try:
78            tmp = int(packagerev)
79        except ValueError:
80            raise CgiError, "Invalid revision provided!"
81        for allowed in target.allowed:
82            if packageurl.startswith(allowed):
83                break
84        else:
85            raise CgiError, "%s is not allowed for this target!" % packageurl
86        get_srpm(packageurl,
87                 revision=packagerev,
88                 targetdirs=target.target,
89                 packager=packager,
90                 revname=1,
91                 svnlog=1,
92                 scripts=target.scripts)
93        show("Package submitted!")
94
95def main():
96    if not os.environ.has_key('REQUEST_METHOD'):
97        sys.stderr.write("error: this program is meant to be used as a cgi\n")
98        sys.exit(1)
99    print "Content-type: text/html\n\n"
100    try:
101        username = os.environ.get("REMOTE_USER")
102        method = os.environ.get("REQUEST_METHOD")
103        if not username or method != "POST":
104            show()
105        else:
106            useremail = config.get("users", username)
107            if not useremail:
108                raise CgiError, \
109                      "Your email was not found. Contact the administrator!"
110            submit_packages(useremail)
111    except CgiError, e:
112        show(str(e), error=1)
113    except Error, e:
114        error = str(e)
115        show(error[0].upper()+error[1:], error=1)
116    except:
117        cgi.print_exception()
118
119# vim:et:ts=4:sw=4
Note: See TracBrowser for help on using the repository browser.