Merge from trunk

This commit is contained in:
Charles Haley 2011-08-01 17:21:21 +01:00
commit eac84f0641
4 changed files with 19 additions and 4 deletions

View File

@ -1430,16 +1430,17 @@ class MOBIFile(object): # {{{
print (str(self.mobi_header).encode('utf-8'), file=f)
# }}}
def inspect_mobi(path_or_stream, prefix='decompiled'): # {{{
def inspect_mobi(path_or_stream, ddir=None): # {{{
stream = (path_or_stream if hasattr(path_or_stream, 'read') else
open(path_or_stream, 'rb'))
f = MOBIFile(stream)
ddir = prefix + '_' + os.path.splitext(os.path.basename(stream.name))[0]
if ddir is None:
ddir = 'decompiled_' + os.path.splitext(os.path.basename(stream.name))[0]
try:
shutil.rmtree(ddir)
except:
pass
os.mkdir(ddir)
os.makedirs(ddir)
with open(os.path.join(ddir, 'header.txt'), 'wb') as out:
f.print_header(f=out)

View File

@ -532,7 +532,7 @@ class MobiMLizer(object):
bstate.pbreak = True
if isblock:
para = bstate.para
if para is not None and para.text == u'\xa0':
if para is not None and para.text == u'\xa0' and len(para) < 1:
para.getparent().replace(para, etree.Element(XHTML('br')))
bstate.para = None
bstate.istate = None

View File

@ -50,6 +50,11 @@ class MOBIOutput(OutputFormatPlugin):
help=_('When adding the Table of Contents to the book, add it at the start of the '
'book instead of the end. Not recommended.')
),
OptionRecommendation(name='extract_to', recommended_value=None,
help=_('Extract the contents of the MOBI file to the'
' specified directory. If the directory already '
'exists, it will be deleted.')
),
OptionRecommendation(name='mobi_navpoints_only_deepest',
recommended_value=False,
help=_('When adding navpoints for the chapter-to-chapter'
@ -185,3 +190,8 @@ class MOBIOutput(OutputFormatPlugin):
write_page_breaks_after_item=write_page_breaks_after_item)
writer(oeb, output_path)
if opts.extract_to is not None:
from calibre.ebooks.mobi.debug import inspect_mobi
ddir = opts.extract_to
inspect_mobi(output_path, ddir=ddir)

View File

@ -67,11 +67,15 @@ def generate_template_language_help():
for func in all_builtin_functions:
class_name = func.__class__.__name__
if class_name == 'BuiltinMergeLists':
class_name = 'BuiltinListUnion'
func_sig = getattr(func, 'doc')
x = func_sig.find(' -- ')
if x < 0:
print 'No sig for ', class_name
continue
if func_sig.startswith('merge_lists('):
continue
func_sig = func_sig[:x]
func_cat = getattr(func, 'category')
funcs[func_cat][func_sig] = class_name