Fix PML2PMLZ FileTypePlugin.

This commit is contained in:
John Schember 2009-12-04 18:38:20 -05:00
parent 7212ede7fb
commit 74d613eb37

View File

@ -54,10 +54,10 @@ class PML2PMLZ(FileTypePlugin):
name = 'PML to PMLZ' name = 'PML to PMLZ'
author = 'John Schember' author = 'John Schember'
description = textwrap.dedent(_('''\ description = textwrap.dedent(_('''\
Create a PMLZ archive containing the PML file \ Create a PMLZ archive containing the PML file \
and all images in the directory pmlname_img or images \ and all images in the directory pmlname_img or images \
file containing all linked files. This plugin is run \ file containing all linked files. This plugin is run \
every time you add an PML file to the library.\ every time you add an PML file to the library.\
''')) '''))
version = numeric_version version = numeric_version
file_types = set(['pml']) file_types = set(['pml'])
@ -66,25 +66,20 @@ class PML2PMLZ(FileTypePlugin):
def run(self, pmlfile): def run(self, pmlfile):
import zipfile import zipfile
from calibre.ptempfile import TemporaryDirectory
with TemporaryDirectory('_plugin_pml2pmlz') as tdir: of = self.temporary_file('_plugin_pml2pmlz.pmlz')
name = os.path.join(tdir, '_plugin_pml2pmlz.pmlz') pmlz = zipfile.ZipFile(of.name, 'w')
pmlz = zipfile.ZipFile(name, 'w') pmlz.write(pmlfile, os.path.basename(pmlfile))
pmlz.write(pmlfile)
pml_img = os.path.basename(pmlfile)[0] + '_img' pml_img = os.path.basename(pmlfile)[0] + '_img'
img_dir = pml_img if os.path.exists(pml_img) else 'images' if \ img_dir = pml_img if os.path.exists(pml_img) else 'images' if \
os.path.exists('images') else '' os.path.exists('images') else ''
if img_dir: if img_dir:
for image in glob.glob(os.path.join(img_dir, '*.png')): for image in glob.glob(os.path.join(img_dir, '*.png')):
pmlz.write(image) pmlz.write(image, os.path.join('images', (os.path.basename(image))))
pmlz.close() pmlz.close()
return name return of.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):