mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Some plugboard fixes
This commit is contained in:
parent
f2e0b50144
commit
c02cee6e8b
@ -295,24 +295,26 @@ class Metadata(object):
|
|||||||
_data = object.__getattribute__(self, '_data')
|
_data = object.__getattribute__(self, '_data')
|
||||||
_data['user_metadata'][field] = metadata
|
_data['user_metadata'][field] = metadata
|
||||||
|
|
||||||
def template_to_attribute(self, other, attrs):
|
def template_to_attribute(self, other, ops):
|
||||||
'''
|
'''
|
||||||
Takes a dict {src:dest, src:dest}, evaluates the template in the context
|
Takes a list [(src,dest), (src,dest)], evaluates the template in the
|
||||||
of other, then copies the result to self[dest]. This is on a best-
|
context of other, then copies the result to self[dest]. This is on a
|
||||||
efforts basis. Some assignments can make no sense.
|
best-efforts basis. Some assignments can make no sense.
|
||||||
'''
|
'''
|
||||||
if not attrs:
|
if not ops:
|
||||||
return
|
return
|
||||||
for src in attrs:
|
for op in ops:
|
||||||
try:
|
try:
|
||||||
|
src = op[0]
|
||||||
|
dest = op[1]
|
||||||
val = composite_formatter.safe_format\
|
val = composite_formatter.safe_format\
|
||||||
(src, other, 'PLUGBOARD TEMPLATE ERROR', other)
|
(src, other, 'PLUGBOARD TEMPLATE ERROR', other)
|
||||||
dfm = self.metadata_for_field(attrs[src])
|
if dest == 'tags':
|
||||||
if dfm and dfm['is_multiple']:
|
self.set(dest, [f.strip() for f in val.split(',') if f.strip()])
|
||||||
self.set(attrs[src],
|
elif dest == 'authors':
|
||||||
[f.strip() for f in val.split(',') if f.strip()])
|
self.set(dest, [val])
|
||||||
else:
|
else:
|
||||||
self.set(attrs[src], val)
|
self.set(dest, val)
|
||||||
except:
|
except:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
pass
|
pass
|
||||||
|
@ -334,7 +334,7 @@ class DeviceManager(Thread): # {{{
|
|||||||
if cpb is not None:
|
if cpb is not None:
|
||||||
if dev_name in cpb:
|
if dev_name in cpb:
|
||||||
cpb = cpb[dev_name]
|
cpb = cpb[dev_name]
|
||||||
elif plugboard_any_device_value in plugboards[ext]:
|
elif plugboard_any_device_value in cpb:
|
||||||
cpb = cpb[plugboard_any_device_value]
|
cpb = cpb[plugboard_any_device_value]
|
||||||
else:
|
else:
|
||||||
cpb = None
|
cpb = None
|
||||||
|
@ -57,12 +57,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
self.formats.insert(1, plugboard_any_format_value)
|
self.formats.insert(1, plugboard_any_format_value)
|
||||||
self.new_format.addItems(self.formats)
|
self.new_format.addItems(self.formats)
|
||||||
|
|
||||||
self.source_fields = ['']
|
|
||||||
for f in self.db.custom_field_keys():
|
|
||||||
if self.db.field_metadata[f]['datatype'] == 'composite':
|
|
||||||
self.source_fields.append(f)
|
|
||||||
self.source_fields.sort(cmp=field_cmp)
|
|
||||||
|
|
||||||
self.dest_fields = ['',
|
self.dest_fields = ['',
|
||||||
'authors', 'author_sort', 'language', 'publisher',
|
'authors', 'author_sort', 'language', 'publisher',
|
||||||
'tags', 'title', 'title_sort']
|
'tags', 'title', 'title_sort']
|
||||||
@ -128,8 +122,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
print 'edit_device_changed: none device!'
|
print 'edit_device_changed: none device!'
|
||||||
return
|
return
|
||||||
self.set_fields()
|
self.set_fields()
|
||||||
for i,src in enumerate(dpb):
|
for i,op in enumerate(dpb):
|
||||||
self.set_field(i, src, dpb[src])
|
self.set_field(i, op[0], op[1])
|
||||||
self.ok_button.setEnabled(True)
|
self.ok_button.setEnabled(True)
|
||||||
self.del_button.setEnabled(True)
|
self.del_button.setEnabled(True)
|
||||||
|
|
||||||
@ -164,7 +158,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
# user specified any format.
|
# user specified any format.
|
||||||
for f in self.current_plugboards:
|
for f in self.current_plugboards:
|
||||||
devs = set(self.current_plugboards[f])
|
devs = set(self.current_plugboards[f])
|
||||||
print 'check', self.current_format, devs
|
|
||||||
if self.current_device != plugboard_save_to_disk_value and \
|
if self.current_device != plugboard_save_to_disk_value and \
|
||||||
plugboard_any_device_value in devs:
|
plugboard_any_device_value in devs:
|
||||||
# specific format/any device in list. conflict.
|
# specific format/any device in list. conflict.
|
||||||
@ -216,7 +209,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
self.new_device.setCurrentIndex(0)
|
self.new_device.setCurrentIndex(0)
|
||||||
|
|
||||||
def ok_clicked(self):
|
def ok_clicked(self):
|
||||||
pb = {}
|
pb = []
|
||||||
for i in range(0, len(self.source_widgets)):
|
for i in range(0, len(self.source_widgets)):
|
||||||
s = unicode(self.source_widgets[i].text())
|
s = unicode(self.source_widgets[i].text())
|
||||||
if s:
|
if s:
|
||||||
@ -229,13 +222,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
'<p>'+_('The template %s is invalid:')%s + \
|
'<p>'+_('The template %s is invalid:')%s + \
|
||||||
'<br>'+str(err), show=True)
|
'<br>'+str(err), show=True)
|
||||||
return
|
return
|
||||||
pb[s] = self.dest_fields[d]
|
pb.append((s, self.dest_fields[d]))
|
||||||
else:
|
else:
|
||||||
error_dialog(self, _('Invalid destination'),
|
error_dialog(self, _('Invalid destination'),
|
||||||
'<p>'+_('The destination field cannot be blank'),
|
'<p>'+_('The destination field cannot be blank'),
|
||||||
show=True)
|
show=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
if len(pb) == 0:
|
if len(pb) == 0:
|
||||||
if self.current_format in self.current_plugboards:
|
if self.current_format in self.current_plugboards:
|
||||||
fpb = self.current_plugboards[self.current_format]
|
fpb = self.current_plugboards[self.current_format]
|
||||||
@ -282,8 +274,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
continue
|
continue
|
||||||
ops = []
|
ops = []
|
||||||
for op in self.current_plugboards[f][d]:
|
for op in self.current_plugboards[f][d]:
|
||||||
ops.append(op + '->' + self.current_plugboards[f][d][op])
|
ops.append('[' + op[0] + '] -> ' + op[1])
|
||||||
txt += '%s:%s [%s]\n'%(f, d, ', '.join(ops))
|
txt += '%s:%s %s\n'%(f, d, ', '.join(ops))
|
||||||
self.existing_plugboards.setPlainText(txt)
|
self.existing_plugboards.setPlainText(txt)
|
||||||
|
|
||||||
def restore_defaults(self):
|
def restore_defaults(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user