mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add --lit2oeb option to lit2lrf
This commit is contained in:
parent
4582b165d6
commit
3d94acb271
@ -5,6 +5,7 @@ import os, sys, shutil, glob, logging
|
||||
from tempfile import mkdtemp
|
||||
from subprocess import Popen, PIPE
|
||||
from calibre.ebooks.lrf import option_parser as lrf_option_parser
|
||||
from calibre.ebooks.lit.reader import LitReader
|
||||
from calibre.ebooks import ConversionError
|
||||
from calibre.ebooks.lrf.html.convert_from import process_file as html_process_file
|
||||
from calibre.ebooks.metadata.opf import OPFReader
|
||||
@ -17,12 +18,24 @@ if islinux and getattr(sys, 'frozen_path', False):
|
||||
CLIT = os.path.join(getattr(sys, 'frozen_path'), 'clit')
|
||||
|
||||
def option_parser():
|
||||
return lrf_option_parser(
|
||||
parser = lrf_option_parser(
|
||||
_('''Usage: %prog [options] mybook.lit
|
||||
|
||||
|
||||
%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
|
||||
|
||||
def generate_html2(pathtolit, logger):
|
||||
if not os.access(pathtolit, os.R_OK):
|
||||
raise ConversionError, 'Cannot read from ' + pathtolit
|
||||
tdir = mkdtemp(prefix=__appname__+'_')
|
||||
lr = LitReader(pathtolit)
|
||||
print 'Extracting LIT file to', tdir
|
||||
lr.extract_content(tdir)
|
||||
return tdir
|
||||
|
||||
def generate_html(pathtolit, logger):
|
||||
if not os.access(pathtolit, os.R_OK):
|
||||
@ -51,7 +64,7 @@ def process_file(path, options, logger=None):
|
||||
logger = logging.getLogger('lit2lrf')
|
||||
setup_cli_handlers(logger, level)
|
||||
lit = os.path.abspath(os.path.expanduser(path))
|
||||
tdir = generate_html(lit, logger)
|
||||
tdir = generate_html2(lit, logger) if options.lit2oeb else generate_html(lit, logger)
|
||||
try:
|
||||
opf = glob.glob(os.path.join(tdir, '*.opf'))
|
||||
if opf:
|
||||
|
@ -778,7 +778,7 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
isbn
|
||||
FROM books;
|
||||
''')
|
||||
conn.execute('pragma user_version=5')
|
||||
conn.execute('pragma user_version=12')
|
||||
conn.commit()
|
||||
|
||||
def __init__(self, dbpath, row_factory=False):
|
||||
|
@ -70,8 +70,22 @@ def import_from_launchpad(url):
|
||||
open(out, 'wb').write(tf.extractfile(next).read())
|
||||
next = tf.next()
|
||||
|
||||
check_for_critical_bugs()
|
||||
return 0
|
||||
|
||||
def check_for_critical_bugs():
|
||||
if os.path.exists('.errors'):
|
||||
shutil.rmtree('.errors')
|
||||
pofilter = ('pofilter', '-i', '.', '-o', '.errors',
|
||||
'-t', 'accelerators', '-t', 'escapes', '-t', 'variables',
|
||||
'-t', 'xmltags')
|
||||
subprocess.check_call(pofilter)
|
||||
errs = os.listdir('.errors')
|
||||
if errs:
|
||||
print 'WARNING: Translation errors detected'
|
||||
print 'See the .errors directory and http://translate.sourceforge.net/wiki/toolkit/using_pofilter'
|
||||
|
||||
|
||||
def main(args=sys.argv):
|
||||
if len(args) > 1:
|
||||
if args[1] == 'pot':
|
||||
|
Loading…
x
Reference in New Issue
Block a user