aboutsummaryrefslogtreecommitdiff
path: root/master
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek.chauhan@gmail.com>2009-02-24 10:03:53 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2009-02-24 10:03:53 +0530
commit0989c022195975311fe550d2a317f7cf759184a1 (patch)
treeb0d6fc5dde69aead1c60b863f455d5ffc78c9126 /master
parentFix setup-master.py to not suck monkey balls (diff)
downloadautotua-0989c022195975311fe550d2a317f7cf759184a1.tar.gz
autotua-0989c022195975311fe550d2a317f7cf759184a1.tar.bz2
autotua-0989c022195975311fe550d2a317f7cf759184a1.zip
Minor changes to follow Pythonesque idioms
* try..finally instead of osp.exists() * Explicit relative imports
Diffstat (limited to 'master')
-rw-r--r--master/master/slave_api.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/master/master/slave_api.py b/master/master/slave_api.py
index e08f4d7..c1d750d 100644
--- a/master/master/slave_api.py
+++ b/master/master/slave_api.py
@@ -1,5 +1,5 @@
# vim: set sw=4 sts=4 et :
-# Copyright: 2008 Gentoo Foundation
+# Copyright: 2008-2009 Gentoo Foundation
# Author(s): Nirbheek Chauhan <nirbheek.chauhan@gmail.com>
# License: AGPL-3
#
@@ -16,7 +16,9 @@ from django.http import HttpResponse, Http404
from django.shortcuts import *
from master.models import Job, User, Slave
-import process, const
+from . import process, const
+
+CRYPTO = crypt.Crypto(gpghome=const.GPGHOME)
def _pickled_http_response(response, crypto=None, recipient=None):
response = pickle.dumps(response, 0)
@@ -45,13 +47,15 @@ def job_list(request, **kwargs):
jobs.append(job_data(job))
if kwargs.has_key('job_name') and len(jobs) == 1:
jobs = jobs[0]
+ # TODO: If logged in, send encrypted job list
+ # Also, find a way to let the slave explicitely request unencrypted
+ # communication
return _pickled_http_response(jobs)
def accept_job(request):
if request.method == 'GET' or not request.POST.has_key('data'):
raise Http404
- crypto = crypt.Crypto(gpghome=const.GPGHOME)
- (data, sender) = crypto.decrypt(request.POST['data'])
+ (data, sender) = CRYPTO.decrypt(request.POST['data'])
data = pickle.loads(data)
data['maintainer'] = get_object_or_404(User, username=data['maintainer'])
job = get_object_or_404(Job, **data)
@@ -65,7 +69,11 @@ def accept_job(request):
def get_pubkey(request):
pubkey_file = '%s/autotua_master.asc' % const.GPGHOME
- if not os.path.exists(pubkey_file):
+ try:
+ pubkey = open(pubkey_file)
+ except IOError, OSError:
crypto = crypt.Crypto(gpghome=const.GPGHOME)
crypto.export_pubkey(pubkey_file, 'AutotuA Master')
- return HttpResponse(open(pubkey_file).read())
+ pubkey = open(pubkey_file)
+ finally:
+ return HttpResponse(pubkey.read())