Commit e29df255 authored by BAIRE Anthony's avatar BAIRE Anthony
Browse files

add Job.data_dir to deduplicate code

parent b6398dcf
......@@ -50,8 +50,8 @@ def job_response(job, request):
4: 'archived',
5: 'deleted',
6: 'aborting'}
odir = os.path.join(DATASTORE, str(
files = {f: get_link(, odir, f, request) for f in os.listdir(odir)
job_dir = job.data_dir
files = {f: get_link(, job_dir, f, request) for f in os.listdir(job_dir)
if os.path.isfile(os.path.join(odir,f)) and not f.startswith(".")}
return {str( {'status': status[job.state],
'files': files
......@@ -105,7 +105,7 @@ def jobs(request):
log.debug('No usable versions')
return HttpResponse("This app is not yet published", status=404)
upload_data(request.FILES.values(), job)
# run the Job validators
......@@ -60,24 +60,24 @@ def get_ssh_data(key):
return fp_encoded, comment
def upload_data(uploaded_files, job_id):
def upload_data(uploaded_files, job):
Upload any data according to a specific job id
uploaded_files: iterable that yields
django.core.files.uploadedfile.UploadedFile objects
job_id (int): job ID.
job (Job): job
>>> upload_data(self.request.FILES.getlist('files'),
>>> upload_data(self.request.FILES.getlist('files'), job)
job_dir = os.path.join(settings.DATASTORE, str(job_id))
job_dir = job.data_dir
for file_data in uploaded_files:
from __future__ import unicode_literals
import os
from django.conf import settings
from django.contrib.auth.models import User, AnonymousUser
from django.core.validators import MinLengthValidator, MinValueValidator, \
......@@ -482,6 +484,13 @@ class Job(TimeStampModel):
return self.state not in (Job.RUNNING, Job.ABORTING)
def data_dir(self):
"""Return the system path to the job data directory"""
return os.path.join(settings.DATASTORE, str(
# def __str__(self):
# return self.webapp
......@@ -656,7 +656,7 @@ class JobDetail(LoginRequiredMixin, DetailView):
if job.state == Job.DONE:
# job is done
# -> read the `allgo.log` file
log_file = os.path.join(dirname, 'allgo.log')
log_file = os.path.join(job.data_dir, 'allgo.log')
with open(log_file, 'r', errors="replace") as log_data:
logs =
......@@ -735,7 +735,7 @@ class JobCreate(SuccessMessageMixin, CreateView):
# Upload files if there are any
upload_data(self.request.FILES.getlist('files'), obj)
# start the job
obj.state = Job.WAITING
......@@ -871,7 +871,7 @@ class JobDelete(LoginRequiredMixin, DeleteView):
# delete the data dir if present
# FIXME: if this fail then we have dangling files staying in the way
job_dir = os.path.join(settings.DATASTORE, str(pk))
job_dir = job.data_dir
if os.path.exists(job_dir):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment