From 4ee828dfe9c83ee2a819fbb56839038c60c08a60 Mon Sep 17 00:00:00 2001 From: croneter Date: Tue, 25 Dec 2018 18:26:13 +0100 Subject: [PATCH] Move function --- resources/lib/library_sync/common.py | 20 ++++++++++++++++++++ resources/lib/library_sync/full_sync.py | 22 +--------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/resources/lib/library_sync/common.py b/resources/lib/library_sync/common.py index 524de886..77cc8a9a 100644 --- a/resources/lib/library_sync/common.py +++ b/resources/lib/library_sync/common.py @@ -28,3 +28,23 @@ def update_kodi_library(video=True, music=True): xbmc.executebuiltin('UpdateLibrary(video)') if music: xbmc.executebuiltin('UpdateLibrary(music)') + + +def tag_last(iterable): + """ + Given some iterable, returns (last, item), where last is only True if you + are on the final iteration. + """ + iterator = iter(iterable) + gotone = False + try: + lookback = next(iterator) + gotone = True + while True: + cur = next(iterator) + yield False, lookback + lookback = cur + except StopIteration: + if gotone: + yield True, lookback + raise StopIteration() diff --git a/resources/lib/library_sync/full_sync.py b/resources/lib/library_sync/full_sync.py index 721b2db0..6ac90b04 100644 --- a/resources/lib/library_sync/full_sync.py +++ b/resources/lib/library_sync/full_sync.py @@ -29,26 +29,6 @@ UPDATED_AT_SAFETY = 60 * 5 LAST_VIEWED_AT_SAFETY = 60 * 5 -def tag_last(iterable): - """ - Given some iterable, returns (last, item), where last is only True if you - are on the final iteration. - """ - iterator = iter(iterable) - gotone = False - try: - lookback = next(iterator) - gotone = True - while True: - cur = next(iterator) - yield False, lookback - lookback = cur - except StopIteration: - if gotone: - yield True, lookback - raise StopIteration() - - class InitNewSection(object): """ Throw this into the queue used for ProcessMetadata to tell it which @@ -201,7 +181,7 @@ class FullSync(common.fullsync_mixin): self.current = 0 # Initialize only once to avoid loosing the last value before # we're breaking the for loop - loop = tag_last(iterator) + loop = common.tag_last(iterator) while True: # Check Plex DB to see what we need to add/update with PlexDB() as self.plexdb: