home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- from __future__ import with_statement
- __license__ = 'GPL v3'
- __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
- __docformat__ = 'restructuredtext en'
- import os
- from odf.odf2xhtml import ODF2XHTML
- from calibre import CurrentDir, walk
- from calibre.customize.conversion import InputFormatPlugin
-
- class Extract(ODF2XHTML):
-
- def extract_pictures(self, zf):
- if not os.path.exists('Pictures'):
- os.makedirs('Pictures')
-
- for name in zf.namelist():
- if name.startswith('Pictures'):
- data = zf.read(name)
-
- try:
- f = _[1]
- f.write(data)
- finally:
- pass
-
- continue
- open(name, 'wb').__exit__
-
-
-
- def __call__(self, stream, odir):
- ZipFile = ZipFile
- import calibre.utils.zipfile
- get_metadata = get_metadata
- import calibre.ebooks.metadata.meta
- OPFCreator = OPFCreator
- import calibre.ebooks.metadata.opf2
- if not os.path.exists(odir):
- os.makedirs(odir)
-
- CurrentDir(odir).__enter__()
-
- try:
- print 'Extracting ODT file...'
- html = self.odf2xhtml(stream)
- html = html.replace('img { width: 100%; height: 100%; }', '')
-
- try:
- f = _[1]
- f.write(html.encode('utf-8'))
- finally:
- pass
-
- zf = ZipFile(stream, 'r')
- self.extract_pictures(zf)
- stream.seek(0)
- mi = get_metadata(stream, 'odt')
- if not mi.authors:
- mi.authors = [
- _('Unknown')]
-
- opf = OPFCreator(os.path.abspath(os.getcwdu()), mi)
- []([ (os.path.abspath(f), None) for f in walk(os.getcwd()) ])
- opf.create_spine([
- os.path.abspath('index.xhtml')])
-
- try:
- f = _[3]
- opf.render(f)
- finally:
- pass
-
- return os.path.abspath('metadata.opf')
- finally:
- pass
-
-
-
-
- class ODTInput(InputFormatPlugin):
- name = 'ODT Input'
- author = 'Kovid Goyal'
- description = 'Convert ODT (OpenOffice) files to HTML'
- file_types = set([
- 'odt'])
-
- def convert(self, stream, options, file_ext, log, accelerators):
- return Extract()(stream, '.')
-
-
- def postprocess_book(self, oeb, opts, log):
- XPath = XPath
- XHTML = XHTML
- import calibre.ebooks.oeb.base
- path = XPath('//h:p/h:div')
- path2 = XPath('//h:div[@style]/h:img[@style]')
- for item in oeb.spine:
- root = item.data
- if not hasattr(root, 'xpath'):
- continue
-
- for div in path(root):
- div.getparent().tag = XHTML('div')
-
- for img in path2(root):
- div = img.getparent()
- if 'position:relative' in div.attrib['style'] and len(div) == 1 and 'img' in div[0].tag:
- del div.attrib['style']
- continue
-
-
-
-
-