Errorcol feature(plugin). On update/overwrite fail, save error msg to cust col.

Remove debug output from configurable.
This commit is contained in:
Jim Miller
2012-07-01 13:16:03 -05:00
parent 57dc8eb12e
commit aee9c7010c
3 changed files with 87 additions and 8 deletions
+32 -4
View File
@@ -61,6 +61,7 @@ all_prefs.defaults['gcnewonly'] = False
all_prefs.defaults['gc_site_settings'] = {}
all_prefs.defaults['allow_gc_from_ini'] = True
all_prefs.defaults['errorcol'] = ''
all_prefs.defaults['custom_cols'] = {}
# The list of settings to copy from all_prefs or the previous library
@@ -164,7 +165,7 @@ class ConfigWidget(QWidget):
if 'Generate Cover' not in plugin_action.gui.iactions:
self.generatecover_tab.setEnabled(False)
self.columns_tab = ColumnsTab(self, plugin_action)
self.columns_tab = CustomColumnsTab(self, plugin_action)
tab_widget.addTab(self.columns_tab, 'Custom Columns')
self.other_tab = OtherTab(self, plugin_action)
@@ -218,6 +219,11 @@ class ConfigWidget(QWidget):
prefs['allow_gc_from_ini'] = self.generatecover_tab.allow_gc_from_ini.isChecked()
# Custom Columns tab
# error column
prefs['errorcol'] = unicode(self.columns_tab.errorcol.itemData(self.columns_tab.errorcol.currentIndex()).toString())
# cust cols
colsmap = {}
for (col,combo) in self.columns_tab.custcol_dropdowns.iteritems():
val = unicode(combo.itemData(combo.currentIndex()).toString())
@@ -661,13 +667,15 @@ titleLabels = {
'version':'FFDL Version'
}
class ColumnsTab(QWidget):
class CustomColumnsTab(QWidget):
def __init__(self, parent_dialog, plugin_action):
self.parent_dialog = parent_dialog
self.plugin_action = plugin_action
QWidget.__init__(self)
custom_columns = self.plugin_action.gui.library_view.model().custom_columns
self.l = QVBoxLayout()
self.setLayout(self.l)
@@ -678,8 +686,6 @@ class ColumnsTab(QWidget):
self.custcol_dropdowns = {}
custom_columns = self.plugin_action.gui.library_view.model().custom_columns
for key, column in custom_columns.iteritems():
if column['datatype'] in permitted_values:
@@ -707,4 +713,26 @@ class ColumnsTab(QWidget):
self.l.insertStretch(-1)
self.l.addSpacing(5)
label = QLabel("Special column:")
label.setWordWrap(True)
self.l.addWidget(label)
self.l.addSpacing(5)
horz = QHBoxLayout()
label = QLabel("Update/Overwrite Error Column:")
tooltip="When an update or overwrite of an existing story fails, record the reason in this column.\n(Text and Long Text columns only.)"
label.setToolTip(tooltip)
horz.addWidget(label)
self.errorcol = QComboBox(self)
self.errorcol.setToolTip(tooltip)
self.errorcol.addItem('',QVariant('none'))
for key, column in custom_columns.iteritems():
if column['datatype'] in ('text','comments'):
self.errorcol.addItem(column['name'],QVariant(key))
self.errorcol.setCurrentIndex(self.errorcol.findData(QVariant(prefs['errorcol'])))
horz.addWidget(self.errorcol)
self.l.addLayout(horz)
#print("prefs['custom_cols'] %s"%prefs['custom_cols'])
+54 -3
View File
@@ -653,6 +653,23 @@ make_firstimage_cover:true
label_text='None of the URLs/stories given can be/need to be downloaded.'
)
d.exec_()
custom_columns = self.gui.library_view.model().custom_columns
if prefs['errorcol'] != '' and prefs['errorcol'] in custom_columns:
label = custom_columns[prefs['errorcol']]['label']
print("errorcol label:%s"%label)
## if error column and all bad.
self.previous = self.gui.library_view.currentIndex()
LoopProgressDialog(self.gui,
book_list,
partial(self._update_bad_book, label=label, options=options, db=self.gui.current_db),
partial(self._update_books_completed, options=options, showlist=False),
init_label="Updating calibre for BAD FanFiction stories...",
win_title="Update calibre for BAD FanFiction stories",
status_prefix="Updated")
return
func = 'arbitrary_n'
@@ -682,7 +699,16 @@ make_firstimage_cover:true
(options['updatemeta'] and book['good']):
self._update_metadata(db, book['calibre_id'], book, mi, options)
def _update_books_completed(self, book_list, options={}):
def _update_bad_book(self,book,db=None,label='errorcol',
options={'fileform':'epub',
'collision':ADDNEW,
'updatemeta':True,
'updateepubcover':True},):
print("add/update bad %s %s %s"%(book['title'],book['url'],book['comment']))
db.set_custom(book['calibre_id'], book['comment'], label=label, commit=True)
def _update_books_completed(self, book_list, options={}, showlist=True):
add_list = filter(lambda x : x['good'] and x['added'], book_list)
add_ids = [ x['calibre_id'] for x in add_list ]
@@ -706,7 +732,7 @@ make_firstimage_cover:true
self.gui.status_bar.show_message(_('Finished Adding/Updating %d books.'%(len(update_list) + len(add_list))), 3000)
if len(update_list) + len(add_list) != len(book_list):
if showlist and (len(update_list) + len(add_list) != len(book_list)):
d = DisplayStoryListDialog(self.gui,
'Updates completed, final status',
prefs,
@@ -750,6 +776,26 @@ make_firstimage_cover:true
win_title="Update calibre for FanFiction stories",
status_prefix="Updated")
bad_list = filter(lambda x : x['calibre_id'] and not x['good'], book_list)
total_bad = len(bad_list)
self.gui.status_bar.show_message(_('Adding/Updating %s BAD books.'%total_bad))
if total_bad > 0:
custom_columns = self.gui.library_view.model().custom_columns
if prefs['errorcol'] != '' and prefs['errorcol'] in custom_columns:
label = custom_columns[prefs['errorcol']]['label']
print("errorcol label:%s"%label)
## if error column and all bad.
LoopProgressDialog(self.gui,
bad_list,
partial(self._update_bad_book, label=label, options=options, db=self.gui.current_db),
partial(self._update_books_completed, options=options, showlist=False),
init_label="Updating calibre for BAD FanFiction stories...",
win_title="Update calibre for BAD FanFiction stories",
status_prefix="Updated")
def _add_or_update_book(self,book,options,prefs,mi=None):
db = self.gui.current_db
@@ -888,7 +934,12 @@ make_firstimage_cover:true
print("Running Generate Cover with settings %s."%setting_name)
realmi = db.get_metadata(book_id, index_is_id=True)
gc_plugin.generate_cover_for_book(realmi,saved_setting_name=setting_name)
## if error column set.
if prefs['errorcol'] != '' and prefs['errorcol'] in custom_columns:
label = custom_columns[prefs['errorcol']]['label']
print("_update_book label:%s"%label)
db.set_custom(book['calibre_id'], '', label=label, commit=True) # book['comment']
def _get_clean_reading_lists(self,lists):
if lists == None or lists.strip() == "" :
+1 -1
View File
@@ -58,7 +58,7 @@ class Configurable(object):
for section in self.sectionslist:
try:
self.config.get(section,key)
print("found %s in section [%s]"%(key,section))
#print("found %s in section [%s]"%(key,section))
return True
except:
pass