|
3 | 3 | import os |
4 | 4 | import json |
5 | 5 |
|
6 | | -from django.http import HttpResponse, HttpResponseForbidden, HttpResponseServerError, HttpResponseRedirect, Http404 |
| 6 | +from django.http import HttpResponse, HttpResponseForbidden, HttpResponseRedirect, Http404 |
7 | 7 | from django.shortcuts import render_to_response |
8 | 8 | from django.template import RequestContext |
9 | 9 | from django.conf import settings |
|
15 | 15 | from ietf.ietfauth.utils import role_required, has_role |
16 | 16 | from ietf.sync.discrepancies import find_discrepancies |
17 | 17 | from ietf.utils.serialize import object_as_shallow_dict |
| 18 | +from ietf.utils.log import log |
18 | 19 |
|
19 | 20 | SYNC_BIN_PATH = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../bin")) |
20 | 21 |
|
@@ -75,30 +76,29 @@ def notify(request, org, notification): |
75 | 76 |
|
76 | 77 | if request.method == "POST": |
77 | 78 | def runscript(name): |
78 | | - p = subprocess.Popen(["python", os.path.join(SYNC_BIN_PATH, name)], |
79 | | - stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
80 | | - out, _ = p.communicate() |
81 | | - return (p.returncode, out) |
| 79 | + cmd = ["python", os.path.join(SYNC_BIN_PATH, name)] |
| 80 | + cmdstring = " ".join(cmd) |
| 81 | + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 82 | + out, err = p.communicate() |
| 83 | + if p.returncode: |
| 84 | + log("Subprocess error %s when running '%s': %s %s" % (p.returncode, cmd, err, out)) |
| 85 | + raise subprocess.CalledProcessError(p.returncode, cmdstring, "\n".join([err, out])) |
82 | 86 |
|
83 | | - import syslog |
84 | | - syslog.syslog("Running sync script from notify view POST") |
| 87 | + log("Running sync script from notify view POST") |
85 | 88 |
|
86 | 89 | if notification == "protocols": |
87 | | - failed, out = runscript("iana-protocols-updates") |
| 90 | + runscript("iana-protocols-updates") |
88 | 91 |
|
89 | 92 | if notification == "changes": |
90 | | - failed, out = runscript("iana-changes-updates") |
| 93 | + runscript("iana-changes-updates") |
91 | 94 |
|
92 | 95 | if notification == "queue": |
93 | | - failed, out = runscript("rfc-editor-queue-updates") |
| 96 | + runscript("rfc-editor-queue-updates") |
94 | 97 |
|
95 | 98 | if notification == "index": |
96 | | - failed, out = runscript("rfc-editor-index-updates") |
| 99 | + runscript("rfc-editor-index-updates") |
97 | 100 |
|
98 | | - if failed: |
99 | | - return HttpResponseServerError("FAIL\n\n" + out, content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET) |
100 | | - else: |
101 | | - return HttpResponse("OK", content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET) |
| 101 | + return HttpResponse("OK", content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET) |
102 | 102 |
|
103 | 103 | return render_to_response('sync/notify.html', |
104 | 104 | dict(org=known_orgs[org], |
|
0 commit comments