This pull request, meant to works towards solving #1:
adds a custom LinkOrFileSystemStorage, that subclasses FileSystemStorage and behaves exactly the same except when the object to save is a LinkableFile (also introduced in this pull request): if that is the case, it tries to create a symbolic link instead of copying, falling back to copying if it was not possible (due to the OS not supporting it, etc):
> storage = LinkOrFileSystemStorage(...)
> storage.save('x/symlink_file', LinkableFile(open('/x/srcfile')))
> storage.save('x/regular_file', File(open('/x/srcfile')))
'x/symlink_file' == symbolic link to /x/srcfile
'x/regular_file' == copy of /x/srcfile
modifies Book.book_file to use that storage instead of the default one.
add a -l--link flag to addepub that, if specified, uses the previous mechanisms to import the epub as a symbolic link instead of a copy.
As a bonus, it includes 4 sample epubs in the repository (2 from https://github.com/IDPF/epub3-samples, 2 custom-made invalid ones, as an initial step for #6) and includes some basic black-box tests for addepub.
Please note that the tests are rather raw at the moment, making some essential assertions on the generation of Books and the creation of files, and they involve the mock library in order to be able to simulate the django.test.utils.override_settings() decorator, which seems not to be working on custom storages (using the decorator caused the tests to write the epubs to the real MEDIA_ROOT, which was quite messy). The good thing is that by installing the mock library (pip install mock - I deliberately left it outside of requirements.txt, as it is a test dependency and not a real dependency), something like:
$ python manage.py test books
should take care of automatically testing both copy and link modes with the sample epubs.
This pull request, meant to works towards solving #1:
LinkOrFileSystemStorage
, that subclassesFileSystemStorage
and behaves exactly the same except when the object to save is aLinkableFile
(also introduced in this pull request): if that is the case, it tries to create a symbolic link instead of copying, falling back to copying if it was not possible (due to the OS not supporting it, etc):Book.book_file
to use that storage instead of the default one.-l
--link
flag toaddepub
that, if specified, uses the previous mechanisms to import the epub as a symbolic link instead of a copy.As a bonus, it includes 4 sample epubs in the repository (2 from https://github.com/IDPF/epub3-samples, 2 custom-made invalid ones, as an initial step for #6) and includes some basic black-box tests for
addepub
.Please note that the tests are rather raw at the moment, making some essential assertions on the generation of
Book
s and the creation of files, and they involve themock
library in order to be able to simulate thedjango.test.utils.override_settings()
decorator, which seems not to be working on custom storages (using the decorator caused the tests to write the epubs to the realMEDIA_ROOT
, which was quite messy). The good thing is that by installing the mock library (pip install mock
- I deliberately left it outside ofrequirements.txt
, as it is a test dependency and not a real dependency), something like:$ python manage.py test books
should take care of automatically testing both copy and link modes with the sample epubs.