Refactoring: move all exceptions in a single module
This commit is contained in:
parent
9da61a059f
commit
176fa07e80
14 changed files with 63 additions and 43 deletions
|
@ -4,19 +4,13 @@ import sqlite3
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from . import variables as v, app
|
from . import variables as v, app
|
||||||
|
from .exceptions import LockedDatabase
|
||||||
|
|
||||||
DB_WRITE_ATTEMPTS = 100
|
DB_WRITE_ATTEMPTS = 100
|
||||||
DB_WRITE_ATTEMPTS_TIMEOUT = 1 # in seconds
|
DB_WRITE_ATTEMPTS_TIMEOUT = 1 # in seconds
|
||||||
DB_CONNECTION_TIMEOUT = 10
|
DB_CONNECTION_TIMEOUT = 10
|
||||||
|
|
||||||
|
|
||||||
class LockedDatabase(Exception):
|
|
||||||
"""
|
|
||||||
Dedicated class to make sure we're not silently catching locked DBs.
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def catch_operationalerrors(method):
|
def catch_operationalerrors(method):
|
||||||
"""
|
"""
|
||||||
sqlite.OperationalError is raised immediately if another DB connection
|
sqlite.OperationalError is raised immediately if another DB connection
|
||||||
|
|
32
resources/lib/exceptions.py
Normal file
32
resources/lib/exceptions.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import absolute_import, division, unicode_literals
|
||||||
|
|
||||||
|
|
||||||
|
class PlaylistError(Exception):
|
||||||
|
"""
|
||||||
|
Exception for our playlist constructs
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class LockedDatabase(Exception):
|
||||||
|
"""
|
||||||
|
Dedicated class to make sure we're not silently catching locked DBs.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class SubtitleError(Exception):
|
||||||
|
"""
|
||||||
|
Exceptions relating to subtitles
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ProcessingNotDone(Exception):
|
||||||
|
"""
|
||||||
|
Exception to detect whether we've completed our sync and did not have to
|
||||||
|
abort or suspend.
|
||||||
|
"""
|
||||||
|
pass
|
|
@ -20,6 +20,7 @@ from .downloadutils import DownloadUtils as DU
|
||||||
from . import utils, timing, plex_functions as PF
|
from . import utils, timing, plex_functions as PF
|
||||||
from . import json_rpc as js, playqueue as PQ, playlist_func as PL
|
from . import json_rpc as js, playqueue as PQ, playlist_func as PL
|
||||||
from . import backgroundthread, app, variables as v
|
from . import backgroundthread, app, variables as v
|
||||||
|
from . import exceptions
|
||||||
|
|
||||||
LOG = getLogger('PLEX.kodimonitor')
|
LOG = getLogger('PLEX.kodimonitor')
|
||||||
|
|
||||||
|
@ -181,7 +182,7 @@ class KodiMonitor(xbmc.Monitor):
|
||||||
try:
|
try:
|
||||||
for i, item in enumerate(items):
|
for i, item in enumerate(items):
|
||||||
PL.add_item_to_plex_playqueue(playqueue, i + 1, kodi_item=item)
|
PL.add_item_to_plex_playqueue(playqueue, i + 1, kodi_item=item)
|
||||||
except PL.PlaylistError:
|
except exceptions.PlaylistError:
|
||||||
LOG.info('Could not build Plex playlist for: %s', items)
|
LOG.info('Could not build Plex playlist for: %s', items)
|
||||||
|
|
||||||
def _json_item(self, playerid):
|
def _json_item(self, playerid):
|
||||||
|
@ -318,7 +319,7 @@ class KodiMonitor(xbmc.Monitor):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
item = PL.init_plex_playqueue(playqueue, plex_id=plex_id)
|
item = PL.init_plex_playqueue(playqueue, plex_id=plex_id)
|
||||||
except PL.PlaylistError:
|
except exceptions.PlaylistError:
|
||||||
LOG.info('Could not initialize the Plex playlist')
|
LOG.info('Could not initialize the Plex playlist')
|
||||||
return
|
return
|
||||||
item.file = path
|
item.file = path
|
||||||
|
|
|
@ -16,6 +16,7 @@ from .kodi_db import KodiVideoDB
|
||||||
from . import plex_functions as PF, playlist_func as PL, playqueue as PQ
|
from . import plex_functions as PF, playlist_func as PL, playqueue as PQ
|
||||||
from . import json_rpc as js, variables as v, utils, transfer
|
from . import json_rpc as js, variables as v, utils, transfer
|
||||||
from . import playback_decision, app
|
from . import playback_decision, app
|
||||||
|
from . import exceptions
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
LOG = getLogger('PLEX.playback')
|
LOG = getLogger('PLEX.playback')
|
||||||
|
@ -192,7 +193,7 @@ def _playback_init(plex_id, plex_type, playqueue, pos, resume):
|
||||||
# Special case - we already got a filled Kodi playqueue
|
# Special case - we already got a filled Kodi playqueue
|
||||||
try:
|
try:
|
||||||
_init_existing_kodi_playlist(playqueue, pos)
|
_init_existing_kodi_playlist(playqueue, pos)
|
||||||
except PL.PlaylistError:
|
except exceptions.PlaylistError:
|
||||||
LOG.error('Playback_init for existing Kodi playlist failed')
|
LOG.error('Playback_init for existing Kodi playlist failed')
|
||||||
_ensure_resolve(abort=True)
|
_ensure_resolve(abort=True)
|
||||||
return
|
return
|
||||||
|
@ -312,7 +313,7 @@ def _init_existing_kodi_playlist(playqueue, pos):
|
||||||
kodi_items = js.playlist_get_items(playqueue.playlistid)
|
kodi_items = js.playlist_get_items(playqueue.playlistid)
|
||||||
if not kodi_items:
|
if not kodi_items:
|
||||||
LOG.error('No Kodi items returned')
|
LOG.error('No Kodi items returned')
|
||||||
raise PL.PlaylistError('No Kodi items returned')
|
raise exceptions.PlaylistError('No Kodi items returned')
|
||||||
item = PL.init_plex_playqueue(playqueue, kodi_item=kodi_items[pos])
|
item = PL.init_plex_playqueue(playqueue, kodi_item=kodi_items[pos])
|
||||||
item.force_transcode = app.PLAYSTATE.force_transcode
|
item.force_transcode = app.PLAYSTATE.force_transcode
|
||||||
# playqueue.py will add the rest - this will likely put the PMS under
|
# playqueue.py will add the rest - this will likely put the PMS under
|
||||||
|
|
|
@ -15,19 +15,13 @@ from . import utils
|
||||||
from . import json_rpc as js
|
from . import json_rpc as js
|
||||||
from . import variables as v
|
from . import variables as v
|
||||||
from . import app
|
from . import app
|
||||||
|
from .exceptions import PlaylistError
|
||||||
from .subtitles import accessible_plex_subtitles
|
from .subtitles import accessible_plex_subtitles
|
||||||
|
|
||||||
|
|
||||||
LOG = getLogger('PLEX.playlist_func')
|
LOG = getLogger('PLEX.playlist_func')
|
||||||
|
|
||||||
|
|
||||||
class PlaylistError(Exception):
|
|
||||||
"""
|
|
||||||
Exception for our playlist constructs
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Playqueue_Object(object):
|
class Playqueue_Object(object):
|
||||||
"""
|
"""
|
||||||
PKC object to represent PMS playQueues and Kodi playlist for queueing
|
PKC object to represent PMS playQueues and Kodi playlist for queueing
|
||||||
|
|
|
@ -15,13 +15,13 @@ from __future__ import absolute_import, division, unicode_literals
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from sqlite3 import OperationalError
|
from sqlite3 import OperationalError
|
||||||
|
|
||||||
from .common import Playlist, PlaylistError, PlaylistObserver, \
|
from .common import Playlist, PlaylistObserver, kodi_playlist_hash
|
||||||
kodi_playlist_hash
|
|
||||||
from . import pms, db, kodi_pl, plex_pl
|
from . import pms, db, kodi_pl, plex_pl
|
||||||
|
|
||||||
from ..watchdog import events
|
from ..watchdog import events
|
||||||
from ..plex_api import API
|
from ..plex_api import API
|
||||||
from .. import utils, path_ops, variables as v, app
|
from .. import utils, path_ops, variables as v, app
|
||||||
|
from ..exceptions import PlaylistError
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
LOG = getLogger('PLEX.playlists')
|
LOG = getLogger('PLEX.playlists')
|
||||||
|
|
|
@ -12,6 +12,8 @@ from ..watchdog.observers import Observer
|
||||||
from ..watchdog.utils.bricks import OrderedSetQueue
|
from ..watchdog.utils.bricks import OrderedSetQueue
|
||||||
|
|
||||||
from .. import path_ops, variables as v, app
|
from .. import path_ops, variables as v, app
|
||||||
|
from ..exceptions import PlaylistError
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
LOG = getLogger('PLEX.playlists.common')
|
LOG = getLogger('PLEX.playlists.common')
|
||||||
|
|
||||||
|
@ -20,13 +22,6 @@ SIMILAR_EVENTS = (events.EVENT_TYPE_CREATED, events.EVENT_TYPE_MODIFIED)
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
class PlaylistError(Exception):
|
|
||||||
"""
|
|
||||||
The one main exception thrown if anything goes awry
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Playlist(object):
|
class Playlist(object):
|
||||||
"""
|
"""
|
||||||
Class representing a synced Playlist with info for both Kodi and Plex.
|
Class representing a synced Playlist with info for both Kodi and Plex.
|
||||||
|
|
|
@ -7,10 +7,11 @@ module
|
||||||
from __future__ import absolute_import, division, unicode_literals
|
from __future__ import absolute_import, division, unicode_literals
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
from .common import Playlist, PlaylistError
|
from .common import Playlist
|
||||||
from ..plex_db import PlexDB
|
from ..plex_db import PlexDB
|
||||||
from ..kodi_db import kodiid_from_filename
|
from ..kodi_db import kodiid_from_filename
|
||||||
from .. import path_ops, utils, variables as v
|
from .. import path_ops, utils, variables as v
|
||||||
|
from ..exceptions import PlaylistError
|
||||||
###############################################################################
|
###############################################################################
|
||||||
LOG = getLogger('PLEX.playlists.db')
|
LOG = getLogger('PLEX.playlists.db')
|
||||||
|
|
||||||
|
@ -121,7 +122,7 @@ def m3u_to_plex_ids(playlist):
|
||||||
def playlist_file_to_plex_ids(playlist):
|
def playlist_file_to_plex_ids(playlist):
|
||||||
"""
|
"""
|
||||||
Takes the playlist file located at path [unicode] and parses it.
|
Takes the playlist file located at path [unicode] and parses it.
|
||||||
Returns a list of plex_ids (str) or raises PL.PlaylistError if a single
|
Returns a list of plex_ids (str) or raises PlaylistError if a single
|
||||||
item cannot be parsed from Kodi to Plex.
|
item cannot be parsed from Kodi to Plex.
|
||||||
"""
|
"""
|
||||||
if playlist.kodi_extension == 'm3u':
|
if playlist.kodi_extension == 'm3u':
|
||||||
|
|
|
@ -7,11 +7,13 @@ from __future__ import absolute_import, division, unicode_literals
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import Playlist, PlaylistError, kodi_playlist_hash
|
from .common import Playlist, kodi_playlist_hash
|
||||||
from . import db, pms
|
from . import db, pms
|
||||||
|
|
||||||
from ..plex_api import API
|
from ..plex_api import API
|
||||||
from .. import utils, path_ops, variables as v
|
from .. import utils, path_ops, variables as v
|
||||||
|
from ..exceptions import PlaylistError
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
LOG = getLogger('PLEX.playlists.kodi_pl')
|
LOG = getLogger('PLEX.playlists.kodi_pl')
|
||||||
REGEX_FILE_NUMBERING = re.compile(r'''_(\d\d)\.\w+$''')
|
REGEX_FILE_NUMBERING = re.compile(r'''_(\d\d)\.\w+$''')
|
||||||
|
|
|
@ -6,8 +6,9 @@ Create and delete playlists on the Plex side of things
|
||||||
from __future__ import absolute_import, division, unicode_literals
|
from __future__ import absolute_import, division, unicode_literals
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
from .common import PlaylistError
|
|
||||||
from . import pms, db
|
from . import pms, db
|
||||||
|
from ..exceptions import PlaylistError
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
LOG = getLogger('PLEX.playlists.plex_pl')
|
LOG = getLogger('PLEX.playlists.plex_pl')
|
||||||
# Used for updating Plex playlists due to Kodi changes - Plex playlist
|
# Used for updating Plex playlists due to Kodi changes - Plex playlist
|
||||||
|
|
|
@ -7,11 +7,11 @@ manipulate playlists
|
||||||
from __future__ import absolute_import, division, unicode_literals
|
from __future__ import absolute_import, division, unicode_literals
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
|
||||||
from .common import PlaylistError
|
|
||||||
|
|
||||||
from ..plex_api import API
|
from ..plex_api import API
|
||||||
from ..downloadutils import DownloadUtils as DU
|
from ..downloadutils import DownloadUtils as DU
|
||||||
from .. import utils, app, variables as v
|
from .. import utils, app, variables as v
|
||||||
|
from ..exceptions import PlaylistError
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
LOG = getLogger('PLEX.playlists.pms')
|
LOG = getLogger('PLEX.playlists.pms')
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import xbmc
|
||||||
from .plex_api import API
|
from .plex_api import API
|
||||||
from . import playlist_func as PL, plex_functions as PF
|
from . import playlist_func as PL, plex_functions as PF
|
||||||
from . import backgroundthread, utils, json_rpc as js, app, variables as v
|
from . import backgroundthread, utils, json_rpc as js, app, variables as v
|
||||||
|
from . import exceptions
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
LOG = getLogger('PLEX.playqueue')
|
LOG = getLogger('PLEX.playqueue')
|
||||||
|
@ -88,7 +89,7 @@ def init_playqueue_from_plex_children(plex_id, transient_token=None):
|
||||||
api = API(child)
|
api = API(child)
|
||||||
try:
|
try:
|
||||||
PL.add_item_to_playlist(playqueue, i, plex_id=api.plex_id)
|
PL.add_item_to_playlist(playqueue, i, plex_id=api.plex_id)
|
||||||
except PL.PlaylistError:
|
except exceptions.PlaylistError:
|
||||||
LOG.error('Could not add Plex item to our playlist: %s, %s',
|
LOG.error('Could not add Plex item to our playlist: %s, %s',
|
||||||
child.tag, child.attrib)
|
child.tag, child.attrib)
|
||||||
playqueue.plex_transient_token = transient_token
|
playqueue.plex_transient_token = transient_token
|
||||||
|
@ -151,7 +152,7 @@ class PlayqueueMonitor(backgroundthread.KillableThread):
|
||||||
i + j, i)
|
i + j, i)
|
||||||
try:
|
try:
|
||||||
PL.move_playlist_item(playqueue, i + j, i)
|
PL.move_playlist_item(playqueue, i + j, i)
|
||||||
except PL.PlaylistError:
|
except exceptions.PlaylistError:
|
||||||
LOG.error('Could not modify playqueue positions')
|
LOG.error('Could not modify playqueue positions')
|
||||||
LOG.error('This is likely caused by mixing audio and '
|
LOG.error('This is likely caused by mixing audio and '
|
||||||
'video tracks in the Kodi playqueue')
|
'video tracks in the Kodi playqueue')
|
||||||
|
@ -167,7 +168,7 @@ class PlayqueueMonitor(backgroundthread.KillableThread):
|
||||||
PL.add_item_to_plex_playqueue(playqueue,
|
PL.add_item_to_plex_playqueue(playqueue,
|
||||||
i,
|
i,
|
||||||
kodi_item=new_item)
|
kodi_item=new_item)
|
||||||
except PL.PlaylistError:
|
except exceptions.PlaylistError:
|
||||||
# Could not add the element
|
# Could not add the element
|
||||||
pass
|
pass
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -196,7 +197,7 @@ class PlayqueueMonitor(backgroundthread.KillableThread):
|
||||||
LOG.debug('Detected deletion of playqueue element at pos %s', i)
|
LOG.debug('Detected deletion of playqueue element at pos %s', i)
|
||||||
try:
|
try:
|
||||||
PL.delete_playlist_item_from_PMS(playqueue, i)
|
PL.delete_playlist_item_from_PMS(playqueue, i)
|
||||||
except PL.PlaylistError:
|
except exceptions.PlaylistError:
|
||||||
LOG.error('Could not delete PMS element from position %s', i)
|
LOG.error('Could not delete PMS element from position %s', i)
|
||||||
LOG.error('This is likely caused by mixing audio and '
|
LOG.error('This is likely caused by mixing audio and '
|
||||||
'video tracks in the Kodi playqueue')
|
'video tracks in the Kodi playqueue')
|
||||||
|
|
|
@ -21,6 +21,7 @@ from . import playqueue as PQ
|
||||||
from . import variables as v
|
from . import variables as v
|
||||||
from . import backgroundthread
|
from . import backgroundthread
|
||||||
from . import app
|
from . import app
|
||||||
|
from . import exceptions
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ def update_playqueue_from_PMS(playqueue,
|
||||||
with app.APP.lock_playqueues:
|
with app.APP.lock_playqueues:
|
||||||
try:
|
try:
|
||||||
xml = PL.get_PMS_playlist(playqueue, playqueue_id)
|
xml = PL.get_PMS_playlist(playqueue, playqueue_id)
|
||||||
except PL.PlaylistError:
|
except exceptions.PlaylistError:
|
||||||
LOG.error('Could now download playqueue %s', playqueue_id)
|
LOG.error('Could now download playqueue %s', playqueue_id)
|
||||||
return
|
return
|
||||||
if playqueue.id == playqueue_id:
|
if playqueue.id == playqueue_id:
|
||||||
|
@ -64,7 +65,7 @@ def update_playqueue_from_PMS(playqueue,
|
||||||
# Get new metadata for the playqueue first
|
# Get new metadata for the playqueue first
|
||||||
try:
|
try:
|
||||||
PL.get_playlist_details_from_xml(playqueue, xml)
|
PL.get_playlist_details_from_xml(playqueue, xml)
|
||||||
except PL.PlaylistError:
|
except exceptions.PlaylistError:
|
||||||
LOG.error('Could not get playqueue ID %s', playqueue_id)
|
LOG.error('Could not get playqueue ID %s', playqueue_id)
|
||||||
return
|
return
|
||||||
playqueue.repeat = 0 if not repeat else int(repeat)
|
playqueue.repeat = 0 if not repeat else int(repeat)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import xml.etree.ElementTree as etree
|
||||||
from . import app
|
from . import app
|
||||||
from . import path_ops
|
from . import path_ops
|
||||||
from . import variables as v
|
from . import variables as v
|
||||||
|
from .exceptions import SubtitleError
|
||||||
|
|
||||||
LOG = getLogger('PLEX.subtitles')
|
LOG = getLogger('PLEX.subtitles')
|
||||||
|
|
||||||
|
@ -467,7 +468,3 @@ def external_subs_from_filesystem(dirname, filename):
|
||||||
class DummySub(etree.Element):
|
class DummySub(etree.Element):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(DummySub, self).__init__('Stream-subtitle-dummy')
|
super(DummySub, self).__init__('Stream-subtitle-dummy')
|
||||||
|
|
||||||
|
|
||||||
class SubtitleError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
Loading…
Reference in a new issue