diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 02bc0b621f..7dfba3a899 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1,3 +1,4 @@ +import os.path __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal ' @@ -49,6 +50,41 @@ every time you add an HTML file to the library.\ 'include: cp1252, latin1, iso-8859-1 and utf-8.') +class PML2PMLZ(FileTypePlugin): + name = 'PML to ZIP' + author = 'John Schember' + description = textwrap.dedent(_('''\ +Create a PMLZ archive containging the PML file \ +and all images in the directory pmlname_img or images \ +file containing all linked files. This plugin is run \ +every time you add an PML file to the library.\ +''')) + version = numeric_version + file_types = set(['pml']) + supported_platforms = ['windows', 'osx', 'linux'] + on_import = True + + def run(self, pmlfile): + import zipfile + from calibre.ptempfile import PersistentTemporaryFile + + name = os.path.join(tdir, '_plugin_pml2pmlz.pmlz') + pmlz = zipfile.ZipFile(name, 'w') + pmlz.write(pmlfile) + + pml_img = os.path.basename(pmlfile)[0] + '_img' + img_dir = pml_img if os.path.exists(pml_img) else 'images' if os.path.exists(images) else '' + if img_dir: + for image in glob.glob(os.path.join(img_dir, '*.png')): + pmlz.write(image) + pmlz.close() + + return name + + def customization_help(self, gui=False): + return _('Character encoding for the input PML files. Should ways be: cp1252.') + + class ComicMetadataReader(MetadataReaderPlugin): name = 'Read comic metadata' @@ -387,7 +423,7 @@ from calibre.devices.nuut2.driver import NUUT2 from calibre.devices.iriver.driver import IRIVER_STORY from calibre.ebooks.metadata.fetch import GoogleBooks, ISBNDB, Amazon -plugins = [HTML2ZIP, GoogleBooks, ISBNDB, Amazon] +plugins = [HTML2ZIP, PML2PMLZ, GoogleBooks, ISBNDB, Amazon] plugins += [ ComicInput, EPUBInput,