From 3d94acb2713b4b4342bc6e0459f756d9448102a4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 21 Jul 2008 20:44:38 -0700 Subject: [PATCH] Add --lit2oeb option to lit2lrf --- src/calibre/ebooks/lrf/lit/convert_from.py | 17 +++++++++++++++-- src/calibre/library/database.py | 2 +- src/calibre/translations/__init__.py | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/lrf/lit/convert_from.py b/src/calibre/ebooks/lrf/lit/convert_from.py index 3d8a3f97b0..486a1e4cda 100644 --- a/src/calibre/ebooks/lrf/lit/convert_from.py +++ b/src/calibre/ebooks/lrf/lit/convert_from.py @@ -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: diff --git a/src/calibre/library/database.py b/src/calibre/library/database.py index d1f759e0f8..0a05f48dc9 100644 --- a/src/calibre/library/database.py +++ b/src/calibre/library/database.py @@ -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): diff --git a/src/calibre/translations/__init__.py b/src/calibre/translations/__init__.py index 01f546b42e..9aca9e9fca 100644 --- a/src/calibre/translations/__init__.py +++ b/src/calibre/translations/__init__.py @@ -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':