file_store Package

admin Module

models Module

file_store module

  • Manages all data files
  • Downloads files from external repositories (by URL)
  • Manage the import cache/public data space

Requirements:

FILE_STORE_DIR setting - main file store directory * must be a subdirectory of MEDIA_ROOT * must be writeable by the Django server Example: FILE_STORE_DIR = ‘files’

class file_store.models.FileStoreCache

LRU file cache

class file_store.models.FileStoreItem(*args, **kwargs)

Bases: django.db.models.base.Model

Represents data files on disk.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception FileStoreItem.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

FileStoreItem.delete_datafile()

Delete datafile if it exists on disk.

Returns:bool – True if deletion succeeded, False otherwise.
FileStoreItem.filetype = None

type of the file

FileStoreItem.get_absolute_path()

Compute the absolute path to the data file.

Returns:str – the absolute path to the data file or None if the file

does not exist on disk.

FileStoreItem.get_file_extension()

Return extension of the file on disk or from the source.

Returns:str – file extension that begins with a period.
FileStoreItem.get_file_object()

Open data file.

Returns:file object – or None if failed to open data file.
FileStoreItem.get_file_size(report_symlinks=False)

Return the size of the file in bytes.

Parameters:report_symlinks (bool.) – report the size of symlinked files or not.
Returns:int – file size. Zero if the file is: - not local - a symlink and report_symlinks=False
FileStoreItem.get_filetype()

Retrieve the type of the datafile.

Returns:str – type of the datafile.
FileStoreItem.get_filetype_display(*moreargs, **morekwargs)
FileStoreItem.get_full_url()

Return the full URL (including hostname) for the datafile.

Returns:str – local URL or source if it’s a remote file
FileStoreItem.is_local()

Check if the datafile can be used as a file object.

Returns:bool – True if the datafile can be used as a file object, False otherwise.
FileStoreItem.is_symlinked()

Check if the data file is a symlink.

Returns:True if the datafile is a symlink, False if not.
FileStoreItem.objects = <file_store.models._FileStoreItemManager object at 0x7f298aedb1d0>
FileStoreItem.rename_datafile(name)

Change name of the data file. New name may not be the same as the requested name in case of conflict with an existing file.

Parameters:name (str.) – new data file name.
Returns:str – new name if renaming succeeded, None otherwise.
FileStoreItem.set_filetype(filetype='')

Assign the type of the datafile. Only existing types allowed as arguments.

Parameters:filetype (str.) – requested file type.
Returns:True if success, False if failure.
FileStoreItem.sharename = None

optional subdirectory inside the file store that contains the files of a

FileStoreItem.source = None

source URL or absolute file system path

Create a symlink to the file pointed by source. Does not check that the source is an absolute file system path.

Returns:bool – True if success, False if failure.
FileStoreItem.uuid = None

unique ID

class file_store.models.SymlinkedFileSystemStorage(location=None, base_url=None)

Bases: django.core.files.storage.FileSystemStorage

Custom file system storage class with support for symlinked files.

exists(name)
file_store.models.file_path(instance, filename)

Construct relative file system path for new file store files relative to FILE_STORE_BASE_DIR. Based on http://michaelandrews.typepad.com/the_technical_times/2009/10/creating-a-hashed-directory-structure.html

Parameters:
  • instance (FileStoreItem.) – FileStoreItem instance.
  • filename (str.) – requested filename.
Returns:

str – if success, None if failure.

file_store.models.get_extension_from_path(path)

Return file extension given its file system path.

Returns:str – File extension preceeded by a period.
file_store.models.get_file_extension(uuid)

Return file extension of the file specified by UUID.

Parameters:uuid (str.) – UUID of a FileStoreItem.
Returns:str – extension of the data file.
file_store.models.get_file_object(file_name)

Open file given its name.

Parameters:file_name (str.) – name of the file.
Returns:file object – or None if failed to open file.
file_store.models.get_file_size(uuid, report_symlinks=False)

Return size of the file specified by UUID.

Parameters:
  • uuid (UUID.) – UUID of a FileStoreItem.
  • report_symlinks – report the size of symlinked files or not.
Returns:

int – size of the file on disk.

file_store.models.get_temp_dir()

Return the absolute path to the file store temp dir.

Returns:str – absolute path to the file store temp dir.
file_store.models.is_local(uuid)

Check if this FileStoreItem can be used as a file object

Parameters:uuid (str.) – UUID of a FileStoreItem
Returns:bool – True if yes, False if no.
file_store.models.is_permanent(uuid)

Check if FileStoreItem instance is referenced in the cache.

Parameters:uuid (str.) – UUID of a FileStoreItem.

tasks Module

exception file_store.tasks.DownloadError(value)

Bases: exceptions.StandardError

Exception raised for download errors

tests Module

This file contains tests for file_store.models and file_store.tasks

class file_store.tests.FileStoreItemManagerTest(methodName='runTest')

Bases: django.test.testcases.SimpleTestCase

FileStoreItemManager methods test.

setUp()
test_empty_file_source_map_translation()

Test that empty map doesn’t affect creating new FileStoreItem instances.

test_file_source_map_translation()

Test translation from URL to file system path when creating a new instance.

class file_store.tests.FileStoreItemTest(methodName='runTest')

Bases: django.test.testcases.SimpleTestCase

FileStoreItem methods test.

setUp()
test_get_file_extension()

Check that the correct file extension is returned.

test_get_file_type()

Check that the correct file type is returned

test_get_full_url_remote_file()

Check if the source URL is returned for files that have not been imported

test_set_file_type_automatically()

Check that a file type is set automatically

test_set_unkown_file_type()

Check that an unknown file type is not set

test_set_valid_file_type()

Check that a valid file type is set correctly

class file_store.tests.FileStoreModuleTest(methodName='runTest')

Bases: django.test.testcases.SimpleTestCase

File store module functions test.

setUp()
test_file_path()

Check that the file store path contains share name and file name.

test_file_path_parens()

Check if the parentheses are replaced with underscores in the file name

test_get_file_object()
test_get_file_object_2(*args, **keywargs)

Decorator version of the test_get_file_obejct()

test_get_temp_dir()

Check that the file store temp dir is reported correctly.

views Module

Table Of Contents

Related Topics

This Page