From 11a068cd306f5a93a848ecbdf75edcefaedfb9b0 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Thu, 15 Sep 2016 05:31:15 -0500 Subject: [PATCH] Migrate db version to emby database --- resources/lib/embydb_functions.py | 15 +++++++++++++++ resources/lib/librarysync.py | 27 +++++++++++++++++++++++---- resources/lib/utils.py | 1 + 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/resources/lib/embydb_functions.py b/resources/lib/embydb_functions.py index 8c2d8b65..ed2ec825 100644 --- a/resources/lib/embydb_functions.py +++ b/resources/lib/embydb_functions.py @@ -20,6 +20,21 @@ class Embydb_Functions(): self.embycursor = embycursor + def get_version(self, version=None): + + if version is not None: + query = "INSERT INTO version(idVersion) VALUES (?)" + self.embycursor.execute(query, (version,)) + else: + query = "SELECT idVersion FROM version" + self.embycursor.execute(query) + try: + version = self.embycursor.fetchone()[0] + except TypeError: + pass + + return version + def getViews(self): views = [] diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 4ac09a7b..a84673d4 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -311,10 +311,14 @@ class LibrarySync(threading.Thread): if pDialog: pDialog.close() + emby_db = embydb.Embydb_Functions(embycursor) + current_version = emby_db.get_version(self.clientInfo.get_version()) + window('emby_version', current_version) + embyconn.commit() embycursor.close() settings('SyncInstallRunDone', value="true") - settings("dbCreatedWithVersion", self.clientInfo.get_version()) + self.saveLastSync() xbmc.executebuiltin('UpdateLibrary(video)') elapsedtotal = datetime.now() - starttotal @@ -891,6 +895,7 @@ class LibrarySync(threading.Thread): def compareDBVersion(self, current, minimum): # It returns True is database is up to date. False otherwise. log.info("current: %s minimum: %s" % (current, minimum)) + currMajor, currMinor, currPatch = current.split(".") minMajor, minMinor, minPatch = minimum.split(".") @@ -941,7 +946,20 @@ class LibrarySync(threading.Thread): if (window('emby_dbCheck') != "true" and settings('SyncInstallRunDone') == "true"): # Verify the validity of the database - currentVersion = settings('dbCreatedWithVersion') + + embyconn = utils.kodiSQL('emby') + embycursor = embyconn.cursor() + emby_db = embydb.Embydb_Functions(embycursor) + currentVersion = emby_db.get_version() + ###$ Begin migration $### + if currentVersion is None: + currentVersion = emby_db.get_version(settings('dbCreatedWithVersion')) + embyconn.commit() + log.info("Migration of database version completed") + ###$ End migration $### + embycursor.close() + window('emby_version', value=currentVersion) + minVersion = window('emby_minDBVersion') uptoDate = self.compareDBVersion(currentVersion, minVersion) @@ -975,10 +993,11 @@ class LibrarySync(threading.Thread): dialog.ok( heading=lang(29999), line1=lang(33024)) - break + break + # Run start up sync - log.warn("Database version: %s" % settings('dbCreatedWithVersion')) + log.warn("Database version: %s", window('emby_version')) log.info("SyncDatabase (started)") startTime = datetime.now() librarySync = self.startSync() diff --git a/resources/lib/utils.py b/resources/lib/utils.py index 561d27df..7a975ea7 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -392,6 +392,7 @@ def reset(): cursor.execute("DELETE FROM " + tablename) cursor.execute('DROP table IF EXISTS emby') cursor.execute('DROP table IF EXISTS view') + cursor.execute("DELETE FROM version") connection.commit() cursor.close()