Avoid duplicate code
This commit is contained in:
parent
3000bfcd7d
commit
70b7a44514
5 changed files with 27 additions and 55 deletions
|
@ -1,10 +1,13 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import absolute_import, division, unicode_literals
|
from __future__ import absolute_import, division, unicode_literals
|
||||||
|
from logging import getLogger
|
||||||
import xbmc
|
import xbmc
|
||||||
|
|
||||||
from .. import utils, app, variables as v
|
from .. import utils, app, variables as v
|
||||||
|
|
||||||
|
LOG = getLogger('PLEX.sync')
|
||||||
|
|
||||||
PLAYLIST_SYNC_ENABLED = (v.DEVICE != 'Microsoft UWP' and
|
PLAYLIST_SYNC_ENABLED = (v.DEVICE != 'Microsoft UWP' and
|
||||||
utils.settings('enablePlaylistSync') == 'true')
|
utils.settings('enablePlaylistSync') == 'true')
|
||||||
|
|
||||||
|
@ -22,6 +25,18 @@ class LibrarySyncMixin(object):
|
||||||
"""
|
"""
|
||||||
return self.should_cancel()
|
return self.should_cancel()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
app.APP.register_thread(self)
|
||||||
|
LOG.debug('##===--- Starting %s ---===##', self.__class__.__name__)
|
||||||
|
try:
|
||||||
|
self._run()
|
||||||
|
except Exception as err:
|
||||||
|
LOG.error('Exception encountered: %s', err)
|
||||||
|
utils.ERROR(notify=True)
|
||||||
|
finally:
|
||||||
|
app.APP.deregister_thread(self)
|
||||||
|
LOG.debug('##===--- %s Stopped ---===##', self.__class__.__name__)
|
||||||
|
|
||||||
|
|
||||||
def update_kodi_library(video=True, music=True):
|
def update_kodi_library(video=True, music=True):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -4,13 +4,13 @@ from logging import getLogger
|
||||||
|
|
||||||
from . import common
|
from . import common
|
||||||
from ..plex_db import PlexDB
|
from ..plex_db import PlexDB
|
||||||
from .. import backgroundthread, app
|
from .. import backgroundthread
|
||||||
|
|
||||||
LOG = getLogger('PLEX.sync.fill_metadata_queue')
|
LOG = getLogger('PLEX.sync.fill_metadata_queue')
|
||||||
|
|
||||||
|
|
||||||
class FillMetadataQueue(common.LibrarySyncMixin,
|
class FillMetadataQueue(common.LibrarySyncMixin,
|
||||||
backgroundthread.KillableThread, ):
|
backgroundthread.KillableThread):
|
||||||
"""
|
"""
|
||||||
Threaded download of Plex XML metadata for a certain library item.
|
Threaded download of Plex XML metadata for a certain library item.
|
||||||
Fills the queue with the downloaded etree XML objects. Will use a COPIED
|
Fills the queue with the downloaded etree XML objects. Will use a COPIED
|
||||||
|
@ -47,21 +47,12 @@ class FillMetadataQueue(common.LibrarySyncMixin,
|
||||||
# Ensures that our queues finish
|
# Ensures that our queues finish
|
||||||
section.number_of_items = count
|
section.number_of_items = count
|
||||||
|
|
||||||
def run(self):
|
def _run(self):
|
||||||
LOG.debug('Starting %s thread', self.__class__.__name__)
|
while not self.should_cancel():
|
||||||
app.APP.register_thread(self)
|
section = self.section_queue.get()
|
||||||
try:
|
self.section_queue.task_done()
|
||||||
while not self.should_cancel():
|
if section is None:
|
||||||
section = self.section_queue.get()
|
break
|
||||||
self.section_queue.task_done()
|
self._process_section(section)
|
||||||
if section is None:
|
# Signal the download metadata threads to stop with a sentinel
|
||||||
break
|
self.get_metadata_queue.put(None)
|
||||||
self._process_section(section)
|
|
||||||
except Exception:
|
|
||||||
from .. import utils
|
|
||||||
utils.ERROR(notify=True)
|
|
||||||
finally:
|
|
||||||
# Signal the download metadata threads to stop with a sentinel
|
|
||||||
self.get_metadata_queue.put(None)
|
|
||||||
app.APP.deregister_thread(self)
|
|
||||||
LOG.debug('##===---- %s Stopped ----===##', self.__class__.__name__)
|
|
||||||
|
|
|
@ -272,20 +272,8 @@ class FullSync(common.LibrarySyncMixin, backgroundthread.KillableThread):
|
||||||
break
|
break
|
||||||
LOG.debug('Done looking for items to delete')
|
LOG.debug('Done looking for items to delete')
|
||||||
|
|
||||||
def run(self):
|
|
||||||
app.APP.register_thread(self)
|
|
||||||
LOG.info('Running library sync with repair=%s', self.repair)
|
|
||||||
try:
|
|
||||||
self.run_full_library_sync()
|
|
||||||
except Exception:
|
|
||||||
utils.ERROR(notify=True)
|
|
||||||
self.successful = False
|
|
||||||
finally:
|
|
||||||
app.APP.deregister_thread(self)
|
|
||||||
LOG.info('Library sync done. successful: %s', self.successful)
|
|
||||||
|
|
||||||
@utils.log_time
|
@utils.log_time
|
||||||
def run_full_library_sync(self):
|
def _run(self):
|
||||||
try:
|
try:
|
||||||
# Get latest Plex libraries and build playlist and video node files
|
# Get latest Plex libraries and build playlist and video node files
|
||||||
if self.should_cancel() or not sections.sync_from_pms(self):
|
if self.should_cancel() or not sections.sync_from_pms(self):
|
||||||
|
|
|
@ -5,7 +5,6 @@ from logging import getLogger
|
||||||
from . import common
|
from . import common
|
||||||
from ..plex_api import API
|
from ..plex_api import API
|
||||||
from .. import backgroundthread, plex_functions as PF, utils, variables as v
|
from .. import backgroundthread, plex_functions as PF, utils, variables as v
|
||||||
from .. import app
|
|
||||||
|
|
||||||
LOG = getLogger('PLEX.sync.get_metadata')
|
LOG = getLogger('PLEX.sync.get_metadata')
|
||||||
LOCK = backgroundthread.threading.Lock()
|
LOCK = backgroundthread.threading.Lock()
|
||||||
|
@ -69,15 +68,6 @@ class GetMetadataThread(common.LibrarySyncMixin,
|
||||||
# Add a "dummy" item so we're not skipping a beat
|
# Add a "dummy" item so we're not skipping a beat
|
||||||
self.processing_queue.put((count, {'section': section, 'xml': None}))
|
self.processing_queue.put((count, {'section': section, 'xml': None}))
|
||||||
|
|
||||||
def run(self):
|
|
||||||
LOG.debug('Starting %s thread', self.__class__.__name__)
|
|
||||||
app.APP.register_thread(self)
|
|
||||||
try:
|
|
||||||
self._run()
|
|
||||||
finally:
|
|
||||||
app.APP.deregister_thread(self)
|
|
||||||
LOG.debug('##===---- %s Stopped ----===##', self.__class__.__name__)
|
|
||||||
|
|
||||||
def _run(self):
|
def _run(self):
|
||||||
while True:
|
while True:
|
||||||
item = self.get_metadata_queue.get()
|
item = self.get_metadata_queue.get()
|
||||||
|
|
|
@ -57,18 +57,6 @@ class ProcessMetadataThread(common.LibrarySyncMixin,
|
||||||
self.processing_queue.task_done()
|
self.processing_queue.task_done()
|
||||||
return item
|
return item
|
||||||
|
|
||||||
def run(self):
|
|
||||||
LOG.debug('Starting %s thread', self.__class__.__name__)
|
|
||||||
app.APP.register_thread(self)
|
|
||||||
try:
|
|
||||||
self._run()
|
|
||||||
except Exception:
|
|
||||||
from .. import utils
|
|
||||||
utils.ERROR(notify=True)
|
|
||||||
finally:
|
|
||||||
app.APP.deregister_thread(self)
|
|
||||||
LOG.debug('##===---- %s Stopped ----===##', self.__class__.__name__)
|
|
||||||
|
|
||||||
def _run(self):
|
def _run(self):
|
||||||
# There are 2 sentinels: None for aborting/ending this thread, the dict
|
# There are 2 sentinels: None for aborting/ending this thread, the dict
|
||||||
# {'section': section, 'xml': None} for skipped/invalid items
|
# {'section': section, 'xml': None} for skipped/invalid items
|
||||||
|
|
Loading…
Reference in a new issue