mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #2403 (Conversion of comics fails on OS X when run from CLI)
This commit is contained in:
parent
f371247347
commit
42b08c0022
@ -43,7 +43,7 @@ PARALLEL_FUNCS = {
|
|||||||
|
|
||||||
'lrfviewer' :
|
'lrfviewer' :
|
||||||
('calibre.gui2.lrf_renderer.main', 'main', {}, None),
|
('calibre.gui2.lrf_renderer.main', 'main', {}, None),
|
||||||
|
|
||||||
'ebook-viewer' :
|
'ebook-viewer' :
|
||||||
('calibre.gui2.viewer.main', 'main', {}, None),
|
('calibre.gui2.viewer.main', 'main', {}, None),
|
||||||
|
|
||||||
@ -52,28 +52,28 @@ PARALLEL_FUNCS = {
|
|||||||
|
|
||||||
'render_table' :
|
'render_table' :
|
||||||
('calibre.ebooks.lrf.html.table_as_image', 'do_render', {}, None),
|
('calibre.ebooks.lrf.html.table_as_image', 'do_render', {}, None),
|
||||||
|
|
||||||
'render_pages' :
|
'render_pages' :
|
||||||
('calibre.ebooks.lrf.comic.convert_from', 'render_pages', {}, 'notification'),
|
('calibre.ebooks.lrf.comic.convert_from', 'render_pages', {}, 'notification'),
|
||||||
|
|
||||||
'comic2lrf' :
|
'comic2lrf' :
|
||||||
('calibre.ebooks.lrf.comic.convert_from', 'do_convert', {}, 'notification'),
|
('calibre.ebooks.lrf.comic.convert_from', 'do_convert', {}, 'notification'),
|
||||||
|
|
||||||
'any2epub' :
|
'any2epub' :
|
||||||
('calibre.ebooks.epub.from_any', 'any2epub', {}, None),
|
('calibre.ebooks.epub.from_any', 'any2epub', {}, None),
|
||||||
|
|
||||||
'feeds2epub' :
|
'feeds2epub' :
|
||||||
('calibre.ebooks.epub.from_feeds', 'main', {}, 'notification'),
|
('calibre.ebooks.epub.from_feeds', 'main', {}, 'notification'),
|
||||||
|
|
||||||
'comic2epub' :
|
'comic2epub' :
|
||||||
('calibre.ebooks.epub.from_comic', 'convert', {}, 'notification'),
|
('calibre.ebooks.epub.from_comic', 'convert', {}, 'notification'),
|
||||||
|
|
||||||
'any2mobi' :
|
'any2mobi' :
|
||||||
('calibre.ebooks.mobi.from_any', 'any2mobi', {}, None),
|
('calibre.ebooks.mobi.from_any', 'any2mobi', {}, None),
|
||||||
|
|
||||||
'feeds2mobi' :
|
'feeds2mobi' :
|
||||||
('calibre.ebooks.mobi.from_feeds', 'main', {}, 'notification'),
|
('calibre.ebooks.mobi.from_feeds', 'main', {}, 'notification'),
|
||||||
|
|
||||||
'comic2mobi' :
|
'comic2mobi' :
|
||||||
('calibre.ebooks.mobi.from_comic', 'convert', {}, 'notification'),
|
('calibre.ebooks.mobi.from_comic', 'convert', {}, 'notification'),
|
||||||
}
|
}
|
||||||
@ -166,9 +166,11 @@ class WorkerMother(object):
|
|||||||
self.gui_executable = os.path.join(contents, 'MacOS',
|
self.gui_executable = os.path.join(contents, 'MacOS',
|
||||||
os.path.basename(sys.executable))
|
os.path.basename(sys.executable))
|
||||||
contents = os.path.join(contents, 'console.app', 'Contents')
|
contents = os.path.join(contents, 'console.app', 'Contents')
|
||||||
self.executable = os.path.join(contents, 'MacOS',
|
exe = os.path.basename(sys.executable)
|
||||||
os.path.basename(sys.executable))
|
if 'python' not in exe:
|
||||||
|
exe = 'python'
|
||||||
|
self.executable = os.path.join(contents, 'MacOS', exe)
|
||||||
|
|
||||||
resources = os.path.join(contents, 'Resources')
|
resources = os.path.join(contents, 'Resources')
|
||||||
fd = os.path.join(contents, 'Frameworks')
|
fd = os.path.join(contents, 'Frameworks')
|
||||||
sp = os.path.join(resources, 'lib', 'python'+sys.version[:3], 'site-packages.zip')
|
sp = os.path.join(resources, 'lib', 'python'+sys.version[:3], 'site-packages.zip')
|
||||||
@ -192,7 +194,7 @@ class WorkerMother(object):
|
|||||||
for func in ('spawn_free_spirit', 'spawn_worker'):
|
for func in ('spawn_free_spirit', 'spawn_worker'):
|
||||||
setattr(self, func, getattr(self, func+'_'+ext))
|
setattr(self, func, getattr(self, func+'_'+ext))
|
||||||
|
|
||||||
|
|
||||||
def cleanup_child_windows(self, child, name=None, fd=None):
|
def cleanup_child_windows(self, child, name=None, fd=None):
|
||||||
try:
|
try:
|
||||||
child.kill()
|
child.kill()
|
||||||
@ -503,9 +505,9 @@ class Overseer(object):
|
|||||||
self.job.update_status(percent, msg)
|
self.job.update_status(percent, msg)
|
||||||
elif word == 'ERROR':
|
elif word == 'ERROR':
|
||||||
self.write('OK')
|
self.write('OK')
|
||||||
exception, traceback = cPickle.loads(msg)
|
exception, tb = cPickle.loads(msg)
|
||||||
self.job.output(u'%s\n%s'%(exception, traceback))
|
self.job.output(u'%s\n%s'%(exception, tb))
|
||||||
self.job.exception, self.job.traceback = exception, traceback
|
self.job.exception, self.job.traceback = exception, tb
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
self.terminate()
|
self.terminate()
|
||||||
@ -520,8 +522,8 @@ class JobKilled(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class Job(object):
|
class Job(object):
|
||||||
|
|
||||||
def __init__(self, job_done, job_manager=None,
|
def __init__(self, job_done, job_manager=None,
|
||||||
args=[], kwargs={}, description=None):
|
args=[], kwargs={}, description=None):
|
||||||
self.args = args
|
self.args = args
|
||||||
self.kwargs = kwargs
|
self.kwargs = kwargs
|
||||||
@ -534,9 +536,9 @@ class Job(object):
|
|||||||
self.description = description
|
self.description = description
|
||||||
self.start_time = None
|
self.start_time = None
|
||||||
self.running_time = None
|
self.running_time = None
|
||||||
|
|
||||||
self.result = self.exception = self.traceback = self.log = None
|
self.result = self.exception = self.traceback = self.log = None
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def __cmp__(self, other):
|
||||||
sstatus, ostatus = self.status(), other.status()
|
sstatus, ostatus = self.status(), other.status()
|
||||||
if sstatus == ostatus or (self.has_run and other.has_run):
|
if sstatus == ostatus or (self.has_run and other.has_run):
|
||||||
@ -551,8 +553,8 @@ class Job(object):
|
|||||||
return -1
|
return -1
|
||||||
if ostatus == 'WAITING':
|
if ostatus == 'WAITING':
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
def job_done(self):
|
def job_done(self):
|
||||||
self.is_running, self.has_run = False, True
|
self.is_running, self.has_run = False, True
|
||||||
self.running_time = (time.time() - self.start_time) if \
|
self.running_time = (time.time() - self.start_time) if \
|
||||||
@ -560,14 +562,14 @@ class Job(object):
|
|||||||
if self.job_manager is not None:
|
if self.job_manager is not None:
|
||||||
self.job_manager.job_done(self)
|
self.job_manager.job_done(self)
|
||||||
self._job_done(self)
|
self._job_done(self)
|
||||||
|
|
||||||
def start_work(self):
|
def start_work(self):
|
||||||
self.is_running = True
|
self.is_running = True
|
||||||
self.has_run = False
|
self.has_run = False
|
||||||
self.start_time = time.time()
|
self.start_time = time.time()
|
||||||
if self.job_manager is not None:
|
if self.job_manager is not None:
|
||||||
self.job_manager.start_work(self)
|
self.job_manager.start_work(self)
|
||||||
|
|
||||||
def update_status(self, percent, msg=None):
|
def update_status(self, percent, msg=None):
|
||||||
self.percent = percent
|
self.percent = percent
|
||||||
self.msg = msg
|
self.msg = msg
|
||||||
@ -576,7 +578,7 @@ class Job(object):
|
|||||||
self.job_manager.status_update(self)
|
self.job_manager.status_update(self)
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
def status(self):
|
def status(self):
|
||||||
if self.is_running:
|
if self.is_running:
|
||||||
return 'WORKING'
|
return 'WORKING'
|
||||||
@ -586,7 +588,7 @@ class Job(object):
|
|||||||
if self.exception is None:
|
if self.exception is None:
|
||||||
return 'DONE'
|
return 'DONE'
|
||||||
return 'ERROR'
|
return 'ERROR'
|
||||||
|
|
||||||
def console_text(self):
|
def console_text(self):
|
||||||
ans = [u'Job: ']
|
ans = [u'Job: ']
|
||||||
if self.description:
|
if self.description:
|
||||||
@ -604,13 +606,13 @@ class Job(object):
|
|||||||
if self.traceback:
|
if self.traceback:
|
||||||
ans.append(u'**Traceback**:')
|
ans.append(u'**Traceback**:')
|
||||||
ans.extend(self.traceback.split('\n'))
|
ans.extend(self.traceback.split('\n'))
|
||||||
|
|
||||||
if self.log:
|
if self.log:
|
||||||
if isinstance(self.log, str):
|
if isinstance(self.log, str):
|
||||||
self.log = unicode(self.log, 'utf-8', 'replace')
|
self.log = unicode(self.log, 'utf-8', 'replace')
|
||||||
ans.append(self.log)
|
ans.append(self.log)
|
||||||
return (u'\n'.join(ans)).encode('utf-8')
|
return (u'\n'.join(ans)).encode('utf-8')
|
||||||
|
|
||||||
def gui_text(self):
|
def gui_text(self):
|
||||||
ans = [u'Job: ']
|
ans = [u'Job: ']
|
||||||
if self.description:
|
if self.description:
|
||||||
@ -635,19 +637,19 @@ class Job(object):
|
|||||||
if isinstance(self.log, str):
|
if isinstance(self.log, str):
|
||||||
self.log = unicode(self.log, 'utf-8', 'replace')
|
self.log = unicode(self.log, 'utf-8', 'replace')
|
||||||
ans.extend(self.log.split('\n'))
|
ans.extend(self.log.split('\n'))
|
||||||
|
|
||||||
ans = [x.decode(preferred_encoding, 'replace') if isinstance(x, str) else x for x in ans]
|
ans = [x.decode(preferred_encoding, 'replace') if isinstance(x, str) else x for x in ans]
|
||||||
|
|
||||||
return u'<br>'.join(ans)
|
return u'<br>'.join(ans)
|
||||||
|
|
||||||
|
|
||||||
class ParallelJob(Job):
|
class ParallelJob(Job):
|
||||||
|
|
||||||
def __init__(self, func, *args, **kwargs):
|
def __init__(self, func, *args, **kwargs):
|
||||||
Job.__init__(self, *args, **kwargs)
|
Job.__init__(self, *args, **kwargs)
|
||||||
self.func = func
|
self.func = func
|
||||||
self.done = self.job_done
|
self.done = self.job_done
|
||||||
|
|
||||||
def output(self, msg):
|
def output(self, msg):
|
||||||
if not self.log:
|
if not self.log:
|
||||||
self.log = u''
|
self.log = u''
|
||||||
@ -657,7 +659,7 @@ class ParallelJob(Job):
|
|||||||
self.log += msg
|
self.log += msg
|
||||||
if self.job_manager is not None:
|
if self.job_manager is not None:
|
||||||
self.job_manager.output(self)
|
self.job_manager.output(self)
|
||||||
|
|
||||||
|
|
||||||
def remove_ipc_socket(path):
|
def remove_ipc_socket(path):
|
||||||
os = __import__('os')
|
os = __import__('os')
|
||||||
@ -696,7 +698,7 @@ class Server(Thread):
|
|||||||
self.result_lock = RLock()
|
self.result_lock = RLock()
|
||||||
self.pool_lock = RLock()
|
self.pool_lock = RLock()
|
||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
def split(self, tasks):
|
def split(self, tasks):
|
||||||
'''
|
'''
|
||||||
Split a list into a list of sub lists, with the number of sub lists being
|
Split a list into a list of sub lists, with the number of sub lists being
|
||||||
@ -714,7 +716,7 @@ class Server(Thread):
|
|||||||
ans.append(section)
|
ans.append(section)
|
||||||
pos += delta
|
pos += delta
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
try:
|
try:
|
||||||
@ -727,7 +729,7 @@ class Server(Thread):
|
|||||||
self.jobs.append(job)
|
self.jobs.append(job)
|
||||||
if job.job_manager is not None:
|
if job.job_manager is not None:
|
||||||
job.job_manager.add_job(job)
|
job.job_manager.add_job(job)
|
||||||
|
|
||||||
def poll(self):
|
def poll(self):
|
||||||
'''
|
'''
|
||||||
Return True if the server has either working or queued jobs
|
Return True if the server has either working or queued jobs
|
||||||
@ -735,14 +737,14 @@ class Server(Thread):
|
|||||||
with self.job_lock:
|
with self.job_lock:
|
||||||
with self.working_lock:
|
with self.working_lock:
|
||||||
return len(self.jobs) + len(self.working) > 0
|
return len(self.jobs) + len(self.working) > 0
|
||||||
|
|
||||||
def wait(self, sleep=1):
|
def wait(self, sleep=1):
|
||||||
'''
|
'''
|
||||||
Wait until job queue is empty
|
Wait until job queue is empty
|
||||||
'''
|
'''
|
||||||
while self.poll():
|
while self.poll():
|
||||||
time.sleep(sleep)
|
time.sleep(sleep)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
while True:
|
||||||
job = None
|
job = None
|
||||||
@ -929,7 +931,7 @@ def work(client_socket, func, args, kwdargs):
|
|||||||
func(*args, **kwargs)
|
func(*args, **kwargs)
|
||||||
except (Exception, SystemExit):
|
except (Exception, SystemExit):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
time.sleep(5) # Give any in progress BufferedSend time to complete
|
time.sleep(5) # Give any in progress BufferedSend time to complete
|
||||||
|
|
||||||
|
|
||||||
@ -942,7 +944,7 @@ def worker(host, port):
|
|||||||
if msg != 'OK':
|
if msg != 'OK':
|
||||||
return 1
|
return 1
|
||||||
write(client_socket, 'WAITING')
|
write(client_socket, 'WAITING')
|
||||||
|
|
||||||
sys.stdout = BufferedSender(client_socket)
|
sys.stdout = BufferedSender(client_socket)
|
||||||
sys.stderr = sys.stdout
|
sys.stderr = sys.stdout
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user