Fix setting rating via ebook-meta command line tool broken in calibre 5. Fixes #1901113 [ebook-meta --rating fails](https://bugs.launchpad.net/calibre/+bug/1901113)

More python 3 chicanery
This commit is contained in:
Kovid Goyal 2020-10-23 09:38:05 +05:30
parent 4a864575b1
commit b0e276435f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 4 additions and 2 deletions

View File

@ -1313,6 +1313,8 @@ class OPF(object): # {{{
'isbn', 'tags', 'category', 'comments', 'book_producer', 'isbn', 'tags', 'category', 'comments', 'book_producer',
'pubdate', 'user_categories', 'author_link_map'): 'pubdate', 'user_categories', 'author_link_map'):
val = getattr(mi, attr, None) val = getattr(mi, attr, None)
if attr == 'rating' and val:
val = float(val)
is_null = val is None or val in ((), [], (None, None), {}) or (attr == 'rating' and val < 0.1) is_null = val is None or val in ((), [], (None, None), {}) or (attr == 'rating' and val < 0.1)
if is_null: if is_null:
if apply_null and attr in {'series', 'tags', 'isbn', 'comments', 'publisher', 'rating'}: if apply_null and attr in {'series', 'tags', 'isbn', 'comments', 'publisher', 'rating'}:

View File

@ -744,7 +744,7 @@ def set_rating(root, prefixes, refines, val):
if prop.lower() == pq: if prop.lower() == pq:
remove_element(meta, refines) remove_element(meta, refines)
if val: if val:
create_rating(root, prefixes, '%.2g' % val) create_rating(root, prefixes, '%.2g' % float(val))
# }}} # }}}
# Series {{{ # Series {{{
@ -1052,7 +1052,7 @@ def apply_metadata(root, mi, cover_prefix='', cover_data=None, apply_null=False,
set_publisher(root, prefixes, refines, mi.publisher) set_publisher(root, prefixes, refines, mi.publisher)
if ok('tags'): if ok('tags'):
set_tags(root, prefixes, refines, mi.tags) set_tags(root, prefixes, refines, mi.tags)
if ok('rating') and mi.rating is not None and mi.rating > 0.1: if ok('rating') and mi.rating is not None and float(mi.rating) > 0.1:
set_rating(root, prefixes, refines, mi.rating) set_rating(root, prefixes, refines, mi.rating)
if ok('series'): if ok('series'):
set_series(root, prefixes, refines, mi.series, mi.series_index or 1) set_series(root, prefixes, refines, mi.series, mi.series_index or 1)