Skip to content

Commit

Permalink
Adjust database discovery
Browse files Browse the repository at this point in the history
Compare loaded vs discovered to avoid loading old databases by accident.
  • Loading branch information
tamara-plante committed Jan 12, 2019
1 parent c0e979c commit ff9120c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
31 changes: 18 additions & 13 deletions resources/lib/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ def _discover_database(self, database):
modified['time'] = modified_int
modified['file'] = file.decode('utf-8')

LOG.info("Loading discovered database: %s", modified)
LOG.info("Discovered database: %s", modified)
self.discovered = True

return xbmc.translatePath("special://database/%s" % modified['file'])
return xbmc.translatePath("special://database/%s" % modified['file']).decode('utf-8')

def _sql(self, file):

Expand All @@ -122,29 +122,34 @@ def _sql(self, file):
'''
databases = obj.Objects().objects

try:
return self._get_database(databases[file]) if file in databases else file
if file not in ('video', 'music', 'texture') or databases.get('database_set%s' % file):
return self._get_database(databases[file], True)

discovered = self._discover_database(file) if not databases.get('database_set%s' % file) else None

try:
loaded = self._get_database(databases[file]) if file in databases else file
except Exception as error:
LOG.error(error)

for i in range(1, 10):
alt_file = "%s-%s" % (file, i)

try:
if file not in ('video', 'music', 'texture'):
return self._get_database(databases[file], True)

databases[file] = self._get_database(databases[alt_file])

return databases[file]
loaded = self._get_database(databases[alt_file])
except KeyError: # No other db options
databases[file] = self._discover_database(file)
return databases[file]
loaded = None

break
except Exception:
pass

databases[file] = discovered if discovered and discovered != loaded else loaded
databases['database_set%s' % file] = True
LOG.info("Database locked in: %s", databases[file])

return databases[file]

def __exit__(self, exc_type, exc_val, exc_tb):

''' Close the connection and cursor.
Expand Down
2 changes: 2 additions & 0 deletions resources/lib/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def test_databases(self):

LOG.info("Newly discovered database: %s", kodidb.path)
settings('DiscoveredDatabase', kodidb.path)
self.monitor.settings['enable_db_discovery'] = True
settings('AskDiscoverDatabase.bool', True)

return False
else:
Expand Down

0 comments on commit ff9120c

Please sign in to comment.