PML2PMLZ input plugin.

This commit is contained in:
John Schember 2009-12-03 20:38:33 -05:00
parent 1e6651393e
commit d5d8202c2a

View File

@ -1,3 +1,4 @@
import os.path
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
@ -49,6 +50,41 @@ every time you add an HTML file to the library.\
'include: cp1252, latin1, iso-8859-1 and utf-8.') '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): class ComicMetadataReader(MetadataReaderPlugin):
name = 'Read comic metadata' 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.devices.iriver.driver import IRIVER_STORY
from calibre.ebooks.metadata.fetch import GoogleBooks, ISBNDB, Amazon from calibre.ebooks.metadata.fetch import GoogleBooks, ISBNDB, Amazon
plugins = [HTML2ZIP, GoogleBooks, ISBNDB, Amazon] plugins = [HTML2ZIP, PML2PMLZ, GoogleBooks, ISBNDB, Amazon]
plugins += [ plugins += [
ComicInput, ComicInput,
EPUBInput, EPUBInput,