From: Ed Page Date: Sat, 6 Mar 2010 17:59:46 +0000 (-0600) Subject: Adding fancier version checks to allow to the cache to be preserved longer X-Git-Url: http://git.maemo.org/git/?p=theonering;a=commitdiff_plain;h=074b7adedaeba92d5993f8015be26c684f8bbfd8 Adding fancier version checks to allow to the cache to be preserved longer --- diff --git a/src/gvoice/conversations.py b/src/gvoice/conversations.py index ea2ab6f..fed382b 100644 --- a/src/gvoice/conversations.py +++ b/src/gvoice/conversations.py @@ -40,11 +40,16 @@ class Conversations(object): _moduleLogger.exception("While loading for %s" % self._name) return - if fileVersion == constants.__version__ and fileBuild == constants.__build__: + if misc_utils.compare_versions( + misc_utils.parse_version("0.8.0"), + misc_utils.parse_version(fileVersion), + ) <= 0: self._conversations = convs else: _moduleLogger.debug( - "%s Skipping cache due to version mismatch (%s-%s)" % (self._name, fileVersion, fileBuild) + "%s Skipping cache due to version mismatch (%s-%s)" % ( + self._name, fileVersion, fileBuild + ) ) def save(self, path): diff --git a/src/util/misc.py b/src/util/misc.py index 69a5b09..cf5c22a 100644 --- a/src/util/misc.py +++ b/src/util/misc.py @@ -718,3 +718,40 @@ def is_valid_number(number): @returns If This number be called ( syntax validation only ) """ return _VALIDATE_RE.match(number) is not None + + +def parse_version(versionText): + """ + >>> parse_version("0.5.2") + [0, 5, 2] + """ + return [ + int(number) + for number in versionText.split(".") + ] + + +def compare_versions(leftParsedVersion, rightParsedVersion): + """ + >>> compare_versions([0, 1, 2], [0, 1, 2]) + 0 + >>> compare_versions([0, 1, 2], [0, 1, 3]) + -1 + >>> compare_versions([0, 1, 2], [0, 2, 2]) + -1 + >>> compare_versions([0, 1, 2], [1, 1, 2]) + -1 + >>> compare_versions([0, 1, 3], [0, 1, 2]) + 1 + >>> compare_versions([0, 2, 2], [0, 1, 2]) + 1 + >>> compare_versions([1, 1, 2], [0, 1, 2]) + 1 + """ + for left, right in zip(leftParsedVersion, rightParsedVersion): + if left < right: + return -1 + elif right < left: + return 1 + else: + return 0