Skip to content

Commit

Permalink
avoid unnecessary file overwriting
Browse files Browse the repository at this point in the history
  • Loading branch information
flibrarian committed May 1, 2022
1 parent e3f35b8 commit 94f5482
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions flibcommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ def build_filename(book, translit):
base = cut_unicode(base, 240)
return "%s.%d.fb2" % (base, book.id)

def compare_descriptions(descr1, descr2):
if descr1 == descr2:
return True
descr1_sorted = Description(descr1.title, descr1.authors, descr1.translators, sorted(descr1.genres), sorted(descr1.sequences), sorted(descr1.psequences), descr1.lang, descr1.year)
descr2_sorted = Description(descr2.title, descr2.authors, descr2.translators, sorted(descr2.genres), sorted(descr2.sequences), sorted(descr2.psequences), descr2.lang, descr2.year)
return descr1_sorted == descr2_sorted

def yes_or_no(question):
question = question + ' (y/n): '
# question = question.encode(sys.stdout.encoding)
Expand Down
2 changes: 1 addition & 1 deletion flibextract.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def check_local_file(book, path, quick, translit):
with open(new_book_path, 'rb') as zfo:
tree = read_book_zip(zfo)
local_book = load_book_info(book.id, tree)
return book.description == local_book.description and book.bodyhash == local_book.bodyhash
return compare_descriptions(book.description, local_book.description) and book.bodyhash == local_book.bodyhash
except Exception as e:
return False

Expand Down

0 comments on commit 94f5482

Please sign in to comment.