- zf = ZipFile(os.path.join(path, archive), 'r')
- infile = zf.open(filename)
- outfile = open(filename, 'wb')
+ global format, compile_format, compiled_format
+ if a_format:
+ format = a_format
+ compile_format = True
+ _compile_format()
+ if compiled_format[-1] in ('\0', '\\', '/'):
+ raise ValueError('Bad format: "%s"' % compiled_format)
+ bdict = {}
+ bdict['author'] = book.authors[0].fullname
+ bdict['extension'] = book.extension.name
+ bdict['file'] = book.file
+ genre = book.genres[0]
+ bdict['gname'] = genre.name
+ bdict['gtitle'] = genre.title
+ bdict['language'] = book.language.name
+ bdict['ser_no'] = book.ser_no or 0
+ bdict['series'] = book.series
+ bdict['title'] = book.title
+ if '%(extension)s' not in compiled_format:
+ compiled_format += '.%(extension)s'
+ filename = compiled_format % bdict
+ full_path = os.path.join(dest_path, filename)
+ try:
+ os.makedirs(os.path.dirname(full_path))
+ except OSError:
+ pass # Already exists
+ zf = ZipFile(os.path.join(lib_path, book.archive), 'r')
+ infile = zf.open('%s.%s' % (book.file, book.extension.name))
+ outfile = open(full_path, 'wb')