home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- __license__ = 'GPL 3'
- __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>, 2009, John Schember <john@nachtimwald.com>'
- __docformat__ = 'restructuredtext en'
- import errno
- import os
- import sys
- import subprocess
- from functools import partial
- from calibre.ebooks import ConversionError, DRMError
- from calibre.ptempfile import PersistentTemporaryFile
- from calibre import isosx, iswindows, islinux, isfreebsd
- from calibre import CurrentDir
- PDFTOHTML = 'pdftohtml'
- popen = subprocess.Popen
- if isosx and hasattr(sys, 'frameworks_dir'):
- PDFTOHTML = os.path.join(getattr(sys, 'frameworks_dir'), PDFTOHTML)
-
- if iswindows and hasattr(sys, 'frozen'):
- PDFTOHTML = os.path.join(os.path.dirname(sys.executable), 'pdftohtml.exe')
- popen = partial(subprocess.Popen, creationflags = 8)
-
- if (islinux or isfreebsd) and getattr(sys, 'frozen_path', False):
- PDFTOHTML = os.path.join(getattr(sys, 'frozen_path'), 'pdftohtml')
-
-
- def pdftohtml(output_dir, pdf_path, no_images):
- if isinstance(pdf_path, unicode):
- pdf_path = pdf_path.encode(sys.getfilesystemencoding())
-
- if not os.access(pdf_path, os.R_OK):
- raise ConversionError('Cannot read from ' + pdf_path)
- os.access(pdf_path, os.R_OK)
- CurrentDir(output_dir).__enter__()
-
- try:
- index = os.path.join(os.getcwd(), 'index.html')
- pdf_path = os.path.abspath(pdf_path)
- cmd = [
- PDFTOHTML,
- '-enc',
- 'UTF-8',
- '-noframes',
- '-p',
- '-nomerge',
- '-nodrm',
- '-q',
- pdf_path,
- os.path.basename(index)]
- logf = PersistentTemporaryFile('pdftohtml_log')
-
- try:
- p = popen(cmd, stderr = logf._fd, stdout = logf._fd, stdin = subprocess.PIPE)
- except OSError:
- None if no_images else CurrentDir(output_dir)
- err = None if no_images else CurrentDir(output_dir)
- if err.errno == 2:
- raise ConversionError(_('Could not find pdftohtml, check it is in your PATH'))
- err.errno == 2
- raise
- except:
- None if no_images else CurrentDir(output_dir)
-
- while True:
-
- try:
- ret = p.wait()
- continue
- except OSError:
- None if no_images else CurrentDir(output_dir)
- e = None if no_images else CurrentDir(output_dir)
- if e.errno == errno.EINTR:
- continue
- else:
- raise
- e.errno == errno.EINTR
-
-
- None if no_images else CurrentDir(output_dir)<EXCEPTION MATCH>OSError
- logf.flush()
- logf.close()
- out = open(logf.name, 'rb').read()
- if ret != 0:
- raise ConversionError(out)
- ret != 0
- print 'pdftohtml log:'
- print out
- if not os.path.exists(index) or os.stat(index).st_size < 100:
- raise DRMError()
- os.stat(index).st_size < 100
-
- try:
- i = _[1]
- raw = i.read()
- raw = "<!-- created by calibre's pdftohtml -->\n" + raw
- i.seek(0)
- i.truncate()
- i.write(raw)
- finally:
- pass
-
- finally:
- pass
-
-
-