Skip to content

Commit

Permalink
Remove get_temp_dir(), FILE_STORE_TEMP_DIR and FILE_UPLOAD_TEMP_DIR (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hackdna committed Jan 17, 2019
1 parent ed06413 commit dbb1848
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 23 deletions.
4 changes: 0 additions & 4 deletions refinery/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,8 @@ def get_setting(name, settings=local_settings, default=None):
FILE_STORE_DIR = get_setting('FILE_STORE_DIR', default='file_store')
# absolute path to the file store root dir
FILE_STORE_BASE_DIR = os.path.join(MEDIA_ROOT, FILE_STORE_DIR)
FILE_STORE_TEMP_DIR = os.path.join(FILE_STORE_BASE_DIR, 'temp')
# for SymlinkedFileSystemStorage (http://stackoverflow.com/q/4832626)
FILE_STORE_BASE_URL = urlparse.urljoin(MEDIA_URL, FILE_STORE_DIR) + '/'
# move uploaded files into file store quickly instead of copying
FILE_UPLOAD_TEMP_DIR = get_setting('FILE_UPLOAD_TEMP_DIR',
default=FILE_STORE_TEMP_DIR)
# always keep uploaded files on disk
FILE_UPLOAD_MAX_MEMORY_SIZE = get_setting('FILE_UPLOAD_MAX_MEMORY_SIZE',
default=0)
Expand Down
10 changes: 5 additions & 5 deletions refinery/data_set_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import shutil
import traceback
import urlparse
import tempfile

from django import forms
from django.conf import settings
Expand All @@ -34,8 +35,7 @@
from core.models import (DataSet, ExtendedGroup, get_user_import_dir)
from core.utils import get_absolute_url
from data_set_manager.isa_tab_parser import ParserException
from file_store.models import (FileStoreItem, generate_file_source_translator,
get_temp_dir)
from file_store.models import FileStoreItem, generate_file_source_translator
from file_store.tasks import FileImportTask, download_file
from file_store.utils import parse_s3_url

Expand Down Expand Up @@ -171,7 +171,7 @@ def clean(self):


def import_by_file(file_obj):
temp_file_path = os.path.join(get_temp_dir(), file_obj.name)
temp_file_path = os.path.join(tempfile.gettempdir(), file_obj.name)
try:
_handle_uploaded_file(file_obj, temp_file_path)
except IOError as exc:
Expand All @@ -187,7 +187,7 @@ def import_by_url(url):
# http://docs.celeryproject.org/en/latest/userguide/tasks.html#task-synchronous-subtasks
parsed_url = urlparse.urlparse(url)
file_name = parsed_url.path.split('/')[-1]
temp_file_path = os.path.join(get_temp_dir(), file_name)
temp_file_path = os.path.join(tempfile.gettempdir(), file_name)
try:
# TODO: refactor download_file to take file handle instead
# of path
Expand Down Expand Up @@ -250,7 +250,7 @@ def get(self, request, *args, **kwargs):
return response
u = urlparse.urlparse(url)
file_name = u.path.split('/')[-1]
temp_file_path = os.path.join(get_temp_dir(), file_name)
temp_file_path = os.path.join(tempfile.gettempdir(), file_name)
try:
# TODO: refactor download_file to take file handle instead of path
download_file(url, temp_file_path)
Expand Down
6 changes: 0 additions & 6 deletions refinery/file_store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

# create data storage directories
make_dir(settings.FILE_STORE_BASE_DIR)
make_dir(settings.FILE_STORE_TEMP_DIR)


def _map_source(source):
Expand Down Expand Up @@ -255,11 +254,6 @@ def transfer_data_file(self, file_store_item):
self.save()


def get_temp_dir():
"""Return the absolute path to the file store temp dir"""
return settings.FILE_STORE_TEMP_DIR


# post_delete is safer than pre_delete
@receiver(post_delete, sender=FileStoreItem)
def _delete_datafile(sender, instance, **kwargs):
Expand Down
7 changes: 4 additions & 3 deletions refinery/file_store/tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import division
import contextlib
import os
import tempfile
import threading
import urllib2
import urlparse
Expand All @@ -11,7 +12,7 @@
import celery
import requests

from .models import FileStoreItem, get_temp_dir
from .models import FileStoreItem
from .utils import (S3MediaStorage, SymlinkedFileSystemStorage,
copy_file_object, copy_s3_object, delete_file,
delete_s3_object, download_s3_object, get_file_size,
Expand Down Expand Up @@ -97,7 +98,7 @@ def import_path_to_path(self, source_path, symlink=True):
logger.debug("Transferring from '%s' to '%s'",
source_path, file_store_path)
if source_path.startswith((settings.REFINERY_DATA_IMPORT_DIR,
get_temp_dir())):
tempfile.gettempdir())):
move_file(source_path, file_store_path)
else:
if symlink:
Expand Down Expand Up @@ -140,7 +141,7 @@ def import_path_to_s3(self, source_path):
logger.info("Finished transferring from '%s' to 's3://%s/%s'",
source_path, settings.MEDIA_BUCKET, file_store_name)

if source_path.startswith(get_temp_dir()):
if source_path.startswith(tempfile.gettempdir()):
delete_file(source_path)

return file_store_name
Expand Down
6 changes: 1 addition & 5 deletions refinery/file_store/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@

from .models import (FileExtension, FileStoreItem, FileType,
_get_extension_from_string, _get_file_extension,
_map_source, generate_file_source_translator,
get_temp_dir)
_map_source, generate_file_source_translator)


class FileStoreModuleTest(TestCase):

def test_get_temp_dir(self):
self.assertEqual(get_temp_dir(), settings.FILE_STORE_TEMP_DIR)

def test_get_extension_from_file(self):
self.assertEqual(_get_extension_from_string('test.fastq'), 'fastq')

Expand Down

0 comments on commit dbb1848

Please sign in to comment.