diff --git a/resources/lib/database/__init__.py b/resources/lib/database/__init__.py index 1eedad8e..b88b6d0b 100644 --- a/resources/lib/database/__init__.py +++ b/resources/lib/database/__init__.py @@ -99,7 +99,8 @@ class Database(object): modified = {'file': None, 'time': 0} for file in reversed(files): - if file.startswith(database) and not file.endswith('-wal') and not file.endswith('-shm'): + if (file.startswith(database) and not file.endswith('-wal') and + not file.endswith('-shm') and not file.endswith('db-journal')): st = xbmcvfs.Stat(databases + file.decode('utf-8')) modified_int = st.st_mtime() diff --git a/resources/lib/entrypoint/service.py b/resources/lib/entrypoint/service.py index 3aee5691..e6efa3e9 100644 --- a/resources/lib/entrypoint/service.py +++ b/resources/lib/entrypoint/service.py @@ -200,7 +200,7 @@ class Service(xbmc.Monitor): return False get_objects(zipfile, label + '.zip') - reload(objects) # to apply latest changes + self.reload_objects() dialog("notification", heading="{emby}", message=_(33156), icon="{emby}") LOG.info("--[ new objects/%s ]", objects.version) @@ -477,6 +477,30 @@ class Service(xbmc.Monitor): if not self.settings['kodi_companion']: dialog("ok", heading="{emby}", line1=_(33138)) + def reload_objects(self): + + ''' Reload objects which depends on the patch module. + This allows to see the changes in code without restarting the python interpreter. + ''' + import full_sync + + reload_modules = ['objects.movies', 'objects.musicvideos', 'objects.tvshows', + 'objects.music', 'objects.obj', 'objects.actions', 'objects.kodi.kodi', + 'objects.kodi.movies', 'objects.kodi.musicvideos', 'objects.kodi.tvshows', + 'objects.kodi.music', 'objects.kodi.artwork', 'objects.kodi.queries', + 'objects.kodi.queries_music', 'objects.kodi.queries_texture'] + + for mod in reload_modules: + del sys.modules[mod] + + reload(objects.kodi) + reload(objects) + reload(library) + reload(full_sync) + reload(monitor) + + LOG.warn("---[ objects reloaded ]") + def shutdown(self): LOG.warn("---<[ EXITING ]") diff --git a/service.py b/service.py index e88b2936..8f6c7dd6 100644 --- a/service.py +++ b/service.py @@ -65,6 +65,8 @@ class ServiceManager(threading.Thread): if not 'ExitService' in error and service is not None: service.shutdown() + elif 'RestartService' in error: + service.reload_objects() self.exception = error @@ -82,31 +84,6 @@ if __name__ == "__main__": session.join() # Block until the thread exits. if 'RestartService' in session.exception: - - ''' Reload objects which depends on the patch module. - ''' - LOG.warn("--[ RESTART ]") - - import objects - import library - import full_sync - import monitor - - reload_modules = ['objects.movies', 'objects.musicvideos', 'objects.tvshows', - 'objects.music', 'objects.obj', 'objects.actions', 'objects.kodi.kodi', - 'objects.kodi.movies', 'objects.kodi.musicvideos', 'objects.kodi.tvshows', - 'objects.kodi.music', 'objects.kodi.artwork', 'objects.kodi.queries', - 'objects.kodi.queries_music', 'objects.kodi.queries_texture'] - - for mod in reload_modules: - del sys.modules[mod] - - reload(objects.kodi) - reload(objects) - reload(library) - reload(full_sync) - reload(monitor) - continue except Exception as error: