mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Integrate rtf2xml debug process to calibre
This commit is contained in:
parent
7ea92e2c67
commit
056f52c843
@ -77,7 +77,18 @@ class RTFInput(InputFormatPlugin):
|
|||||||
|
|
||||||
def generate_xml(self, stream):
|
def generate_xml(self, stream):
|
||||||
from calibre.ebooks.rtf2xml.ParseRtf import ParseRtf
|
from calibre.ebooks.rtf2xml.ParseRtf import ParseRtf
|
||||||
ofile = 'out.xml'
|
debug_dir = getattr(self.opts, 'debug_pipeline', None)
|
||||||
|
run_lev = 1
|
||||||
|
if debug_dir is not None:
|
||||||
|
try:
|
||||||
|
debug_dir = os.path.abspath(os.path.normpath(debug_dir + u'/rtfdebug/'))
|
||||||
|
os.makedirs(debug_dir)
|
||||||
|
run_lev = 6
|
||||||
|
except OSError, ( errno, strerror ):
|
||||||
|
print strerror
|
||||||
|
print errno
|
||||||
|
debug_dir = None
|
||||||
|
ofile = 'dataxml.xml'
|
||||||
parser = ParseRtf(
|
parser = ParseRtf(
|
||||||
in_file = stream,
|
in_file = stream,
|
||||||
out_file = ofile,
|
out_file = ofile,
|
||||||
@ -117,12 +128,13 @@ class RTFInput(InputFormatPlugin):
|
|||||||
empty_paragraphs = 1,
|
empty_paragraphs = 1,
|
||||||
|
|
||||||
#debug
|
#debug
|
||||||
deb_dir = "D:\\Mes eBooks\\Developpement\\debug\\rtfdebug",
|
deb_dir = debug_dir,
|
||||||
run_level = 3
|
run_level = run_lev,
|
||||||
)
|
)
|
||||||
parser.parse_rtf()
|
parser.parse_rtf()
|
||||||
ans = open('out.xml').read()
|
ans = open('dataxml.xml').read()
|
||||||
os.remove('out.xml')
|
if debug_dir is None:
|
||||||
|
os.remove('dataxml.xml')
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def extract_images(self, picts):
|
def extract_images(self, picts):
|
||||||
@ -213,7 +225,7 @@ class RTFInput(InputFormatPlugin):
|
|||||||
css += '\n'+'\n'.join(font_size_classes)
|
css += '\n'+'\n'.join(font_size_classes)
|
||||||
css += '\n' +'\n'.join(color_classes)
|
css += '\n' +'\n'.join(color_classes)
|
||||||
|
|
||||||
for cls, val in border_styles.items():
|
for cls, val in border_styles.iteritems():
|
||||||
css += '\n\n.%s {\n%s\n}'%(cls, val)
|
css += '\n\n.%s {\n%s\n}'%(cls, val)
|
||||||
|
|
||||||
with open('styles.css', 'ab') as f:
|
with open('styles.css', 'ab') as f:
|
||||||
@ -277,9 +289,6 @@ class RTFInput(InputFormatPlugin):
|
|||||||
raise ValueError(_('This RTF file has a feature calibre does not '
|
raise ValueError(_('This RTF file has a feature calibre does not '
|
||||||
'support. Convert it to HTML first and then try it.\n%s')%e)
|
'support. Convert it to HTML first and then try it.\n%s')%e)
|
||||||
|
|
||||||
with open('dataxml.xml', 'w') as dataxml:
|
|
||||||
dataxml.write(xml)
|
|
||||||
|
|
||||||
d = glob.glob(os.path.join('*_rtf_pict_dir', 'picts.rtf'))
|
d = glob.glob(os.path.join('*_rtf_pict_dir', 'picts.rtf'))
|
||||||
if d:
|
if d:
|
||||||
imap = {}
|
imap = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user