From 97b8083562f61a67868d3a562a685c48332f0d0a Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Wed, 10 Feb 2016 11:00:32 +0100 Subject: [PATCH] Fix embydb --- resources/lib/embydb_functions.py | 22 ++++++++++++++++++++-- resources/lib/entrypoint.py | 2 +- resources/lib/librarysync.py | 6 +++--- resources/lib/utils.py | 20 -------------------- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/resources/lib/embydb_functions.py b/resources/lib/embydb_functions.py index bf42ac49..bbde60bb 100644 --- a/resources/lib/embydb_functions.py +++ b/resources/lib/embydb_functions.py @@ -2,12 +2,30 @@ ################################################################################################# -import utils +from utils import logging, kodiSQL ################################################################################################# -@utils.logging +class GetEmbyDB(): + """ + Usage: with GetEmbyDB() as emby_db: + do stuff with emby_db + + On exiting "with" (no matter what), commits get automatically committed + and the db gets closed + """ + def __enter__(self): + self.embyconn = kodiSQL('emby') + self.emby_db = Embydb_Functions(self.embyconn.cursor()) + return self.emby_db + + def __exit__(self, type, value, traceback): + self.embyconn.commit() + self.embyconn.close() + + +@logging class Embydb_Functions(): def __init__(self, embycursor): diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index 665fa074..0e8792a7 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -386,7 +386,7 @@ def getThemeMedia(): return # Get every user view Id - with utils.GetEmbyDB() as emby_db: + with embydb.GetEmbyDB() as emby_db: viewids = emby_db.getViews() # Get Ids with Theme Videos diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 7db4475f..5f90aa10 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -276,7 +276,7 @@ class LibrarySync(threading.Thread): # Get all PMS items already saved in Kodi # Also get checksums of every Plex items already saved in Kodi allKodiElementsId = {} - with utils.GetEmbyDB() as emby_db: + with embydb.GetEmbyDB() as emby_db: for itemtype in PlexFunctions.EmbyItemtypes(): try: allKodiElementsId.update( @@ -733,7 +733,7 @@ class LibrarySync(threading.Thread): self.allKodiElementsId = {} if self.compare: - with utils.GetEmbyDB() as emby_db: + with embydb.GetEmbyDB() as emby_db: # Get movies from Plex server # Pull the list of movies and boxsets in Kodi try: @@ -850,7 +850,7 @@ class LibrarySync(threading.Thread): self.allKodiElementsId = {} if self.compare: - with utils.GetEmbyDB() as emby_db: + with embydb.GetEmbyDB() as emby_db: # Get movies from Plex server # Pull the list of TV shows already in Kodi try: diff --git a/resources/lib/utils.py b/resources/lib/utils.py index aa39b46e..bd8cc150 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -19,32 +19,12 @@ import xbmcaddon import xbmcgui import xbmcvfs -import embydb_functions as embydb - ################################################################################################# addonName = xbmcaddon.Addon().getAddonInfo('name') -class GetEmbyDB(): - """ - Usage: with GetEmbyDB() as emby_db: - do stuff with emby_db - - On exiting "with" (no matter what), commits get automatically committed - and the db gets closed - """ - def __enter__(self): - self.embyconn = kodiSQL('emby') - self.emby_db = embydb.Embydb_Functions(self.embyconn.cursor()) - return self.emby_db - - def __exit__(self, type, value, traceback): - self.embyconn.commit() - self.embyconn.close() - - def LogTime(func): """ Decorator for functions and methods to log the time it took to run the code