From 033c07f070decc37e3e135ecd812efc4fd497200 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Wed, 5 Jan 2022 04:15:10 -0800 Subject: [PATCH] prevent using empty cached version --- WakaTime.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/WakaTime.py b/WakaTime.py index da25186..584ef30 100644 --- a/WakaTime.py +++ b/WakaTime.py @@ -725,10 +725,7 @@ def getLatestCliVersion(): try: configs = parseConfigFile(INTERNAL_CONFIG_FILE) if configs: - if configs.has_option('internal', 'cli_version'): - last_version = configs.get('internal', 'cli_version') - if last_version and configs.has_option('internal', 'cli_version_last_modified'): - last_modified = configs.get('internal', 'cli_version_last_modified') + last_modified, last_version = lastModifiedAndVersion(configs) except: log(DEBUG, traceback.format_exc()) @@ -762,6 +759,17 @@ def getLatestCliVersion(): return None +def lastModifiedAndVersion(configs): + last_modified, last_version = None, None + if configs.has_option('internal', 'cli_version'): + last_version = configs.get('internal', 'cli_version') + if last_version and configs.has_option('internal', 'cli_version_last_modified'): + last_modified = configs.get('internal', 'cli_version_last_modified') + if last_modified and last_version and extractVersion(last_version): + return last_modified, last_version + return None, None + + def extractVersion(text): pattern = re.compile(r"([0-9]+\.[0-9]+\.[0-9]+)") match = pattern.search(text)