Switch to using lit2oeb to explode LIT files.

This commit is contained in:
Kovid Goyal 2008-08-05 22:33:19 -07:00
parent f5bcc609b3
commit 4dff7ecf95
7 changed files with 7 additions and 53 deletions

View File

@ -10,7 +10,6 @@ import glob, sys, subprocess, tarfile, os, re, py_compile, shutil
HOME = '/home/kovid' HOME = '/home/kovid'
PYINSTALLER = os.path.expanduser('~/build/pyinstaller') PYINSTALLER = os.path.expanduser('~/build/pyinstaller')
CALIBREPREFIX = '___' CALIBREPREFIX = '___'
CLIT = '/usr/bin/clit'
PDFTOHTML = '/usr/bin/pdftohtml' PDFTOHTML = '/usr/bin/pdftohtml'
LIBUNRAR = '/usr/lib/libunrar.so' LIBUNRAR = '/usr/lib/libunrar.so'
QTDIR = '/usr/lib/qt4' QTDIR = '/usr/lib/qt4'
@ -117,7 +116,7 @@ for f in glob.glob(os.path.join(CALIBREPLUGINS, '*.so.*')):
binaries += [(os.path.basename(f), f, 'BINARY')] binaries += [(os.path.basename(f), f, 'BINARY')]
print 'Adding external programs...' print 'Adding external programs...'
binaries += [('clit', CLIT, 'BINARY'), ('pdftohtml', PDFTOHTML, 'BINARY'), binaries += [('pdftohtml', PDFTOHTML, 'BINARY'),
('libunrar.so', LIBUNRAR, 'BINARY')] ('libunrar.so', LIBUNRAR, 'BINARY')]
print 'Adding external libraries...' print 'Adding external libraries...'

View File

@ -244,12 +244,6 @@ _check_symlinks_prescript()
print print
print 'Adding clit'
os.link(os.path.expanduser('~/clit'), os.path.join(frameworks_dir, 'clit'))
print
print 'Adding unrtf'
os.link(os.path.expanduser('~/unrtf'), os.path.join(frameworks_dir, 'unrtf'))
print
print 'Adding pdftohtml' print 'Adding pdftohtml'
os.link(os.path.expanduser('~/pdftohtml'), os.path.join(frameworks_dir, 'pdftohtml')) os.link(os.path.expanduser('~/pdftohtml'), os.path.join(frameworks_dir, 'pdftohtml'))
print 'Adding plugins' print 'Adding plugins'

View File

@ -10,7 +10,6 @@ QT_DIR = 'C:\\Qt\\4.4.0'
DEVCON = 'C:\\devcon\\i386\\devcon.exe' DEVCON = 'C:\\devcon\\i386\\devcon.exe'
LIBUSB_DIR = 'C:\\libusb' LIBUSB_DIR = 'C:\\libusb'
LIBUNRAR = 'C:\\Program Files\\UnrarDLL\\unrar.dll' LIBUNRAR = 'C:\\Program Files\\UnrarDLL\\unrar.dll'
CLIT = 'C:\\clit\\clit.exe'
PDFTOHTML = 'C:\\pdftohtml\\pdftohtml.exe' PDFTOHTML = 'C:\\pdftohtml\\pdftohtml.exe'
IMAGEMAGICK_DIR = 'C:\\ImageMagick' IMAGEMAGICK_DIR = 'C:\\ImageMagick'
FONTCONFIG_DIR = 'C:\\fontconfig' FONTCONFIG_DIR = 'C:\\fontconfig'
@ -105,8 +104,6 @@ class BuildEXE(py2exe.build_exe.py2exe):
shutil.copyfile(DEVCON, os.path.join(tdir, os.path.basename(DEVCON))) shutil.copyfile(DEVCON, os.path.join(tdir, os.path.basename(DEVCON)))
print '\tAdding unrar' print '\tAdding unrar'
shutil.copyfile(LIBUNRAR, os.path.join(PY2EXE_DIR, os.path.basename(LIBUNRAR))) shutil.copyfile(LIBUNRAR, os.path.join(PY2EXE_DIR, os.path.basename(LIBUNRAR)))
print '\tAdding ConvertLIT'
shutil.copyfile(CLIT, os.path.join(PY2EXE_DIR, os.path.basename(CLIT)))
print '\tAdding pdftohtml' print '\tAdding pdftohtml'
shutil.copyfile(PDFTOHTML, os.path.join(PY2EXE_DIR, os.path.basename(PDFTOHTML))) shutil.copyfile(PDFTOHTML, os.path.join(PY2EXE_DIR, os.path.basename(PDFTOHTML)))
print '\tAdding ImageMagick' print '\tAdding ImageMagick'

View File

@ -98,7 +98,7 @@ CONFIG += x86 ppc
def build_extension(self, ext): def build_extension(self, ext):
self.inplace = True self.inplace = True # Causes extensions to be built in the source tree
if not isinstance(ext, PyQtExtension): if not isinstance(ext, PyQtExtension):
return _build_ext.build_extension(self, ext) return _build_ext.build_extension(self, ext)

View File

@ -3,19 +3,12 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import os, sys, shutil, glob, logging import os, sys, shutil, glob, logging
from tempfile import mkdtemp from tempfile import mkdtemp
from subprocess import Popen, PIPE
from calibre.ebooks.lrf import option_parser as lrf_option_parser from calibre.ebooks.lrf import option_parser as lrf_option_parser
from calibre.ebooks.lit.reader import LitReader from calibre.ebooks.lit.reader import LitReader
from calibre.ebooks import ConversionError from calibre.ebooks import ConversionError
from calibre.ebooks.lrf.html.convert_from import process_file as html_process_file from calibre.ebooks.lrf.html.convert_from import process_file as html_process_file
from calibre.ebooks.metadata.opf import OPFReader from calibre.ebooks.metadata.opf import OPFReader
from calibre import isosx, __appname__, setup_cli_handlers, islinux from calibre import __appname__, setup_cli_handlers
CLIT = 'clit'
if isosx and hasattr(sys, 'frameworks_dir'):
CLIT = os.path.join(getattr(sys, 'frameworks_dir'), CLIT)
if islinux and getattr(sys, 'frozen_path', False):
CLIT = os.path.join(getattr(sys, 'frozen_path'), 'clit')
def option_parser(): def option_parser():
parser = lrf_option_parser( parser = lrf_option_parser(
@ -24,11 +17,9 @@ _('''Usage: %prog [options] mybook.lit
%prog converts mybook.lit to mybook.lrf''') %prog converts mybook.lit to mybook.lrf''')
) )
parser.add_option('--lit2oeb', default=False, dest='lit2oeb', action='store_true',
help='Use the new lit2oeb to convert lit files instead of convertlit.')
return parser return parser
def generate_html2(pathtolit, logger): def generate_html(pathtolit, logger):
if not os.access(pathtolit, os.R_OK): if not os.access(pathtolit, os.R_OK):
raise ConversionError, 'Cannot read from ' + pathtolit raise ConversionError, 'Cannot read from ' + pathtolit
tdir = mkdtemp(prefix=__appname__+'_'+'lit2oeb_') tdir = mkdtemp(prefix=__appname__+'_'+'lit2oeb_')
@ -37,36 +28,13 @@ def generate_html2(pathtolit, logger):
lr.extract_content(tdir) lr.extract_content(tdir)
return tdir return tdir
def generate_html(pathtolit, logger):
if isinstance(pathtolit, unicode):
pathtolit = pathtolit.encode(sys.getfilesystemencoding())
if not os.access(pathtolit, os.R_OK):
raise ConversionError, 'Cannot read from ' + pathtolit
tdir = mkdtemp(prefix=__appname__+'_')
os.rmdir(tdir)
cmd = [CLIT, pathtolit, '%s'%(tdir+os.sep)]
logger.debug(repr(cmd))
p = Popen(cmd, stderr=PIPE, stdout=PIPE)
stdout = p.stdout.read()
err = p.stderr.read()
logger.info(p.stdout.read())
ret = p.wait()
if ret != 0:
if os.path.exists(tdir) and os.path.isdir(tdir):
shutil.rmtree(tdir)
if 'keys.txt' in unicode(err)+unicode(stdout):
raise ConversionError('This lit file is protected by DRM. You must first use the ConvertLIT program to remove the DRM. Doing so may be illegal, and so %s does not do this, nor does it provide instructions on how to do it.'%(__appname__,))
raise ConversionError, err
return tdir
def process_file(path, options, logger=None): def process_file(path, options, logger=None):
if logger is None: if logger is None:
level = logging.DEBUG if options.verbose else logging.INFO level = logging.DEBUG if options.verbose else logging.INFO
logger = logging.getLogger('lit2lrf') logger = logging.getLogger('lit2lrf')
setup_cli_handlers(logger, level) setup_cli_handlers(logger, level)
lit = os.path.abspath(os.path.expanduser(path)) lit = os.path.abspath(os.path.expanduser(path))
tdir = generate_html2(lit, logger) if getattr(options, 'lit2oeb', False) \ tdir = generate_html(lit, logger)
else generate_html(lit, logger)
try: try:
opf = glob.glob(os.path.join(tdir, '*.opf')) opf = glob.glob(os.path.join(tdir, '*.opf'))
if opf: if opf:

View File

@ -35,7 +35,6 @@ class Distribution(object):
('ImageMagick', '6.3.5', 'imagemagick', 'imagemagick', 'ImageMagick'), ('ImageMagick', '6.3.5', 'imagemagick', 'imagemagick', 'ImageMagick'),
('xdg-utils', '1.0.2', 'xdg-utils', 'xdg-utils', 'xdg-utils'), ('xdg-utils', '1.0.2', 'xdg-utils', 'xdg-utils', 'xdg-utils'),
('dbus-python', '0.82.2', 'dbus-python', 'python-dbus', 'dbus-python'), ('dbus-python', '0.82.2', 'dbus-python', 'python-dbus', 'dbus-python'),
('convertlit', '1.8', 'convertlit', None, None),
('lxml', '1.3.3', 'lxml', 'python-lxml', 'python-lxml'), ('lxml', '1.3.3', 'lxml', 'python-lxml', 'python-lxml'),
('help2man', '1.36.4', 'help2man', 'help2man', 'help2man'), ('help2man', '1.36.4', 'help2man', 'help2man', 'help2man'),
] ]
@ -49,10 +48,7 @@ class Distribution(object):
'fedora':'Fedora 8', 'debian':'Debian Sid', 'generic': 'Generic Unix'} 'fedora':'Fedora 8', 'debian':'Debian Sid', 'generic': 'Generic Unix'}
MANUAL_MAP = { MANUAL_MAP = {
'ubuntu' : '<li>You will have to install <a href="">convertlit</a> manually to be able to convert LIT files.</li>', 'fedora' : '''<li>You have to upgrade Qt to at least 4.4.0 and PyQt to at least 4.4.2</li>''',
'fedora' : '''<li>You have to upgrade Qt to at least 4.3.1 and PyQt to at least 4.3.1</li>'''\
'''<li>You will have to install <a href="">convertlit</a> manually to be able to convert LIT files.</li>''',
'debian' : '<li>Add the following to /etc/apt/sources.list<pre class="wiki">deb http://www.debian-multimedia.org sid main</pre>Then<pre class="wiki">apt-get install clit</pre></li>',
} }
def __init__(self, os): def __init__(self, os):

View File

@ -220,7 +220,7 @@ def stage_one():
os.mkdir('build') os.mkdir('build')
shutil.rmtree('docs') shutil.rmtree('docs')
os.mkdir('docs') os.mkdir('docs')
subprocess.call('python setup.py develop', shell=True) check_call('python setup.py build', shell=True)
check_call('sudo python setup.py develop', shell=True) check_call('sudo python setup.py develop', shell=True)
check_call('make', shell=True) check_call('make', shell=True)
tag_release() tag_release()