mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
KG updates
This commit is contained in:
commit
d728f4e671
@ -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
|
||||
|
||||
|
@ -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'])
|
||||
|
@ -122,7 +122,6 @@ 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
|
||||
@ -138,7 +137,6 @@ 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)
|
||||
data = img.export('jpg')
|
||||
scale -= 0.05
|
||||
|
@ -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)
|
||||
|
@ -5,7 +5,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
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,6 +30,15 @@ def remove_dir(x):
|
||||
def base_dir():
|
||||
global _base_dir
|
||||
if _base_dir is None:
|
||||
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)
|
||||
|
@ -6,11 +6,11 @@ __license__ = 'GPL v3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__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
|
||||
|
||||
|
@ -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))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user