X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/0c613164e94ea79fce559b2b1632691986a84f25..8658102277980ea8e8e53a953e7c2f5fedf8de16:/apps/catalogue/utils.py?ds=sidebyside diff --git a/apps/catalogue/utils.py b/apps/catalogue/utils.py index 369656e40..0134701a6 100644 --- a/apps/catalogue/utils.py +++ b/apps/catalogue/utils.py @@ -55,8 +55,8 @@ class ExistingFile(UploadedFile): pass -class BookImportDocProvider(DocProvider): - """Used for joined EPUB and PDF files.""" +class ORMDocProvider(DocProvider): + """Used for getting books' children.""" def __init__(self, book): self.book = book @@ -90,6 +90,7 @@ class LockFile(object): self.lock.close() +@task def create_zip(paths, zip_slug): """ Creates a zip in MEDIA_ROOT/zip directory containing files from path. @@ -108,9 +109,14 @@ def create_zip(paths, zip_slug): with LockFile(zip_path, zip_slug): if not path.exists(path.join(zip_path, zip_filename)): - with ZipFile(path.join(zip_path, zip_filename), 'w') as zipf: - for p in paths: - zipf.write(p, path.basename(p)) + zipf = ZipFile(path.join(zip_path, zip_filename), 'w') + try: + for arcname, p in paths: + if arcname is None: + arcname = path.basename(p) + zipf.write(p, arcname) + finally: + zipf.close() return 'zip/' + zip_filename @@ -125,8 +131,3 @@ def remove_zip(zip_slug): except OSError as oe: if oe.errno != ENOENT: raise oe - - -@task -def create_zip_task(*args): - return create_zip(*args)