diff --git a/src/calibre/ebooks/chm/reader.py b/src/calibre/ebooks/chm/reader.py index 6b2ef2d211..73587edfa4 100644 --- a/src/calibre/ebooks/chm/reader.py +++ b/src/calibre/ebooks/chm/reader.py @@ -15,7 +15,6 @@ from calibre.utils.chm.chmlib import ( chm_enumerate, ) -from calibre.utils.config import OptionParser from calibre.ebooks.metadata.toc import TOC from calibre.ebooks.chardet import xml_to_unicode @@ -37,41 +36,6 @@ def check_empty(s, rex = re.compile(r'\S')): return rex.search(s) is None -def option_parser(): - parser = OptionParser(usage=_('%prog [options] mybook.chm')) - parser.add_option('--output-dir', '-d', default='.', help=_('Output directory. Defaults to current directory'), dest='output') - parser.add_option('--verbose', default=False, action='store_true', dest='verbose') - parser.add_option("-t", "--title", action="store", type="string", \ - dest="title", help=_("Set the book title")) - parser.add_option('--title-sort', action='store', type='string', default=None, - dest='title_sort', help=_('Set sort key for the title')) - parser.add_option("-a", "--author", action="store", type="string", \ - dest="author", help=_("Set the author")) - parser.add_option('--author-sort', action='store', type='string', default=None, - dest='author_sort', help=_('Set sort key for the author')) - parser.add_option("-c", "--category", action="store", type="string", \ - dest="category", help=_("The category this book belongs" - " to. E.g.: History")) - parser.add_option("--thumbnail", action="store", type="string", \ - dest="thumbnail", help=_("Path to a graphic that will be" - " set as this files' thumbnail")) - parser.add_option("--comment", action="store", type="string", \ - dest="freetext", help=_("Path to a txt file containing a comment.")) - parser.add_option("--get-thumbnail", action="store_true", \ - dest="get_thumbnail", default=False, \ - help=_("Extract thumbnail from LRF file")) - parser.add_option('--publisher', default=None, help=_('Set the publisher')) - parser.add_option('--classification', default=None, help=_('Set the book classification')) - parser.add_option('--creator', default=None, help=_('Set the book creator')) - parser.add_option('--producer', default=None, help=_('Set the book producer')) - parser.add_option('--get-cover', action='store_true', default=False, - help=_('Extract cover from LRF file. Note that the LRF format has no defined cover, so we use some heuristics to guess the cover.')) - parser.add_option('--bookid', action='store', type='string', default=None, - dest='book_id', help=_('Set book ID')) - parser.add_option('--font-delta', action='store', type='int', default=0, - dest='font_delta', help=_('Set font delta')) - return parser - class CHMError(Exception): pass diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py index dadca610ae..5c2477c3dc 100644 --- a/src/calibre/ebooks/metadata/opf2.py +++ b/src/calibre/ebooks/metadata/opf2.py @@ -529,14 +529,6 @@ class OPF(object): # {{{ self.find_toc() self.read_user_metadata() - def get_all_user_metadata(self, make_copy): - ''' - return a dict containing all the custom field metadata associated with - the book. - ''' - self.read_user_metadata() - return self._user_metadata_ - def read_user_metadata(self): self._user_metadata_ = {} temp = Metadata('x', ['x']) diff --git a/src/calibre/ebooks/mobi/writer.py b/src/calibre/ebooks/mobi/writer.py index 5e4dca4a9e..9105890d44 100644 --- a/src/calibre/ebooks/mobi/writer.py +++ b/src/calibre/ebooks/mobi/writer.py @@ -122,15 +122,14 @@ def rescale_image(data, maxsizeb, dimen=None): img = Image() quality = 95 - if hasattr(img, 'set_compression_quality'): - img.load(data) - while len(data) >= maxsizeb and quality >= 10: - quality -= 5 - img.set_compression_quality(quality) - data = img.export('jpg') - if len(data) <= maxsizeb: - return data - orig_data = data + img.load(data) + while len(data) >= maxsizeb and quality >= 10: + quality -= 5 + img.set_compression_quality(quality) + data = img.export('jpg') + if len(data) <= maxsizeb: + return data + orig_data = data scale = 0.9 while len(data) >= maxsizeb and scale >= 0.05: @@ -138,8 +137,7 @@ def rescale_image(data, maxsizeb, dimen=None): img.load(orig_data) w, h = img.size img.size = (int(scale*w), int(scale*h)) - if hasattr(img, 'set_compression_quality'): - img.set_compression_quality(quality) + img.set_compression_quality(quality) data = img.export('jpg') scale -= 0.05 return data diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index f123dbac79..450ea77669 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -1254,6 +1254,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): ''' Set metadata for the book `id` from the `Metadata` object `mi` ''' + if hasattr(mi, 'to_book_metadata'): + # Handle code passing in a OPF object instead of a Metadata object + mi = mi.to_book_metadata() + def doit(func, *args, **kwargs): try: func(*args, **kwargs) diff --git a/src/calibre/ptempfile.py b/src/calibre/ptempfile.py index ca7343ee9b..16a1ef4ce4 100644 --- a/src/calibre/ptempfile.py +++ b/src/calibre/ptempfile.py @@ -5,7 +5,7 @@ __copyright__ = '2008, Kovid Goyal ' Provides platform independent temporary files that persist even after being closed. """ -import tempfile, os, atexit +import tempfile, os, atexit, binascii, cPickle from calibre import __version__, __appname__ @@ -30,9 +30,18 @@ def remove_dir(x): def base_dir(): global _base_dir if _base_dir is None: - _base_dir = tempfile.mkdtemp(prefix='%s_%s_tmp_'%(__appname__, - __version__)) - atexit.register(remove_dir, _base_dir) + td = os.environ.get('CALIBRE_WORKER_TEMP_DIR', None) + if td is not None: + try: + td = cPickle.loads(binascii.unhexlify(td)) + except: + td = None + if td and os.path.exists(td): + _base_dir = td + else: + _base_dir = tempfile.mkdtemp(prefix='%s_%s_tmp_'%(__appname__, + __version__)) + atexit.register(remove_dir, _base_dir) return _base_dir class PersistentTemporaryFile(object): diff --git a/src/calibre/utils/ipc/launch.py b/src/calibre/utils/ipc/launch.py index e13c9e0cb6..8d3628d69a 100644 --- a/src/calibre/utils/ipc/launch.py +++ b/src/calibre/utils/ipc/launch.py @@ -6,11 +6,11 @@ __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import subprocess, os, sys, time +import subprocess, os, sys, time, binascii, cPickle from calibre.constants import iswindows, isosx, isfrozen, isnewosx from calibre.utils.config import prefs -from calibre.ptempfile import PersistentTemporaryFile +from calibre.ptempfile import PersistentTemporaryFile, base_dir if iswindows: import win32process @@ -81,6 +81,8 @@ class Worker(object): def env(self): env = dict(os.environ) env['CALIBRE_WORKER'] = '1' + td = binascii.hexlify(cPickle.dumps(base_dir())) + env['CALIBRE_WORKER_TEMP_DIR'] = td env.update(self._env) return env diff --git a/src/calibre/utils/magick/draw.py b/src/calibre/utils/magick/draw.py index 88f488cb23..6808215554 100644 --- a/src/calibre/utils/magick/draw.py +++ b/src/calibre/utils/magick/draw.py @@ -42,7 +42,7 @@ def save_cover_data_to(data, path, bgcolor='#ffffff', resize_to=None, if resize_to is not None: img.size = (resize_to[0], resize_to[1]) changed = True - if not hasattr(img, 'has_transparent_pixels') or img.has_transparent_pixels(): + if img.has_transparent_pixels(): canvas = create_canvas(img.size[0], img.size[1], bgcolor) canvas.compose(img) img = canvas @@ -72,7 +72,7 @@ def thumbnail(data, width=120, height=120, bgcolor='#ffffff', fmt='jpg'): img.size = (nwidth, nheight) canvas = create_canvas(img.size[0], img.size[1], bgcolor) canvas.compose(img) - if fmt == 'jpg' and hasattr(canvas, 'set_compression_quality'): + if fmt == 'jpg': canvas.set_compression_quality(70) return (canvas.size[0], canvas.size[1], canvas.export(fmt))