mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dump mobi and docx easily with calibre-debug
You can now directly run calibre-debug file.mobi or calibre-debug file.docx to dump the contents of the file for debugging/inspection.
This commit is contained in:
parent
773b7d4127
commit
fc4f0f4379
@ -152,7 +152,8 @@ def add_simple_plugin(path_to_plugin):
|
||||
shutil.rmtree(tdir)
|
||||
|
||||
def print_basic_debug_info(out=None):
|
||||
if out is None: out = sys.stdout
|
||||
if out is None:
|
||||
out = sys.stdout
|
||||
out = functools.partial(prints, file=out)
|
||||
import platform
|
||||
from calibre.constants import (__appname__, get_version, isportable, isosx,
|
||||
@ -175,7 +176,7 @@ def print_basic_debug_info(out=None):
|
||||
|
||||
def run_debug_gui(logpath):
|
||||
import time
|
||||
time.sleep(3) # Give previous GUI time to shutdown fully and release locks
|
||||
time.sleep(3) # Give previous GUI time to shutdown fully and release locks
|
||||
from calibre.constants import __appname__
|
||||
prints(__appname__, _('Debug log'))
|
||||
print_basic_debug_info()
|
||||
@ -197,6 +198,12 @@ def run_script(path, args):
|
||||
g['__file__'] = ef
|
||||
execfile(ef, g)
|
||||
|
||||
def inspect_mobi(path):
|
||||
from calibre.ebooks.mobi.debug.main import inspect_mobi
|
||||
prints('Inspecting:', path)
|
||||
inspect_mobi(path)
|
||||
print
|
||||
|
||||
def main(args=sys.argv):
|
||||
from calibre.constants import debug
|
||||
debug()
|
||||
@ -231,7 +238,7 @@ def main(args=sys.argv):
|
||||
main()
|
||||
elif opts.command:
|
||||
sys.argv = args
|
||||
exec opts.command
|
||||
exec(opts.command)
|
||||
elif opts.debug_device_driver:
|
||||
debug_device_driver()
|
||||
elif opts.add_simple_plugin is not None:
|
||||
@ -246,11 +253,8 @@ def main(args=sys.argv):
|
||||
sql_dump = args[-1]
|
||||
reinit_db(opts.reinitialize_db, sql_dump=sql_dump)
|
||||
elif opts.inspect_mobi:
|
||||
from calibre.ebooks.mobi.debug.main import inspect_mobi
|
||||
for path in args[1:]:
|
||||
prints('Inspecting:', path)
|
||||
inspect_mobi(path)
|
||||
print
|
||||
elif opts.tweak_book:
|
||||
from calibre.ebooks.tweak import tweak
|
||||
tweak(opts.tweak_book)
|
||||
@ -274,6 +278,16 @@ def main(args=sys.argv):
|
||||
plugin.cli_main([plugin.name] + args[1:])
|
||||
elif len(args) >= 2 and args[1].rpartition('.')[-1] in {'py', 'recipe'}:
|
||||
run_script(args[1], args[2:])
|
||||
elif len(args) >= 2 and args[1].rpartition('.')[-1] in {'mobi', 'azw', 'azw3', 'docx'}:
|
||||
for path in args[1:]:
|
||||
ext = path.rpartition('.')[-1]
|
||||
if ext == 'docx':
|
||||
from calibre.ebooks.docx.dump import dump
|
||||
dump(path)
|
||||
elif ext in {'mobi', 'azw', 'azw3'}:
|
||||
inspect_mobi(path)
|
||||
else:
|
||||
print ('Cannot dump unknown filetype: %s' % path)
|
||||
else:
|
||||
from calibre import ipython
|
||||
ipython()
|
||||
@ -282,3 +296,4 @@ def main(args=sys.argv):
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
|
||||
|
@ -15,7 +15,7 @@ from calibre.utils.zipfile import ZipFile
|
||||
|
||||
def dump(path):
|
||||
dest = os.path.splitext(os.path.basename(path))[0]
|
||||
dest += '_extracted'
|
||||
dest += '-dumped'
|
||||
if os.path.exists(dest):
|
||||
shutil.rmtree(dest)
|
||||
with ZipFile(path) as zf:
|
||||
|
@ -542,7 +542,7 @@ class PostInstall:
|
||||
o_and_w('fetch-ebook-metadata', fem_op, [])
|
||||
o_and_w('calibre-smtp', smtp_op, [])
|
||||
o_and_w('calibre-server', serv_op, [])
|
||||
o_and_e('calibre-debug', debug_op, ['py', 'recipe'], file_map={
|
||||
o_and_e('calibre-debug', debug_op, ['py', 'recipe', 'mobi', 'azw', 'azw3', 'docx'], file_map={
|
||||
'--tweak-book':['epub', 'azw3', 'mobi'],
|
||||
'--subset-font':['ttf', 'otf'],
|
||||
'--exec-file':['py', 'recipe'],
|
||||
|
Loading…
x
Reference in New Issue
Block a user