This commit is contained in:
Kovid Goyal 2008-08-03 14:30:48 -07:00
parent 0c1f1c1c7b
commit 1c5ecad88f
4 changed files with 15 additions and 9 deletions

View File

@ -318,7 +318,7 @@ def extract(path, dir):
raise Exception('Unknown archive type') raise Exception('Unknown archive type')
extractor(path, dir) extractor(path, dir)
def get_proxies(self): def get_proxies():
proxies = {} proxies = {}
if iswindows: if iswindows:
try: try:

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python from __future__ import with_statement
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
@ -31,12 +31,13 @@ try:
MagickQuantizeImage, RGBColorspace, \ MagickQuantizeImage, RGBColorspace, \
MagickWriteImage, DestroyPixelWand, \ MagickWriteImage, DestroyPixelWand, \
DestroyMagickWand, CloneMagickWand, \ DestroyMagickWand, CloneMagickWand, \
MagickThumbnailImage, MagickCropImage, initialize, finalize MagickThumbnailImage, MagickCropImage, ImageMagick
_imagemagick_loaded = True _imagemagick_loaded = True
except: except:
_imagemagick_loaded = False _imagemagick_loaded = False
PROFILES = { PROFILES = {
# Name : (width, height) in pixels
'prs500':(584, 754), 'prs500':(584, 754),
} }
@ -205,8 +206,7 @@ def process_pages(pages, opts, update):
''' '''
if not _imagemagick_loaded: if not _imagemagick_loaded:
raise RuntimeError('Failed to load ImageMagick') raise RuntimeError('Failed to load ImageMagick')
initialize() with ImageMagick():
try:
tdir = PersistentTemporaryDirectory('_comic2lrf_pp') tdir = PersistentTemporaryDirectory('_comic2lrf_pp')
processed_pages = [PageProcessor(path, tdir, opts, i) for i, path in enumerate(pages)] processed_pages = [PageProcessor(path, tdir, opts, i) for i, path in enumerate(pages)]
tp = ThreadPool(detect_ncpus()) tp = ThreadPool(detect_ncpus())
@ -223,9 +223,7 @@ def process_pages(pages, opts, update):
else: else:
ans += pp ans += pp
return ans, failures, tdir return ans, failures, tdir
finally:
finalize()
def config(defaults=None): def config(defaults=None):
desc = _('Options to control the conversion of comics (CBR, CBZ) files into ebooks') desc = _('Options to control the conversion of comics (CBR, CBZ) files into ebooks')
if defaults is None: if defaults is None:

View File

@ -104,6 +104,14 @@ def finalize():
_magick.MagickWandTerminus() _magick.MagickWandTerminus()
_initialized = False _initialized = False
class ImageMagick(object):
def __enter__(self):
initialize()
def __exit__(self, *args):
finalize()
class MetricType(ctypes.c_int): pass class MetricType(ctypes.c_int): pass
UndefinedMetric = MetricType(0) UndefinedMetric = MetricType(0)

View File

@ -67,7 +67,7 @@ def run_recipe(opts, recipe_arg, parser, notification=None, handler=None):
if notification is None: if notification is None:
from calibre.utils.terminfo import TerminalController, ProgressBar from calibre.utils.terminfo import TerminalController, ProgressBar
term = TerminalController(sys.stdout) term = TerminalController(sys.stdout)
pb = ProgressBar(term, _('Fetching feeds...'), no_progress_bar=opts.progress_bar) pb = ProgressBar(term, _('Fetching feeds...'), no_progress_bar=not opts.progress_bar)
notification = pb.update notification = pb.update
recipe, is_profile = None, False recipe, is_profile = None, False