Sorted user recipes in serialize_collection

This commit is contained in:
Starson17 2011-02-04 12:17:33 -05:00
parent 8c952c2c32
commit 1a5c956188
3 changed files with 35 additions and 23 deletions

View File

@ -179,28 +179,42 @@ class DBAdder(QObject): # {{{
cover = f.read()
orig_formats = formats
formats = [f for f in formats if not f.lower().endswith('.opf')]
if prefs['add_formats_to_existing']:
if prefs['add_formats_to_existing']: #automerge is on
identical_book_list = self.db.find_identical_books(mi)
if identical_book_list: # books with same author and nearly same title exist in db
print 'identical_book_list is: ', identical_book_list #We are dealing with only one file of a specific format, and this is a list of matching db book records to the one file/format being processed
if identical_book_list: # books with same author and nearly same title exist in db for the one format being handled
self.merged_books.add(mi.title)
for identical_book in identical_book_list:
for identical_book in identical_book_list: #this will add the new format to *each* matching entry in the db - Do we need to do this?
if gprefs['automerge'] == 'ignore':
self.add_formats(identical_book, formats, replace=False)
print 'do something for ignore'
if gprefs['automerge'] == 'overwrite':
self.add_formats(identical_book, formats, replace=True)
print 'do something for overwrite'
print 'inside overwrite'
if gprefs['automerge'] == 'new record':
print 'We are in new record'
'''
We are here because we have at least one book record in the db that matches the one file/format being processed
We need to check if the file/format being processed matches a format in the matching book record.
If so, create new record (as below), else, add to existing record, as above.
Test if format exists in matching record. identical_book is an id, formats is a FQPN path in a list
'''
for path in formats: #I think there's always only one path in formats - Check
fmt = os.path.splitext(path)[-1].replace('.', '').upper() #this is the format extension of the incoming file
ib_fmts = self.db.formats(identical_book, index_is_id=True) #These are the formats in the record
if fmt in ib_fmts: #Create a new record if the incoming format already exists in the identical book (ib) record
id = self.db.create_book_entry(mi, cover=cover, add_duplicates=True)
self.number_of_books_added += 1
self.add_formats(id, formats)
print 'do something for new record'
else:
#If we created a new record, are we done - or should we go on and add to other existing records that don't have this format?
else: #a new record is not required - the incoming format does not exist in the ib record
self.add_formats(identical_book, formats, replace=False)
else: # books with same author and nearly same title do not exist in db
id = self.db.create_book_entry(mi, cover=cover, add_duplicates=True)
self.number_of_books_added += 1
self.add_formats(id, formats)
else:
else: #automerge is off -use legacy duplicates code
id = self.db.create_book_entry(mi, cover=cover, add_duplicates=False)
if id is None:
self.duplicates.append((mi, cover, orig_formats))
@ -214,7 +228,7 @@ class DBAdder(QObject): # {{{
return mi.title
def add_formats(self, id, formats, replace=True):
for path in formats:
for path in formats: #path and formats will be the same fully qualified path and book filename when used by automerge
fmt = os.path.splitext(path)[-1].replace('.', '').upper()
with open(path, 'rb') as f:
self.db.add_format(id, fmt, f, index_is_id=True,

View File

@ -23,10 +23,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
r('read_file_metadata', prefs)
r('swap_author_names', prefs)
r('add_formats_to_existing', prefs)
choices = [(_('Ignore'), 'ignore'), (_('Overwrite'), 'overwrite'),
(_('New Record'), 'new record')]
choices = [(_('Ignore the incoming format'), 'ignore'), (_('Overwrite the existing format with the incoming format'), 'overwrite'), (_('Create a new book record for the incoming format'), 'new record')]
r('automerge', gprefs, choices=choices)
#print 'The automerge setting is: ', gprefs['automerge']
self.filename_pattern = FilenamePattern(self)
self.metadata_box.layout().insertWidget(0, self.filename_pattern)

View File

@ -31,22 +31,22 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="1"> #MOD was colspan="2"
<item row="2" column="0" colspan="1">
<widget class="QCheckBox" name="opt_add_formats_to_existing">
<property name="toolTip">
<string>If an existing book with a similar title and author is found, the incoming format will be added to the existing book record where possible.
If the existing book already has the incoming format, then the setting to the right controls and the new format will be ignored, it will overwrite the old format
or a new record will be created.
<string>If an existing book with a similar title and author is found, the incoming format will be added to the existing book record, where possible.
If the existing book already has the incoming format, then the setting to the right controls and the new format will be ignored, it will overwrite the existing format
or a new book record will be created for the incoming format.
Title match ignores leading indefinite articles (&quot;the&quot;, &quot;a&quot;, &quot;an&quot;), punctuation, case, etc. Author match is exact.</string>
</property>
<property name="text">
<string>If books with similar titles and authors found, &amp;try to merge the new formats automatically
and do this for duplicate formats: </string>
<string>Automerge: If books with similar titles and authors found, try to &amp;merge the incoming formats automatically
into existing book records. The option to the right controls what happens when the existing record already has the incoming format: </string>
</property>
</widget>
</item>
<item row="2" column="1"> #MOD added as new item
<item row="2" column="1">
<widget class="QComboBox" name="opt_automerge"/>
</item>
<item row="3" column="0" colspan="2">