From c940578ecf2d1510c07d61a32d63718903448b48 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Fri, 25 Jan 2019 05:32:29 -0600 Subject: [PATCH] Add indicator for sync --- resources/lib/entrypoint/service.py | 6 ++-- resources/lib/full_sync.py | 53 +++++++++++++++-------------- resources/lib/library.py | 20 ++++++++--- 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/resources/lib/entrypoint/service.py b/resources/lib/entrypoint/service.py index 66e0c410..ffc122d1 100644 --- a/resources/lib/entrypoint/service.py +++ b/resources/lib/entrypoint/service.py @@ -498,11 +498,11 @@ class Service(xbmc.Monitor): window('emby_should_stop.bool', True) properties = [ # TODO: review - "emby_state", "emby_serverStatus", - "emby_syncRunning", "emby_currUser", + "emby_state", "emby_serverStatus", "emby_currUser", "emby_play", "emby_online", "emby.connected", "emby.resume", "emby_startup", - "emby.external", "emby.external_check", "emby_deviceId", "emby_db_check", "emby_pathverified" + "emby.external", "emby.external_check", "emby_deviceId", "emby_db_check", "emby_pathverified", + "emby_sync" ] for prop in properties: window(prop, clear=True) diff --git a/resources/lib/full_sync.py b/resources/lib/full_sync.py index cf3bbd79..ec22882a 100644 --- a/resources/lib/full_sync.py +++ b/resources/lib/full_sync.py @@ -14,7 +14,7 @@ import downloader as server import helper.xmls as xmls from database import Database, get_sync, save_sync, emby_db from objects import Movies, TVShows, MusicVideos, Music -from helper import _, settings, progress, dialog, LibraryException +from helper import _, settings, window, progress, dialog, LibraryException from helper.utils import get_screensaver, set_screensaver from emby import Emby @@ -31,12 +31,20 @@ class FullSync(object): _shared_state = {} sync = None running = False + screensaver = None def __init__(self, library, library_id=None, update=False): ''' Map the syncing process and start the sync. Ensure only one sync is running. ''' self.__dict__ = self._shared_state + window('emby_sync.bool', True) + + if not settings('dbSyncScreensaver.bool'): + + xbmc.executebuiltin('InhibitIdleShutdown(true)') + self.screensaver = get_screensaver() + set_screensaver(value="") if not self.running: @@ -162,32 +170,15 @@ class FullSync(object): save_sync(self.sync) start_time = datetime.datetime.now() - if not settings('dbSyncScreensaver.bool'): + for library in list(self.sync['Libraries']): - xbmc.executebuiltin('InhibitIdleShutdown(true)') - screensaver = get_screensaver() - set_screensaver(value="") + self.process_library(library) - try: - for library in list(self.sync['Libraries']): + if not library.startswith('Boxsets:') and library not in self.sync['Whitelist']: + self.sync['Whitelist'].append(library) - self.process_library(library) - - if not library.startswith('Boxsets:') and library not in self.sync['Whitelist']: - self.sync['Whitelist'].append(library) - - self.sync['Libraries'].pop(self.sync['Libraries'].index(library)) - self.sync['RestorePoint'] = {} - except Exception as error: - - if not settings('dbSyncScreensaver.bool'): - - xbmc.executebuiltin('InhibitIdleShutdown(false)') - set_screensaver(value=screensaver) - - self.running = False - - raise + self.sync['Libraries'].pop(self.sync['Libraries'].index(library)) + self.sync['RestorePoint'] = {} elapsed = datetime.datetime.now() - start_time settings('SyncInstallRunDone.bool', True) @@ -198,7 +189,6 @@ class FullSync(object): dialog("notification", heading="{emby}", message="%s %s" % (_(33025), str(elapsed).split('.')[0]), icon="{emby}", sound=False) LOG.info("Full sync completed in: %s", str(elapsed).split('.')[0]) - self.running = False def process_library(self, library_id): @@ -249,6 +239,19 @@ class FullSync(object): raise + def __exit__(self, exc_type, exc_val, exc_tb): + + ''' Exiting sync + ''' + self.running = False + window('emby_sync', clear=True) + + if not settings('dbSyncScreensaver.bool'): + + xbmc.executebuiltin('InhibitIdleShutdown(false)') + set_screensaver(value=self.screensaver) + + @progress() def movies(self, library, dialog): diff --git a/resources/lib/library.py b/resources/lib/library.py index b63fe7e3..4cad0b7d 100644 --- a/resources/lib/library.py +++ b/resources/lib/library.py @@ -173,6 +173,7 @@ class Library(threading.Thread): self.pending_refresh = False self.save_last_sync() self.total_updates = 0 + window('emby_sync', clear=True) if self.progress_updates: @@ -196,6 +197,13 @@ class Library(threading.Thread): def stop_client(self): self.stop_thread = True + def enable_pending_refresh(self): + + ''' When there's an active thread. Let the main thread know. + ''' + self.pending_refresh = True + window('emby_sync.bool', True) + def worker_queue_size(self): ''' Get how many items are queued up for worker threads. @@ -251,7 +259,7 @@ class Library(threading.Thread): new_thread.start() LOG.info("-->[ q:updated/%s/%s ]", queues, id(new_thread)) self.writer_threads['updated'].append(new_thread) - self.pending_refresh = True + self.enable_pending_refresh() def worker_userdata(self): @@ -270,7 +278,7 @@ class Library(threading.Thread): new_thread.start() LOG.info("-->[ q:userdata/%s/%s ]", queues, id(new_thread)) self.writer_threads['userdata'].append(new_thread) - self.pending_refresh = True + self.enable_pending_refresh() def worker_remove(self): @@ -289,7 +297,7 @@ class Library(threading.Thread): new_thread.start() LOG.info("-->[ q:removed/%s/%s ]", queues, id(new_thread)) self.writer_threads['removed'].append(new_thread) - self.pending_refresh = True + self.enable_pending_refresh() def worker_notify(self): @@ -517,7 +525,8 @@ class Library(threading.Thread): @progress(_(33144)) def remove_library(self, library_id, dialog): - + window('emby_sync.bool', True) + try: with Database('emby') as embydb: @@ -572,10 +581,11 @@ class Library(threading.Thread): except Exception as error: LOG.exception(error) - dialog.close() + window('emby_sync', clear=True) return False + window('emby_sync', clear=True) Views().get_views() Views().get_nodes()