Add a new Debug option that will allow you to debug the different stages of the conversion pipeline. Available when converting a single book at a time.

This commit is contained in:
Kovid Goyal 2009-08-27 13:23:09 -06:00
parent 548aaba5d4
commit 2533bc65e9
6 changed files with 3044 additions and 1 deletions

View File

@ -0,0 +1,61 @@
#!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from __future__ import with_statement
__license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import os
from PyQt4.Qt import SIGNAL
from calibre.gui2.convert.debug_ui import Ui_Form
from calibre.gui2.convert import Widget
from calibre.gui2 import error_dialog, choose_dir
class DebugWidget(Widget, Ui_Form):
TITLE = _('Debug')
ICON = ':/images/debug.svg'
HELP = _('Debug the conversion process.')
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'debug',
['debug_pipeline']
)
self.db, self.book_id = db, book_id
self.initialize_options(get_option, get_help, db, book_id)
self.connect(self.button_debug_dir, SIGNAL('clicked()'),
self.set_debug_dir)
self.connect(self.button_clear, SIGNAL('clicked()'),
self.clear_debug_dir)
def clear_debug_dir(self):
self.opt_debug_pipeline.setText('')
def set_debug_dir(self):
x = choose_dir(self, 'conversion debug dir', _('Choose debug folder'))
if x:
self.opt_debug_pipeline.setText(x)
def pre_commit_check(self):
try:
x = unicode(self.opt_debug_pipeline.text()).strip()
x = os.path.abspath(x)
if x:
if not os.path.exists(x):
os.makedirs(x)
test = os.path.join(x, 'test')
open(test, 'wb').close()
os.remove(test)
except:
import traceback
det_msg = traceback.format_exc()
error_dialog(self, _('Invalid debug directory'),
_('Failed to create debug directory')+': '+
unicode(self.opt_debug_pipeline.text()),
det_msg=det_msg, show=True)
return False
return True

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>436</width>
<height>382</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="label">
<property name="text">
<string>Choose a folder to put the debug output into. If you specify a folder, calibre will place a lot of debug output into it. This will be useful in understanding the conversion process and figuring out the correct values for conversion parameters like Table of Contents and Chapter Detection.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="opt_debug_pipeline">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="button_debug_dir">
<property name="toolTip">
<string>Choose debug folder</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/document_open.svg</normaloff>:/images/document_open.svg</iconset>
</property>
</widget>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QToolButton" name="button_clear">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/clear_left.svg</normaloff>:/images/clear_left.svg</iconset>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -19,6 +19,8 @@ from calibre.gui2.convert.look_and_feel import LookAndFeelWidget
from calibre.gui2.convert.page_setup import PageSetupWidget
from calibre.gui2.convert.structure_detection import StructureDetectionWidget
from calibre.gui2.convert.toc import TOCWidget
from calibre.gui2.convert.debug import DebugWidget
from calibre.ebooks.conversion.plumber import Plumber, supported_input_formats
from calibre.customize.ui import available_output_formats
@ -139,6 +141,7 @@ class Config(ResizableDialog, Ui_Dialog):
ps = widget_factory(PageSetupWidget)
sd = widget_factory(StructureDetectionWidget)
toc = widget_factory(TOCWidget)
debug = widget_factory(DebugWidget)
output_widget = None
name = self.plumber.output_plugin.name.lower().replace(' ', '_')
@ -173,6 +176,7 @@ class Config(ResizableDialog, Ui_Dialog):
widgets.append(input_widget)
if output_widget is not None:
widgets.append(output_widget)
widgets.append(debug)
for w in widgets:
self.stack.addWidget(w)
self.connect(w, SIGNAL('set_help(PyQt_PyObject)'),

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 124 KiB

View File

@ -126,6 +126,10 @@ def convert_bulk_ebook(parent, db, book_ids, out_format=None):
OptionRecommendation.HIGH))
temp_files.append(d.cover_file)
for x in list(lrecs):
if x[0] == 'debug_pipeline':
lrecs.remove(x)
desc = _('Convert book %d of %d (%s)') % (i + 1, total, repr(mi.title))
args = [in_file, out_file.name, lrecs]