Add indicator for sync

This commit is contained in:
angelblue05 2019-01-25 05:32:29 -06:00
parent 033d29ede8
commit c940578ecf
3 changed files with 46 additions and 33 deletions

View file

@ -498,11 +498,11 @@ class Service(xbmc.Monitor):
window('emby_should_stop.bool', True) window('emby_should_stop.bool', True)
properties = [ # TODO: review properties = [ # TODO: review
"emby_state", "emby_serverStatus", "emby_state", "emby_serverStatus", "emby_currUser",
"emby_syncRunning", "emby_currUser",
"emby_play", "emby_online", "emby.connected", "emby.resume", "emby_startup", "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: for prop in properties:
window(prop, clear=True) window(prop, clear=True)

View file

@ -14,7 +14,7 @@ import downloader as server
import helper.xmls as xmls import helper.xmls as xmls
from database import Database, get_sync, save_sync, emby_db from database import Database, get_sync, save_sync, emby_db
from objects import Movies, TVShows, MusicVideos, Music 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 helper.utils import get_screensaver, set_screensaver
from emby import Emby from emby import Emby
@ -31,12 +31,20 @@ class FullSync(object):
_shared_state = {} _shared_state = {}
sync = None sync = None
running = False running = False
screensaver = None
def __init__(self, library, library_id=None, update=False): def __init__(self, library, library_id=None, update=False):
''' Map the syncing process and start the sync. Ensure only one sync is running. ''' Map the syncing process and start the sync. Ensure only one sync is running.
''' '''
self.__dict__ = self._shared_state 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: if not self.running:
@ -162,32 +170,15 @@ class FullSync(object):
save_sync(self.sync) save_sync(self.sync)
start_time = datetime.datetime.now() start_time = datetime.datetime.now()
if not settings('dbSyncScreensaver.bool'): for library in list(self.sync['Libraries']):
xbmc.executebuiltin('InhibitIdleShutdown(true)') self.process_library(library)
screensaver = get_screensaver()
set_screensaver(value="")
try: if not library.startswith('Boxsets:') and library not in self.sync['Whitelist']:
for library in list(self.sync['Libraries']): self.sync['Whitelist'].append(library)
self.process_library(library) self.sync['Libraries'].pop(self.sync['Libraries'].index(library))
self.sync['RestorePoint'] = {}
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
elapsed = datetime.datetime.now() - start_time elapsed = datetime.datetime.now() - start_time
settings('SyncInstallRunDone.bool', True) settings('SyncInstallRunDone.bool', True)
@ -198,7 +189,6 @@ class FullSync(object):
dialog("notification", heading="{emby}", message="%s %s" % (_(33025), str(elapsed).split('.')[0]), dialog("notification", heading="{emby}", message="%s %s" % (_(33025), str(elapsed).split('.')[0]),
icon="{emby}", sound=False) icon="{emby}", sound=False)
LOG.info("Full sync completed in: %s", str(elapsed).split('.')[0]) LOG.info("Full sync completed in: %s", str(elapsed).split('.')[0])
self.running = False
def process_library(self, library_id): def process_library(self, library_id):
@ -249,6 +239,19 @@ class FullSync(object):
raise 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() @progress()
def movies(self, library, dialog): def movies(self, library, dialog):

View file

@ -173,6 +173,7 @@ class Library(threading.Thread):
self.pending_refresh = False self.pending_refresh = False
self.save_last_sync() self.save_last_sync()
self.total_updates = 0 self.total_updates = 0
window('emby_sync', clear=True)
if self.progress_updates: if self.progress_updates:
@ -196,6 +197,13 @@ class Library(threading.Thread):
def stop_client(self): def stop_client(self):
self.stop_thread = True 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): def worker_queue_size(self):
''' Get how many items are queued up for worker threads. ''' Get how many items are queued up for worker threads.
@ -251,7 +259,7 @@ class Library(threading.Thread):
new_thread.start() new_thread.start()
LOG.info("-->[ q:updated/%s/%s ]", queues, id(new_thread)) LOG.info("-->[ q:updated/%s/%s ]", queues, id(new_thread))
self.writer_threads['updated'].append(new_thread) self.writer_threads['updated'].append(new_thread)
self.pending_refresh = True self.enable_pending_refresh()
def worker_userdata(self): def worker_userdata(self):
@ -270,7 +278,7 @@ class Library(threading.Thread):
new_thread.start() new_thread.start()
LOG.info("-->[ q:userdata/%s/%s ]", queues, id(new_thread)) LOG.info("-->[ q:userdata/%s/%s ]", queues, id(new_thread))
self.writer_threads['userdata'].append(new_thread) self.writer_threads['userdata'].append(new_thread)
self.pending_refresh = True self.enable_pending_refresh()
def worker_remove(self): def worker_remove(self):
@ -289,7 +297,7 @@ class Library(threading.Thread):
new_thread.start() new_thread.start()
LOG.info("-->[ q:removed/%s/%s ]", queues, id(new_thread)) LOG.info("-->[ q:removed/%s/%s ]", queues, id(new_thread))
self.writer_threads['removed'].append(new_thread) self.writer_threads['removed'].append(new_thread)
self.pending_refresh = True self.enable_pending_refresh()
def worker_notify(self): def worker_notify(self):
@ -517,6 +525,7 @@ class Library(threading.Thread):
@progress(_(33144)) @progress(_(33144))
def remove_library(self, library_id, dialog): def remove_library(self, library_id, dialog):
window('emby_sync.bool', True)
try: try:
with Database('emby') as embydb: with Database('emby') as embydb:
@ -572,10 +581,11 @@ class Library(threading.Thread):
except Exception as error: except Exception as error:
LOG.exception(error) LOG.exception(error)
dialog.close() window('emby_sync', clear=True)
return False return False
window('emby_sync', clear=True)
Views().get_views() Views().get_views()
Views().get_nodes() Views().get_nodes()