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['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
|
||||
of other, then copies the result to self[dest]. This is on a best-
|
||||
efforts basis. Some assignments can make no sense.
|
||||
Takes a list [(src,dest), (src,dest)], evaluates the template in the
|
||||
context of other, then copies the result to self[dest]. This is on a
|
||||
best-efforts basis. Some assignments can make no sense.
|
||||
'''
|
||||
if not attrs:
|
||||
if not ops:
|
||||
return
|
||||
for src in attrs:
|
||||
for op in ops:
|
||||
try:
|
||||
src = op[0]
|
||||
dest = op[1]
|
||||
val = composite_formatter.safe_format\
|
||||
(src, other, 'PLUGBOARD TEMPLATE ERROR', other)
|
||||
dfm = self.metadata_for_field(attrs[src])
|
||||
if dfm and dfm['is_multiple']:
|
||||
self.set(attrs[src],
|
||||
[f.strip() for f in val.split(',') if f.strip()])
|
||||
if dest == 'tags':
|
||||
self.set(dest, [f.strip() for f in val.split(',') if f.strip()])
|
||||
elif dest == 'authors':
|
||||
self.set(dest, [val])
|
||||
else:
|
||||
self.set(attrs[src], val)
|
||||
self.set(dest, val)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
pass
|
||||
|
@ -334,7 +334,7 @@ class DeviceManager(Thread): # {{{
|
||||
if cpb is not None:
|
||||
if dev_name in cpb:
|
||||
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]
|
||||
else:
|
||||
cpb = None
|
||||
|
@ -57,12 +57,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
self.formats.insert(1, plugboard_any_format_value)
|
||||
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 = ['',
|
||||
'authors', 'author_sort', 'language', 'publisher',
|
||||
'tags', 'title', 'title_sort']
|
||||
@ -128,8 +122,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
print 'edit_device_changed: none device!'
|
||||
return
|
||||
self.set_fields()
|
||||
for i,src in enumerate(dpb):
|
||||
self.set_field(i, src, dpb[src])
|
||||
for i,op in enumerate(dpb):
|
||||
self.set_field(i, op[0], op[1])
|
||||
self.ok_button.setEnabled(True)
|
||||
self.del_button.setEnabled(True)
|
||||
|
||||
@ -164,7 +158,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
# user specified any format.
|
||||
for f in self.current_plugboards:
|
||||
devs = set(self.current_plugboards[f])
|
||||
print 'check', self.current_format, devs
|
||||
if self.current_device != plugboard_save_to_disk_value and \
|
||||
plugboard_any_device_value in devs:
|
||||
# specific format/any device in list. conflict.
|
||||
@ -216,7 +209,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
self.new_device.setCurrentIndex(0)
|
||||
|
||||
def ok_clicked(self):
|
||||
pb = {}
|
||||
pb = []
|
||||
for i in range(0, len(self.source_widgets)):
|
||||
s = unicode(self.source_widgets[i].text())
|
||||
if s:
|
||||
@ -229,13 +222,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
'<p>'+_('The template %s is invalid:')%s + \
|
||||
'<br>'+str(err), show=True)
|
||||
return
|
||||
pb[s] = self.dest_fields[d]
|
||||
pb.append((s, self.dest_fields[d]))
|
||||
else:
|
||||
error_dialog(self, _('Invalid destination'),
|
||||
'<p>'+_('The destination field cannot be blank'),
|
||||
show=True)
|
||||
return
|
||||
|
||||
if len(pb) == 0:
|
||||
if self.current_format in self.current_plugboards:
|
||||
fpb = self.current_plugboards[self.current_format]
|
||||
@ -282,8 +274,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
continue
|
||||
ops = []
|
||||
for op in self.current_plugboards[f][d]:
|
||||
ops.append(op + '->' + self.current_plugboards[f][d][op])
|
||||
txt += '%s:%s [%s]\n'%(f, d, ', '.join(ops))
|
||||
ops.append('[' + op[0] + '] -> ' + op[1])
|
||||
txt += '%s:%s %s\n'%(f, d, ', '.join(ops))
|
||||
self.existing_plugboards.setPlainText(txt)
|
||||
|
||||
def restore_defaults(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user