From 5de91ff9b54334f2b4c2547ba9f9d06723d2c70f Mon Sep 17 00:00:00 2001 From: croneter Date: Wed, 23 Jan 2019 10:00:49 +0100 Subject: [PATCH] Fix KodiVideoDB object has no attribute kodiconn - Partially fixes #593 - Fixes #614 --- resources/lib/artwork.py | 4 +++- resources/lib/itemtypes/common.py | 17 +++++++++-------- resources/lib/itemtypes/music.py | 12 ++++++++---- resources/lib/kodi_db/common.py | 23 +++++++++++++++-------- resources/lib/kodi_db/texture.py | 6 +++--- resources/lib/plex_db/common.py | 5 +++-- 6 files changed, 41 insertions(+), 26 deletions(-) diff --git a/resources/lib/artwork.py b/resources/lib/artwork.py index e86c82bb..539a9c45 100644 --- a/resources/lib/artwork.py +++ b/resources/lib/artwork.py @@ -42,7 +42,9 @@ class ImageCachingThread(backgroundthread.KillableThread): while True: batch = [] with kind(texture_db=True) as kodidb: - texture_db = KodiTextureDB(cursor=kodidb.artcursor) + texture_db = KodiTextureDB(kodiconn=kodidb.kodiconn, + artconn=kodidb.artconn, + lock=False) for i, url in enumerate(kodidb.artwork_generator(kodi_type, BATCH_SIZE, offset)): diff --git a/resources/lib/itemtypes/common.py b/resources/lib/itemtypes/common.py index 83e4991d..4074430b 100644 --- a/resources/lib/itemtypes/common.py +++ b/resources/lib/itemtypes/common.py @@ -41,14 +41,14 @@ class ItemBase(object): def __init__(self, last_sync, plexdb=None, kodidb=None, lock=True): self.last_sync = last_sync self.lock = lock - self.plexconn = None + self.plexdb = plexdb + self.kodidb = kodidb + self.plexconn = plexdb.plexconn if plexdb else None self.plexcursor = plexdb.cursor if plexdb else None - self.kodiconn = None + self.kodiconn = kodidb.kodiconn if kodidb else None self.kodicursor = kodidb.cursor if kodidb else None self.artconn = kodidb.artconn if kodidb else None self.artcursor = kodidb.artcursor if kodidb else None - self.plexdb = plexdb - self.kodidb = kodidb def __enter__(self): """ @@ -67,10 +67,11 @@ class ItemBase(object): else: self.artconn = None self.artcursor = None - self.plexdb = PlexDB(cursor=self.plexcursor) - self.kodidb = KodiVideoDB(texture_db=True, - cursor=self.kodicursor, - artcursor=self.artcursor) + self.plexdb = PlexDB(plexconn=self.plexconn, lock=False) + self.kodidb = KodiVideoDB(texture_db=app.SYNC.artwork, + kodiconn=self.kodiconn, + artconn=self.artconn, + lock=False) return self def __exit__(self, exc_type, exc_val, exc_tb): diff --git a/resources/lib/itemtypes/music.py b/resources/lib/itemtypes/music.py index afb4a06f..b51da1cb 100644 --- a/resources/lib/itemtypes/music.py +++ b/resources/lib/itemtypes/music.py @@ -27,10 +27,14 @@ class MusicMixin(object): if app.SYNC.artwork: self.artconn = utils.kodi_sql('texture') self.artcursor = self.artconn.cursor() - self.plexdb = PlexDB(self.plexcursor) - self.kodidb = KodiMusicDB(texture_db=True, - cursor=self.kodicursor, - artcursor=self.artcursor) + else: + self.artconn = None + self.artcursor = None + self.plexdb = PlexDB(plexconn=self.plexconn, lock=False) + self.kodidb = KodiMusicDB(texture_db=app.SYNC.artwork, + kodiconn=self.kodiconn, + artconn=self.artconn, + lock=False) return self def update_userdata(self, xml_element, plex_type): diff --git a/resources/lib/kodi_db/common.py b/resources/lib/kodi_db/common.py index 0ba3f308..510d8559 100644 --- a/resources/lib/kodi_db/common.py +++ b/resources/lib/kodi_db/common.py @@ -10,6 +10,13 @@ KODIDB_LOCK = Lock() DB_WRITE_ATTEMPTS = 100 +class LockedKodiDatabase(Exception): + """ + Dedicated class to make sure we're not silently catching locked DBs. + """ + pass + + def catch_operationalerrors(method): """ sqlite.OperationalError is raised immediately if another DB connection @@ -32,7 +39,7 @@ def catch_operationalerrors(method): attempts -= 1 if attempts == 0: # Reraise in order to NOT catch nested OperationalErrors - raise RuntimeError('Kodi database locked') + raise LockedKodiDatabase('Kodi database locked') # Need to close the transactions and begin new ones self.kodiconn.commit() if self.artconn: @@ -51,24 +58,24 @@ class KodiDBBase(object): """ Kodi database methods used for all types of items """ - def __init__(self, texture_db=False, cursor=None, artcursor=None, lock=True): + def __init__(self, texture_db=False, kodiconn=None, artconn=None, lock=True): """ Allows direct use with a cursor instead of context mgr """ self._texture_db = texture_db - self.cursor = cursor - self.artconn = None - self.artcursor = artcursor self.lock = lock + self.kodiconn = kodiconn + self.cursor = self.kodiconn.cursor() if self.kodiconn else None + self.artconn = artconn + self.artcursor = self.artconn.cursor() if self.artconn else None def __enter__(self): if self.lock: KODIDB_LOCK.acquire() self.kodiconn = utils.kodi_sql(self.db_kind) self.cursor = self.kodiconn.cursor() - if self._texture_db: - self.artconn = utils.kodi_sql('texture') - self.artcursor = self.artconn.cursor() + self.artconn = utils.kodi_sql('texture') if self._texture_db else None + self.artcursor = self.artconn.cursor() if self._texture_db else None return self def __exit__(self, e_typ, e_val, trcbak): diff --git a/resources/lib/kodi_db/texture.py b/resources/lib/kodi_db/texture.py index dfc4cdd7..14e016f2 100644 --- a/resources/lib/kodi_db/texture.py +++ b/resources/lib/kodi_db/texture.py @@ -12,6 +12,6 @@ class KodiTextureDB(common.KodiDBBase): """ Returns True if url has not yet been cached to the Kodi texture cache """ - self.cursor.execute('SELECT url FROM texture WHERE url = ? LIMIT 1', - (url, )) - return self.cursor.fetchone() is None + self.artcursor.execute('SELECT url FROM texture WHERE url = ? LIMIT 1', + (url, )) + return self.artcursor.fetchone() is None diff --git a/resources/lib/plex_db/common.py b/resources/lib/plex_db/common.py index 72956c18..8d6db16e 100644 --- a/resources/lib/plex_db/common.py +++ b/resources/lib/plex_db/common.py @@ -22,9 +22,10 @@ class PlexDBBase(object): """ Plex database methods used for all types of items """ - def __init__(self, cursor=None, lock=True): + def __init__(self, plexconn=None, lock=True): # Allows us to use this class with a cursor instead of context mgr - self.cursor = cursor + self.plexconn = plexconn + self.cursor = self.plexconn.cursor() if self.plexconn else None self.lock = lock def __enter__(self):