HTML2ZIP import plugin works again

This commit is contained in:
Kovid Goyal 2009-05-15 07:54:10 -07:00
parent c3ff54c319
commit 29c172b95e
4 changed files with 16 additions and 7 deletions

View File

@ -2,7 +2,7 @@ from __future__ import with_statement
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import textwrap, os import textwrap, os, glob
from calibre.customize import FileTypePlugin, MetadataReaderPlugin, MetadataWriterPlugin from calibre.customize import FileTypePlugin, MetadataReaderPlugin, MetadataWriterPlugin
from calibre.constants import __version__ from calibre.constants import __version__
@ -20,9 +20,20 @@ every time you add an HTML file to the library.\
on_import = True on_import = True
def run(self, htmlfile): def run(self, htmlfile):
of = self.temporary_file('_plugin_html2zip.zip') from calibre.ptempfile import TemporaryDirectory
from calibre.ebooks.html import gui_main as html2oeb from calibre.gui2.convert.gui_conversion import gui_convert
html2oeb(htmlfile, of) from calibre.customize.conversion import OptionRecommendation
from calibre.ebooks.epub import initialize_container
with TemporaryDirectory('_plugin_html2zip') as tdir:
gui_convert(htmlfile, tdir, [('debug_input', tdir,
OptionRecommendation.HIGH)])
of = self.temporary_file('_plugin_html2zip.zip')
opf = glob.glob(os.path.join(tdir, '*.opf'))[0]
epub = initialize_container(of.name, os.path.basename(opf))
epub.add_dir(tdir)
epub.close()
return of.name return of.name
class OPFMetadataReader(MetadataReaderPlugin): class OPFMetadataReader(MetadataReaderPlugin):

View File

@ -101,7 +101,6 @@ class ReadMetadata(Thread):
return return
for id in ids: for id in ids:
print 11111111, id
progress(id) progress(id)
for job in jobs: for job in jobs:

View File

@ -90,7 +90,7 @@ class Adder(QObject):
def add_formats(self, id, formats): def add_formats(self, id, formats):
for path in formats: for path in formats:
fmt = os.path.splitext(path)[-1].replace('.', '').upper() fmt = os.path.splitext(path)[-1].replace('.', '').upper()
self.db.add_format(id, fmt, open(path, 'rb'), index_is_id=True, self.db.add_format_with_hooks(id, fmt, path, index_is_id=True,
notify=False) notify=False)
def canceled(self): def canceled(self):

1
todo
View File

@ -5,4 +5,3 @@
* Replace single application stuff with Listener from multiprocessing * Replace single application stuff with Listener from multiprocessing
* Fix HTML-to-ZIP plugin