mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 02:06:09 +00:00
move DB reset function to the databse file
use the new DB connection context for all DB reset actions
This commit is contained in:
parent
4701041d99
commit
d3ce04ab10
4 changed files with 102 additions and 98 deletions
|
@ -23,6 +23,7 @@ import entrypoint
|
||||||
import loghandler
|
import loghandler
|
||||||
from utils import window, dialog, language as lang
|
from utils import window, dialog, language as lang
|
||||||
from ga_client import GoogleAnalytics
|
from ga_client import GoogleAnalytics
|
||||||
|
import database
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
|
@ -80,7 +81,7 @@ class Main(object):
|
||||||
import utils
|
import utils
|
||||||
modes = {
|
modes = {
|
||||||
|
|
||||||
'reset': utils.reset,
|
'reset': database.db_reset,
|
||||||
'resetauth': entrypoint.resetAuth,
|
'resetauth': entrypoint.resetAuth,
|
||||||
'play': entrypoint.doPlayback,
|
'play': entrypoint.doPlayback,
|
||||||
'passwords': utils.passwordsXML,
|
'passwords': utils.passwordsXML,
|
||||||
|
|
|
@ -4,10 +4,16 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
from contextlib import closing
|
||||||
|
import sys
|
||||||
|
|
||||||
import xbmc
|
import xbmc
|
||||||
|
import xbmcaddon
|
||||||
|
import xbmcgui
|
||||||
|
import xbmcplugin
|
||||||
|
import xbmcvfs
|
||||||
|
|
||||||
from utils import window, should_stop, settings
|
from utils import window, should_stop, settings, language, deletePlaylists, deleteNodes
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
|
@ -120,8 +126,98 @@ class DatabaseConn(object):
|
||||||
|
|
||||||
if self.commit_on_close == True and changes:
|
if self.commit_on_close == True and changes:
|
||||||
log.info("number of rows updated: %s", changes)
|
log.info("number of rows updated: %s", changes)
|
||||||
kodi_commit()
|
if self.db_file == "video":
|
||||||
|
kodi_commit()
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
log.info("close: %s", self.path)
|
log.info("close: %s", self.path)
|
||||||
self.conn.close()
|
self.conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def db_reset():
|
||||||
|
|
||||||
|
dialog = xbmcgui.Dialog()
|
||||||
|
|
||||||
|
if not dialog.yesno(language(29999), language(33074)):
|
||||||
|
return
|
||||||
|
|
||||||
|
# first stop any db sync
|
||||||
|
window('emby_online', value="reset")
|
||||||
|
window('emby_shouldStop', value="true")
|
||||||
|
count = 10
|
||||||
|
while window('emby_dbScan') == "true":
|
||||||
|
log.info("Sync is running, will retry: %s..." % count)
|
||||||
|
count -= 1
|
||||||
|
if count == 0:
|
||||||
|
dialog.ok(language(29999), language(33085))
|
||||||
|
return
|
||||||
|
xbmc.sleep(1000)
|
||||||
|
|
||||||
|
# Clean up the playlists
|
||||||
|
deletePlaylists()
|
||||||
|
|
||||||
|
# Clean up the video nodes
|
||||||
|
deleteNodes()
|
||||||
|
|
||||||
|
# Wipe the kodi databases
|
||||||
|
log.warn("Resetting the Kodi video database.")
|
||||||
|
with DatabaseConn('video') as conn:
|
||||||
|
with closing(conn.cursor()) as cursor:
|
||||||
|
cursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
for row in rows:
|
||||||
|
tablename = row[0]
|
||||||
|
if tablename != "version":
|
||||||
|
cursor.execute("DELETE FROM " + tablename)
|
||||||
|
|
||||||
|
if settings('enableMusic') == "true":
|
||||||
|
log.warn("Resetting the Kodi music database.")
|
||||||
|
with DatabaseConn('music') as conn:
|
||||||
|
with closing(conn.cursor()) as cursor:
|
||||||
|
cursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
for row in rows:
|
||||||
|
tablename = row[0]
|
||||||
|
if tablename != "version":
|
||||||
|
cursor.execute("DELETE FROM " + tablename)
|
||||||
|
|
||||||
|
# Wipe the emby database
|
||||||
|
log.warn("Resetting the Emby database.")
|
||||||
|
with DatabaseConn('emby') as conn:
|
||||||
|
with closing(conn.cursor()) as cursor:
|
||||||
|
cursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
for row in rows:
|
||||||
|
tablename = row[0]
|
||||||
|
if tablename != "version":
|
||||||
|
cursor.execute("DELETE FROM " + tablename)
|
||||||
|
cursor.execute('DROP table IF EXISTS emby')
|
||||||
|
cursor.execute('DROP table IF EXISTS view')
|
||||||
|
cursor.execute("DROP table IF EXISTS version")
|
||||||
|
|
||||||
|
# Offer to wipe cached thumbnails
|
||||||
|
if dialog.yesno(language(29999), language(33086)):
|
||||||
|
log.warn("Resetting all cached artwork")
|
||||||
|
# Remove all existing textures first
|
||||||
|
import artwork
|
||||||
|
artwork.Artwork().delete_cache()
|
||||||
|
|
||||||
|
# reset the install run flag
|
||||||
|
settings('SyncInstallRunDone', value="false")
|
||||||
|
|
||||||
|
# Remove emby info
|
||||||
|
resp = dialog.yesno(language(29999), language(33087))
|
||||||
|
if resp:
|
||||||
|
import connectmanager
|
||||||
|
# Delete the settings
|
||||||
|
addon = xbmcaddon.Addon()
|
||||||
|
addondir = xbmc.translatePath(
|
||||||
|
"special://profile/addon_data/plugin.video.emby/").decode('utf-8')
|
||||||
|
dataPath = "%ssettings.xml" % addondir
|
||||||
|
xbmcvfs.delete(dataPath)
|
||||||
|
connectmanager.ConnectManager().clear_data()
|
||||||
|
|
||||||
|
dialog.ok(heading=language(29999), line1=language(33088))
|
||||||
|
xbmc.executebuiltin('RestartApp')
|
||||||
|
return xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, xbmcgui.ListItem())
|
||||||
|
|
|
@ -933,7 +933,7 @@ class LibrarySync(threading.Thread):
|
||||||
log.warn("Database version is out of date! USER IGNORED!")
|
log.warn("Database version is out of date! USER IGNORED!")
|
||||||
dialog.ok(lang(29999), lang(33023))
|
dialog.ok(lang(29999), lang(33023))
|
||||||
else:
|
else:
|
||||||
utils.reset()
|
database.db_reset()
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
|
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
@ -15,6 +14,7 @@ import unicodedata
|
||||||
import xml.etree.ElementTree as etree
|
import xml.etree.ElementTree as etree
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
import xbmc
|
import xbmc
|
||||||
import xbmcaddon
|
import xbmcaddon
|
||||||
import xbmcgui
|
import xbmcgui
|
||||||
|
@ -280,99 +280,6 @@ def profiling(sortby="cumulative"):
|
||||||
#################################################################################################
|
#################################################################################################
|
||||||
# Addon utilities
|
# Addon utilities
|
||||||
|
|
||||||
def reset():
|
|
||||||
|
|
||||||
dialog = xbmcgui.Dialog()
|
|
||||||
|
|
||||||
if not dialog.yesno(language(29999), language(33074)):
|
|
||||||
return
|
|
||||||
|
|
||||||
# first stop any db sync
|
|
||||||
window('emby_online', value="reset")
|
|
||||||
window('emby_shouldStop', value="true")
|
|
||||||
count = 10
|
|
||||||
while window('emby_dbScan') == "true":
|
|
||||||
log.info("Sync is running, will retry: %s..." % count)
|
|
||||||
count -= 1
|
|
||||||
if count == 0:
|
|
||||||
dialog.ok(language(29999), language(33085))
|
|
||||||
return
|
|
||||||
xbmc.sleep(1000)
|
|
||||||
|
|
||||||
# Clean up the playlists
|
|
||||||
deletePlaylists()
|
|
||||||
|
|
||||||
# Clean up the video nodes
|
|
||||||
deleteNodes()
|
|
||||||
|
|
||||||
# Wipe the kodi databases
|
|
||||||
log.warn("Resetting the Kodi video database.")
|
|
||||||
connection = kodiSQL('video')
|
|
||||||
cursor = connection.cursor()
|
|
||||||
cursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
|
|
||||||
rows = cursor.fetchall()
|
|
||||||
for row in rows:
|
|
||||||
tablename = row[0]
|
|
||||||
if tablename != "version":
|
|
||||||
cursor.execute("DELETE FROM " + tablename)
|
|
||||||
connection.commit()
|
|
||||||
cursor.close()
|
|
||||||
|
|
||||||
if settings('enableMusic') == "true":
|
|
||||||
log.warn("Resetting the Kodi music database.")
|
|
||||||
connection = kodiSQL('music')
|
|
||||||
cursor = connection.cursor()
|
|
||||||
cursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
|
|
||||||
rows = cursor.fetchall()
|
|
||||||
for row in rows:
|
|
||||||
tablename = row[0]
|
|
||||||
if tablename != "version":
|
|
||||||
cursor.execute("DELETE FROM " + tablename)
|
|
||||||
connection.commit()
|
|
||||||
cursor.close()
|
|
||||||
|
|
||||||
# Wipe the emby database
|
|
||||||
log.warn("Resetting the Emby database.")
|
|
||||||
connection = kodiSQL('emby')
|
|
||||||
cursor = connection.cursor()
|
|
||||||
cursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
|
|
||||||
rows = cursor.fetchall()
|
|
||||||
for row in rows:
|
|
||||||
tablename = row[0]
|
|
||||||
if tablename != "version":
|
|
||||||
cursor.execute("DELETE FROM " + tablename)
|
|
||||||
cursor.execute('DROP table IF EXISTS emby')
|
|
||||||
cursor.execute('DROP table IF EXISTS view')
|
|
||||||
cursor.execute("DROP table IF EXISTS version")
|
|
||||||
connection.commit()
|
|
||||||
cursor.close()
|
|
||||||
|
|
||||||
# Offer to wipe cached thumbnails
|
|
||||||
if dialog.yesno(language(29999), language(33086)):
|
|
||||||
log.warn("Resetting all cached artwork")
|
|
||||||
# Remove all existing textures first
|
|
||||||
import artwork
|
|
||||||
artwork.Artwork().delete_cache()
|
|
||||||
|
|
||||||
# reset the install run flag
|
|
||||||
settings('SyncInstallRunDone', value="false")
|
|
||||||
|
|
||||||
# Remove emby info
|
|
||||||
resp = dialog.yesno(language(29999), language(33087))
|
|
||||||
if resp:
|
|
||||||
import connectmanager
|
|
||||||
# Delete the settings
|
|
||||||
addon = xbmcaddon.Addon()
|
|
||||||
addondir = xbmc.translatePath(
|
|
||||||
"special://profile/addon_data/plugin.video.emby/").decode('utf-8')
|
|
||||||
dataPath = "%ssettings.xml" % addondir
|
|
||||||
xbmcvfs.delete(dataPath)
|
|
||||||
connectmanager.ConnectManager().clear_data()
|
|
||||||
|
|
||||||
dialog.ok(heading=language(29999), line1=language(33088))
|
|
||||||
xbmc.executebuiltin('RestartApp')
|
|
||||||
return xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, xbmcgui.ListItem())
|
|
||||||
|
|
||||||
def sourcesXML():
|
def sourcesXML():
|
||||||
# To make Master lock compatible
|
# To make Master lock compatible
|
||||||
path = xbmc.translatePath("special://profile/").decode('utf-8')
|
path = xbmc.translatePath("special://profile/").decode('utf-8')
|
||||||
|
|
Loading…
Reference in a new issue