Wipe Kodi database on first PKC run

- Fixes #543
This commit is contained in:
croneter 2018-10-06 15:47:41 +02:00
parent ab81c88b8f
commit 8d9d135595
2 changed files with 31 additions and 0 deletions

View file

@ -638,6 +638,10 @@ class InitialSetup(object):
# Make sure that we only ask these questions upon first installation # Make sure that we only ask these questions upon first installation
utils.settings('InstallQuestionsAnswered', value='true') utils.settings('InstallQuestionsAnswered', value='true')
# New installation - make sure we start with a clean slate
from . import kodidb_functions
kodidb_functions.wipe_kodi_dbs()
if goto_settings is False: if goto_settings is False:
# Open Settings page now? You will need to restart! # Open Settings page now? You will need to restart!
goto_settings = utils.yesno_dialog(utils.lang(29999), goto_settings = utils.yesno_dialog(utils.lang(29999),

View file

@ -1253,3 +1253,30 @@ def kodiid_from_filename(path, kodi_type=None, db_type=None):
except TypeError: except TypeError:
LOG.debug('No kodi video db element found for path %s', path) LOG.debug('No kodi video db element found for path %s', path)
return kodi_id, kodi_type return kodi_id, kodi_type
def wipe_kodi_dbs():
"""
Completely resets the Kodi databases 'video', 'texture' and 'music' (if
music sync is enabled)
"""
LOG.warn('Wiping Kodi databases!')
query = "SELECT name FROM sqlite_master WHERE type = 'table'"
kinds = ['video', 'texture']
if state.ENABLE_MUSIC:
LOG.info('Also deleting music database')
kinds.append('music')
for db in kinds:
with GetKodiDB(db) as kodi_db:
kodi_db.cursor.execute(query)
tables = kodi_db.cursor.fetchall()
tables = [i[0] for i in tables]
if 'version' in tables:
tables.remove('version')
for table in tables:
delete_query = 'DELETE FROM %s' % table
kodi_db.cursor.execute(delete_query)
import xbmc
xbmc.executebuiltin('UpdateLibrary(video)')
if state.ENABLE_MUSIC:
xbmc.executebuiltin('UpdateLibrary(music)')