Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
allgo
allgo
Commits
e29df255
Commit
e29df255
authored
Sep 18, 2018
by
BAIRE Anthony
Browse files
add Job.data_dir to deduplicate code
parent
b6398dcf
Changes
4
Hide whitespace changes
Inline
Side-by-side
django/allgo/api/v1/views.py
View file @
e29df255
...
...
@@ -50,8 +50,8 @@ def job_response(job, request):
4
:
'archived'
,
5
:
'deleted'
,
6
:
'aborting'
}
o
dir
=
os
.
path
.
join
(
DATASTORE
,
str
(
job
.
id
))
files
=
{
f
:
get_link
(
job
.
id
,
o
dir
,
f
,
request
)
for
f
in
os
.
listdir
(
o
dir
)
job_
dir
=
job
.
data_dir
files
=
{
f
:
get_link
(
job
.
id
,
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
(
job
.
id
):
{
'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
.
id
)
upload_data
(
request
.
FILES
.
values
(),
job
)
# run the Job validators
try
:
...
...
django/allgo/main/helpers.py
View file @
e29df255
...
...
@@ -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
Args:
uploaded_files: iterable that yields
django.core.files.uploadedfile.UploadedFile objects
job
_id (int):
job
ID.
job
(Job):
job
Examples:
>>> upload_data(self.request.FILES.getlist('files'), job
.id
)
>>> upload_data(self.request.FILES.getlist('files'), job)
Returns:
Nothing
"""
job_dir
=
os
.
path
.
join
(
settings
.
DATASTORE
,
str
(
job_id
))
job_dir
=
job
.
data_dir
os
.
makedirs
(
job_dir
)
for
file_data
in
uploaded_files
:
...
...
django/allgo/main/models.py
View file @
e29df255
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
,
\
RegexValidator
...
...
@@ -482,6 +484,13 @@ class Job(TimeStampModel):
"""
return
self
.
state
not
in
(
Job
.
RUNNING
,
Job
.
ABORTING
)
@
property
def
data_dir
(
self
):
"""Return the system path to the job data directory"""
return
os
.
path
.
join
(
settings
.
DATASTORE
,
str
(
self
.
id
))
# def __str__(self):
# return self.webapp
...
...
django/allgo/main/views.py
View file @
e29df255
...
...
@@ -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'
)
try
:
with
open
(
log_file
,
'r'
,
errors
=
"replace"
)
as
log_data
:
logs
=
log_data
.
read
()
...
...
@@ -735,7 +735,7 @@ class JobCreate(SuccessMessageMixin, CreateView):
obj
.
save
()
# Upload files if there are any
upload_data
(
self
.
request
.
FILES
.
getlist
(
'files'
),
obj
.
id
)
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
):
shutil
.
rmtree
(
job_dir
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment