|
5 | 5 | import shutil
|
6 | 6 | import tempfile
|
7 | 7 | import time
|
| 8 | +from zipfile import ZipFile, ZIP_DEFLATED |
8 | 9 |
|
9 | 10 | import jinja2
|
10 | 11 | import requests
|
@@ -264,8 +265,40 @@ def create_zip_archive(epub_name):
|
264 | 265 | os.remove(os.path.join(epub_name_with_path, '.zip'))
|
265 | 266 | except OSError:
|
266 | 267 | pass
|
267 |
| - shutil.make_archive(epub_name_with_path, 'zip', self.EPUB_DIR) |
268 |
| - return epub_name_with_path + '.zip' |
| 268 | + # perform zip operation |
| 269 | + # TODO cleanup chdir code |
| 270 | + # TODO refactor/simplify walk code |
| 271 | + # TODO compression - debug Stored for now |
| 272 | + save_cwd = os.getcwd() |
| 273 | + os.chdir(self.EPUB_DIR) |
| 274 | + archname = epub_name_with_path + '.zip' |
| 275 | + paths = ['.'] |
| 276 | + flist = None |
| 277 | + if os.path.exists(archname): |
| 278 | + os.unlink(archname) |
| 279 | + if not flist: |
| 280 | + flist = ['mimetype'] |
| 281 | + for path in paths: |
| 282 | + for root, dirs, files in os.walk(path): |
| 283 | + for fname in files: |
| 284 | + if fname == 'mimetype': |
| 285 | + continue |
| 286 | + fname = os.path.join(root, fname) |
| 287 | + flist.append(fname) |
| 288 | + os.chdir(save_cwd) |
| 289 | + arch = ZipFile(archname, 'w')#, ZIP_DEFLATED) # FIXME |
| 290 | + os.chdir(self.EPUB_DIR) |
| 291 | + for fname in flist: |
| 292 | + # . is bad for py24 under win, |
| 293 | + # py 2.5 generates more sane entries for: |
| 294 | + # './filename' and '.\\filename' |
| 295 | + print(fname) # FIXME DEBUG |
| 296 | + fname = os.path.normpath(fname) |
| 297 | + arch.write(fname) |
| 298 | + arch.close() |
| 299 | + os.chdir(save_cwd) |
| 300 | + |
| 301 | + return archname |
269 | 302 |
|
270 | 303 | def turn_zip_into_epub(zip_archive):
|
271 | 304 | epub_full_name = zip_archive.strip('.zip') + '.epub'
|
|
0 commit comments