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)
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)

View file

@ -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):

View file

@ -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()