def submit(project, reporter, email, summary, ticket_description="", location=None, component="", **kw): #project = "test" baseurl_exposed = "https://trac.the-hub.net" baseurl = "http://172.24.0.206:13000" loginurl = "%s/%s/login" % (baseurl, project) newticketurl = "%s/%s/newticket" % (baseurl, project) b = mechanize.Browser() b.set_handle_robots(False) b.open(loginurl) forms = list(b.forms()) for form in forms: if set(["user", "password"]).issubset(set([c.name for c in form.controls])): nr = forms.index(form) b.select_form(nr=nr) break # else: no form ? b['user'] = settings.TRAC_USER b['password'] = settings.TRAC_SECRET try: b.submit() except Exception, err: if isinstance(err, mechanize._response.seek_wrapper): if err.wrapped.code == 501 and 'https_proxy' in os.environ: raise Exception("Hint: try unset https_proxy before you start the issue reporter deamon") # at this point we should email the request to us raise
b['user'] = settings.TRAC_USER b['password'] = settings.TRAC_SECRET try: b.submit() except Exception, err: if isinstance(err, mechanize._response.seek_wrapper): if err.wrapped.code == 501 and 'https_proxy' in os.environ: raise Exception("Hint: try unset https_proxy before you start the issue reporter deamon") # at this point we should email the request to us raise b.open(newticketurl) forms = list(b.forms()) for form in forms: if set(["field_reporter", "field_summary"]).issubset(set([c.name for c in form.controls])): nr = forms.index(form) b.select_form(nr=nr) break # else: no form ? b["field_reporter"] = "%(reporter)s <%(email)s>" % locals() b["field_summary"] = summary b["field_description"] = ticket_description #b["field_type"] = ["defect"] b["field_priority"] = ["major"] if component: b["field_component"] = [component] if location and project in ('networks', 'test') and location.lower() != 'other': b['field_hub_location'] = [location] if 'cc_email' in kw: b['field_cc'] = kw['cc_email'] b.submit('submit')