View Single Post
Old 10-20-2013, 08:28 AM   #1
At_Libitum
Addict
At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.At_Libitum ought to be getting tired of karma fortunes by now.
 
Posts: 265
Karma: 724240
Join Date: Aug 2013
Device: KyBook
weirdness while accessing metadata in plugin

Hi,

I'm a bit stumped as the msgs I am getting aren't making sense.

I have the following bit of code
Code:
mi = get_metadata(_stream)
# get a list of all of the metadata fields 
_all_lookup_fields = mi.all_field_keys()
for key in enumerate(_all_lookup_fields):
	self._log(repr(key))
if getattr(mi, 'user_metadata'):
	book.user_metadata = mi.get('user_metadata')
when run it produces the following debug output.
Code:
DEBUG:   18.8  (0, 'rating')
DEBUG:   18.8  (1, 'title_sort')
DEBUG:   18.8  (2, 'application_id')
DEBUG:   18.8  (3, 'pubdate')
DEBUG:   18.8  (4, 'series')
DEBUG:   18.8  (5, 'author_sort_map')
DEBUG:   18.8  (6, 'publication_type')
DEBUG:   18.8  (7, 'size')
DEBUG:   18.8  (8, 'author_link_map')
DEBUG:   18.8  (9, 'rights')
DEBUG:   18.8  (10, 'uuid')
DEBUG:   18.8  (11, 'title')
DEBUG:   18.8  (12, 'comments')
DEBUG:   18.8  (13, 'languages')
DEBUG:   18.8  (14, 'cover_data')
DEBUG:   18.8  (15, 'toc')
DEBUG:   18.8  (16, 'thumbnail')
DEBUG:   18.8  (17, 'db_id')
DEBUG:   18.8  (18, 'user_metadata')
DEBUG:   18.8  (19, 'tags')
DEBUG:   18.8  (20, 'timestamp')
DEBUG:   18.8  (21, 'last_modified')
DEBUG:   18.8  (22, 'mime')
DEBUG:   18.8  (23, 'authors')
DEBUG:   18.8  (24, 'publisher')
DEBUG:   18.8  (25, 'series_index')
DEBUG:   18.8  (26, 'lpath')
DEBUG:   18.8  (27, 'user_categories')
DEBUG:   18.8  (28, 'spine')
DEBUG:   18.8  (29, 'author_sort')
DEBUG:   18.8  (30, 'cover')
DEBUG:   18.8  (31, 'book_producer')
DEBUG:   18.8  (32, 'manifest')
DEBUG:   18.8  (33, 'formats')
DEBUG:   18.8  (34, 'guide')
DEBUG:   18.8  (35, 'device_collections')
DEBUG:   18.8  (36, 'identifiers')
DeviceJob: 2 Get list of books on device done, calling callback
Metadata object has no attribute named: 'user_metadata'

Traceback (most recent call last):
  File "site-packages\calibre\gui2\device.py", line 85, in run
  File "site-packages\calibre\gui2\device.py", line 480, in _books
  File "%tempdir%\reader_overlays.py", line 697, in books
  File "%tempdir%\reader_overlays.py", line 441, in _get_books_from_device
  File "%tempdir%\reader_overlays.py", line 573, in _get_metadata
  File "site-packages\calibre\ebooks\metadata\book\base.py", line 149, in __getattribute__
AttributeError: Metadata object has no attribute named: 'user_metadata'
Now I may know zilch about python, but I am definitely seeing the user_metadata listed when retrieving the present keys, so why does it complain?

the second inconstent response I got when executing this

Code:
if hasattr(mi,'identifiers'):
	book.identifiers = mi.get('identifiers')
	_urn = book.identifiers['urn']

u'urn'

Traceback (most recent call last):
  File "site-packages\calibre\gui2\device.py", line 85, in run
  File "site-packages\calibre\gui2\device.py", line 480, in _books
  File "%tempdir%\reader_overlays.py", line 697, in books
  File "%tempdir%\reader_overlays.py", line 441, in _get_books_from_device
  File "%tempdir%\reader_overlays.py", line 555, in _get_metadata
KeyError: u'urn'
and if I change the hasattr to getattr, lo and behold, no complaint and I even get a value from 'urn' posted to _urn

????
At_Libitum is offline   Reply With Quote