Skip to content

Commit

Permalink
BUG always make copy of external data (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
glemaitre authored Mar 13, 2020
1 parent 854994b commit 21ec4b1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
4 changes: 4 additions & 0 deletions doc/whats_new/v0.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Changelog
`ramp-database`
...............

- Bug: fix a bug which was always doing a symlink of the external data.
Instead, we now always copy the file.
:pr:`413` by :user:`Guillaume Lemaitre <glemaitre>`.

`ramp-engine`
.............

Expand Down
5 changes: 3 additions & 2 deletions ramp-database/ramp_database/model/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,8 @@ def __repr__(self):

@property
def is_editable(self):
"""bool: Whether the submission file is from an editable format."""
"""bool: Whether the submission file is from an editable format on the
frontend."""
return self.workflow_element.is_editable

@property
Expand Down Expand Up @@ -754,7 +755,7 @@ class SubmissionFileType(Model):
name : str
The name of the submission file type.
is_editable : bool
Whether or not this type of file is editable.
Whether or not this type of file is editable on the frontend.
max_size : int
The maximum size of this file type.
workflow_element_types : list of \
Expand Down
6 changes: 4 additions & 2 deletions ramp-database/ramp_database/model/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def file_type(self):

@property
def is_editable(self):
"""bool: Whether or not the submission file is an editable type."""
"""bool: Whether or not the submission file is an editable type on the
frontend."""
return self.type.is_editable

@property
Expand Down Expand Up @@ -180,7 +181,8 @@ def file_type(self):

@property
def is_editable(self):
"""bool: Whether or not the submission file is an editable type."""
"""bool: Whether or not the submission file is an editable type on the
frontend."""
return self.workflow_element_type.is_editable

@property
Expand Down
8 changes: 2 additions & 6 deletions ramp-database/ramp_database/tools/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,24 +181,20 @@ def add_submission(session, event_name, team_name, submission_name,
event.set_n_submissions()

def is_editable(filename, workflow):
"""Whether or not the file format is editable on the frontend."""
for element in workflow.elements:
if element.name in filename:
return element.is_editable
return True

# copy the submission file in the submission folder
# For files that are not editable, only create a symlink to avoid
# duplicating large datafiles
if os.path.exists(submission.path):
shutil.rmtree(submission.path)
os.makedirs(submission.path)
for filename in submission.f_names:
src = os.path.join(submission_path, filename)
dst = os.path.join(submission.path, filename)
if is_editable(filename, event.problem.workflow):
shutil.copy2(src=src, dst=dst)
else:
os.symlink(src, dst)
shutil.copy2(src=src, dst=dst)

# for remembering it in the sandbox view
event_team.last_submission_name = submission_name
Expand Down
7 changes: 1 addition & 6 deletions ramp-frontend/ramp_frontend/views/ramp.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,14 +888,9 @@ def view_model(submission_hash, f_name):
name=filename.split('.')[0], workflow=event.workflow).one()

# TODO: deal with different extensions of the same file
# For non-editable files, only create a symlink if the file
# does not already exist.
src = os.path.join(submission.path, filename)
dst = os.path.join(sandbox_submission.path, filename)
if workflow_element.is_editable:
shutil.copy2(src, dst) # copying also metadata
elif not os.path.exists(dst):
os.symlink(src, dst)
shutil.copy2(src, dst) # copying also metadata
logger.info('Copying {} to {}'.format(src, dst))

submission_file = SubmissionFile.query.filter_by(
Expand Down

0 comments on commit 21ec4b1

Please sign in to comment.