Move method to function

This commit is contained in:
tomkat83 2017-05-29 17:05:22 +02:00
parent ba698288bb
commit 456959b676
2 changed files with 39 additions and 33 deletions

View file

@ -12,7 +12,7 @@ from xbmcvfs import exists
from utils import window, settings, getUnixTimestamp, sourcesXML,\
thread_methods, create_actor_db_index, dialog, LogTime, getScreensaver,\
setScreensaver, playlistXSP, language as lang, DateToKodi, reset,\
tryDecode, deletePlaylists, deleteNodes, tryEncode
tryDecode, deletePlaylists, deleteNodes, tryEncode, compare_version
import downloadutils
import itemtypes
import plexdb_functions as plexdb
@ -1087,37 +1087,6 @@ class LibrarySync(Thread):
if itemid not in self.allPlexElementsId:
Music.remove(itemid)
def compareDBVersion(self, current, minimum):
# It returns True is database is up to date. False otherwise.
log.info("current DB: %s minimum DB: %s" % (current, minimum))
try:
currMajor, currMinor, currPatch = current.split(".")
except ValueError:
# there WAS no current DB, e.g. deleted.
return True
minMajor, minMinor, minPatch = minimum.split(".")
currMajor = int(currMajor)
currMinor = int(currMinor)
currPatch = int(currPatch)
minMajor = int(minMajor)
minMinor = int(minMinor)
minPatch = int(minPatch)
if currMajor > minMajor:
return True
elif currMajor < minMajor:
return False
if currMinor > minMinor:
return True
elif currMinor < minMinor:
return False
if currPatch >= minPatch:
return True
else:
return False
def processMessage(self, message):
"""
processes json.loads() messages from websocket. Triage what we need to
@ -1486,7 +1455,7 @@ class LibrarySync(Thread):
currentVersion = settings('dbCreatedWithVersion')
minVersion = window('plex_minDBVersion')
if not self.compareDBVersion(currentVersion, minVersion):
if not compare_version(currentVersion, minVersion):
log.warn("Db version out of date: %s minimum version "
"required: %s" % (currentVersion, minVersion))
# DB out of date. Proceed to recreate?

View file

@ -468,6 +468,43 @@ def convertdate(date):
return date
def compare_version(current, minimum):
"""
Returns True if current is >= then minimum. False otherwise
Input strings: e.g. "1.2.3"; always with Major, Minor and Patch!
"""
log.info("current DB: %s minimum DB: %s" % (current, minimum))
try:
currMajor, currMinor, currPatch = current.split(".")
except ValueError:
# there WAS no current DB, e.g. deleted.
return True
minMajor, minMinor, minPatch = minimum.split(".")
currMajor = int(currMajor)
currMinor = int(currMinor)
currPatch = int(currPatch)
minMajor = int(minMajor)
minMinor = int(minMinor)
minPatch = int(minPatch)
if currMajor > minMajor:
return True
elif currMajor < minMajor:
return False
if currMinor > minMinor:
return True
elif currMinor < minMinor:
return False
if currPatch >= minPatch:
return True
else:
return False
def normalize_nodes(text):
# For video nodes
text = text.replace(":", "")