#!/usr/bin/python from MgaRepo import Error, config from MgaRepo.rpmutil import get_srpm from MgaRepo.cgiutil import CgiError, get_targets import cgi import sys import os TEMPLATE = """\ Repository package submission system


%(message)s

Package URL:

Ex. svn+ssh://cvs.mandriva.com/svn/mdv/cooker/pkgname
Revision:


Package target:



""" def get_targetoptions(): s = "" selected = " selected" for target in get_targets(): s += '' \ % (target.name, selected, target.name) selected = "" return s def show(msg="", error=0): if error: msg = '%s' % msg print(TEMPLATE % {"message":msg, "targetoptions":get_targetoptions()}) def submit_packages(packager): form = cgi.FieldStorage() packageurl = form.getfirst("packageurl", "").strip() packagerev = form.getfirst("packagerev", "").strip() if not packageurl: show() elif not packagerev: raise CgiError("No revision provided!") else: targetname = form.getfirst("target") if not targetname: raise CgiError("No target selected!") for target in get_targets(): if target.name == targetname: break else: raise CgiError("Target not found!") try: tmp = int(packagerev) except ValueError: raise CgiError("Invalid revision provided!") for allowed in target.allowed: if packageurl.startswith(allowed): break else: raise CgiError("%s is not allowed for this target!" % packageurl) get_srpm(packageurl, revision=packagerev, targetdirs=target.target, packager=packager, revname=1, svnlog=1, scripts=target.scripts) show("Package submitted!") def main(): if 'REQUEST_METHOD' not in os.environ: sys.stderr.write("error: this program is meant to be used as a cgi\n") sys.exit(1) print("Content-type: text/html\n\n") try: username = os.environ.get("REMOTE_USER") method = os.environ.get("REQUEST_METHOD") if not username or method != "POST": show() else: useremail = config.get("users", username) if not useremail: raise CgiError("Your email was not found. Contact the administrator!") submit_packages(useremail) except CgiError as e: show(str(e), error=1) except Error as e: error = str(e) show(error[0].upper()+error[1:], error=1) except: cgi.print_exception() # vim:et:ts=4:sw=4