Fix OperationalError and PKC not starting up

This commit is contained in:
croneter 2018-12-10 20:32:59 +01:00
parent 531b2dedb3
commit b87ba4c753

View file

@ -105,33 +105,32 @@ def wipe_dbs(music=True):
""" """
Completely resets the Kodi databases 'video', 'texture' and 'music' (if Completely resets the Kodi databases 'video', 'texture' and 'music' (if
music sync is enabled) music sync is enabled)
DO NOT use context menu as we need to connect without WAL mode - if Kodi
is still accessing the DB
""" """
from sqlite3 import connect
LOG.warn('Wiping Kodi databases!') LOG.warn('Wiping Kodi databases!')
kinds = [KodiVideoDB, KodiTextureDB] kinds = [v.DB_VIDEO_PATH, v.DB_TEXTURE_PATH]
if music: if music:
kinds.append(KodiMusicDB) kinds.append(v.DB_TEXTURE_PATH)
for db in kinds: for path in kinds:
with db() as kodidb: conn = connect(path, timeout=5.0)
kodidb.cursor.execute("SELECT name FROM sqlite_master WHERE type = 'table'") cursor = conn.cursor()
tables = kodidb.cursor.fetchall() cursor.execute("SELECT name FROM sqlite_master WHERE type = 'table'")
tables = [i[0] for i in tables] tables = cursor.fetchall()
if 'version' in tables: tables = [i[0] for i in tables]
tables.remove('version') if 'version' in tables:
if 'versiontagscan' in tables: tables.remove('version')
tables.remove('versiontagscan') if 'versiontagscan' in tables:
for table in tables: tables.remove('versiontagscan')
kodidb.cursor.execute('DELETE FROM %s' % table) for table in tables:
cursor.execute('DELETE FROM %s' % table)
conn.commit()
conn.close()
setup_kodi_default_entries() setup_kodi_default_entries()
# Delete SQLITE wal files # Delete SQLITE wal files
import xbmc import xbmc
db_dir = xbmc.translatePath('special://database').decode('utf-8')
for root, _, files in path_ops.walk(db_dir):
for file in files:
if path_ops.path.splitext(file)[1].lower() in ('.db-shm', '.db-wal'):
try:
path_ops.remove(path_ops.path.join(root, file))
except OSError:
LOG.info('Could not delete temp DB file %s', file)
# Make sure Kodi knows we wiped the databases # Make sure Kodi knows we wiped the databases
xbmc.executebuiltin('UpdateLibrary(video)') xbmc.executebuiltin('UpdateLibrary(video)')
if utils.settings('enableMusic') == 'true': if utils.settings('enableMusic') == 'true':