mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2025-09-18 12:34:39 +00:00
Restructure stop decorator and LibraryException
This commit is contained in:
parent
209994f67d
commit
3de5b2e43d
5 changed files with 67 additions and 46 deletions
|
@ -13,7 +13,12 @@ from .objects import Movies, TVShows, MusicVideos, Music
|
|||
from .database import Database, get_sync, save_sync, jellyfin_db
|
||||
from .helper import translate, settings, window, progress, dialog, LazyLogger, xmls
|
||||
from .helper.utils import get_screensaver, set_screensaver
|
||||
from .helper.exceptions import LibraryException, PathValidationException
|
||||
from .helper.exceptions import (
|
||||
LibraryException,
|
||||
LibraryExitException,
|
||||
LibrarySyncLaterException,
|
||||
PathValidationException,
|
||||
)
|
||||
|
||||
##################################################################################################
|
||||
|
||||
|
@ -169,11 +174,13 @@ class FullSync(object):
|
|||
selection = dialog("multi", translate(33120), choices)
|
||||
|
||||
if selection is None:
|
||||
raise LibraryException("LibrarySelection")
|
||||
# TODO: Why are we handling these two differently?
|
||||
# presumably one means the dialog got aborted, the other means that we just pressed ok without selecting any libraries
|
||||
raise LibraryException("Library selection dialog returned None.")
|
||||
elif not selection:
|
||||
LOG.info("Nothing was selected.")
|
||||
|
||||
raise LibraryException("SyncLibraryLater")
|
||||
raise LibrarySyncLaterException("No libraries where selected, sync later.")
|
||||
|
||||
if 0 in selection:
|
||||
selection = list(range(1, len(libraries) + 1))
|
||||
|
@ -275,11 +282,13 @@ class FullSync(object):
|
|||
|
||||
media[library["CollectionType"]](library)
|
||||
except LibraryException as error:
|
||||
|
||||
if error.status == "StopCalled":
|
||||
# TODO: Fixme; We're catching all LibraryException here,
|
||||
# but silently ignoring any that isn't the exit condition.
|
||||
# Investigate what would be appropriate behavior here.
|
||||
if isinstance(error, LibraryExitException):
|
||||
save_sync(self.sync)
|
||||
|
||||
raise
|
||||
LOG.warning("Ignoring exception %s", error)
|
||||
|
||||
except PathValidationException:
|
||||
raise
|
||||
|
|
|
@ -19,9 +19,15 @@ class HTTPException(Exception):
|
|||
|
||||
|
||||
class LibraryException(Exception):
|
||||
# Jellyfin library sync exception
|
||||
def __init__(self, status):
|
||||
self.status = status
|
||||
pass
|
||||
|
||||
|
||||
class LibraryExitException(LibraryException):
|
||||
"Exception raised to propagate application exit."
|
||||
|
||||
|
||||
class LibrarySyncLaterException(LibraryException):
|
||||
"Raised when no libraries are selected for sync."
|
||||
|
||||
|
||||
class PathValidationException(Exception):
|
||||
|
@ -30,5 +36,3 @@ class PathValidationException(Exception):
|
|||
|
||||
TODO: Investigate the usage of this to see if it can be done better.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
|
|
@ -162,18 +162,6 @@ def dialog(dialog_type, *args, **kwargs):
|
|||
return types[dialog_type](*args, **kwargs)
|
||||
|
||||
|
||||
def should_stop():
|
||||
"""Checkpoint during the sync process."""
|
||||
if xbmc.Monitor().waitForAbort(0.00001):
|
||||
return True
|
||||
|
||||
if window("jellyfin_should_stop.bool"):
|
||||
LOG.info("exiiiiitttinggg")
|
||||
return True
|
||||
|
||||
return not window("jellyfin_online.bool")
|
||||
|
||||
|
||||
def get_screensaver():
|
||||
"""Get the current screensaver value."""
|
||||
result = JSONRPC("Settings.getSettingValue").execute(
|
||||
|
|
|
@ -4,11 +4,12 @@ from __future__ import division, absolute_import, print_function, unicode_litera
|
|||
#################################################################################################
|
||||
|
||||
import xbmcgui
|
||||
import xbmc
|
||||
|
||||
from . import LazyLogger
|
||||
|
||||
from .utils import should_stop
|
||||
from .exceptions import LibraryException
|
||||
from .utils import window
|
||||
from .exceptions import LibraryExitException
|
||||
from .translate import translate
|
||||
|
||||
#################################################################################################
|
||||
|
@ -55,14 +56,15 @@ def stop(func):
|
|||
|
||||
def wrapper(*args, **kwargs):
|
||||
|
||||
try:
|
||||
if should_stop(): # ??? TODO: Fixme
|
||||
raise Exception
|
||||
if xbmc.Monitor().waitForAbort(0.00001):
|
||||
raise LibraryExitException("Kodi aborted, exiting...")
|
||||
|
||||
except Exception as error:
|
||||
LOG.exception(error)
|
||||
if window("jellyfin_should_stop.bool"):
|
||||
LOG.info("exiiiiitttinggg")
|
||||
raise LibraryExitException("Should stop flag raised, exiting...")
|
||||
|
||||
raise LibraryException("StopCalled")
|
||||
if not window("jellyfin_online.bool"):
|
||||
raise LibraryExitException("Jellyfin not online, exiting...")
|
||||
|
||||
return func(*args, **kwargs)
|
||||
|
||||
|
|
|
@ -19,7 +19,11 @@ from .views import Views
|
|||
from .downloader import GetItemWorker
|
||||
from .helper import translate, api, stop, settings, window, dialog, event, LazyLogger
|
||||
from .helper.utils import split_list, set_screensaver, get_screensaver
|
||||
from .helper.exceptions import LibraryException
|
||||
from .helper.exceptions import (
|
||||
LibraryException,
|
||||
LibraryExitException,
|
||||
LibrarySyncLaterException,
|
||||
)
|
||||
from .jellyfin import Jellyfin
|
||||
|
||||
##################################################################################################
|
||||
|
@ -93,7 +97,8 @@ class Library(threading.Thread):
|
|||
|
||||
try:
|
||||
self.service()
|
||||
except LibraryException:
|
||||
except LibraryException as error:
|
||||
LOG.warning(error)
|
||||
break
|
||||
except Exception as error:
|
||||
LOG.exception(error)
|
||||
|
@ -438,19 +443,20 @@ class Library(threading.Thread):
|
|||
return True
|
||||
|
||||
return True
|
||||
|
||||
except LibrarySyncLaterException as error:
|
||||
LOG.error(error.status)
|
||||
dialog("ok", "{jellyfin}", translate(33129))
|
||||
settings("SyncInstallRunDone.bool", True)
|
||||
sync = get_sync()
|
||||
sync["Libraries"] = []
|
||||
save_sync(sync)
|
||||
|
||||
return True
|
||||
|
||||
except LibraryException as error:
|
||||
LOG.error(error.status)
|
||||
|
||||
if error.status in "SyncLibraryLater":
|
||||
|
||||
dialog("ok", "{jellyfin}", translate(33129))
|
||||
settings("SyncInstallRunDone.bool", True)
|
||||
sync = get_sync()
|
||||
sync["Libraries"] = []
|
||||
save_sync(sync)
|
||||
|
||||
return True
|
||||
|
||||
except Exception as error:
|
||||
LOG.exception(error)
|
||||
|
||||
|
@ -758,8 +764,12 @@ class UpdateWorker(threading.Thread):
|
|||
(item["Type"], api.API(item).get_naming())
|
||||
)
|
||||
except LibraryException as error:
|
||||
if error.status == "StopCalled":
|
||||
# TODO: Fixme; We're catching all LibraryException here,
|
||||
# but silently ignoring any that isn't the exit condition.
|
||||
# Investigate what would be appropriate behavior here.
|
||||
if isinstance(error, LibraryExitException):
|
||||
break
|
||||
LOG.warning("Ignoring exception %s", error)
|
||||
except Exception as error:
|
||||
LOG.exception(error)
|
||||
|
||||
|
@ -823,8 +833,12 @@ class UserDataWorker(threading.Thread):
|
|||
elif item["Type"] == "Audio":
|
||||
music.userdata(item)
|
||||
except LibraryException as error:
|
||||
if error.status == "StopCalled":
|
||||
# TODO: Fixme; We're catching all LibraryException here,
|
||||
# but silently ignoring any that isn't the exit condition.
|
||||
# Investigate what would be appropriate behavior here.
|
||||
if isinstance(error, LibraryExitException):
|
||||
break
|
||||
LOG.warning("Ignoring exception %s", error)
|
||||
except Exception as error:
|
||||
LOG.exception(error)
|
||||
|
||||
|
@ -943,8 +957,12 @@ class RemovedWorker(threading.Thread):
|
|||
try:
|
||||
obj(item["Id"])
|
||||
except LibraryException as error:
|
||||
if error.status == "StopCalled":
|
||||
# TODO: Fixme; We're catching all LibraryException here,
|
||||
# but silently ignoring any that isn't the exit condition.
|
||||
# Investigate what would be appropriate behavior here.
|
||||
if isinstance(error, LibraryExitException):
|
||||
break
|
||||
LOG.warning("Ignoring exception %s", error)
|
||||
except Exception as error:
|
||||
LOG.exception(error)
|
||||
finally:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue