summaryrefslogtreecommitdiff
path: root/python/vyos/version.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-04-09 07:38:01 +0200
committerGitHub <noreply@github.com>2020-04-09 07:38:01 +0200
commitd4469e373df1ee5f572cd601cb0aa7fd1bdd7770 (patch)
tree1548930a6cc31561d54fe5f6366a03e3692d4793 /python/vyos/version.py
parentec99423f227fcb879ff9abeca2c49c5b86804044 (diff)
parent38c2b8947e5e901609a834e0c6c14ed7f17043f2 (diff)
downloadvyos-1x-d4469e373df1ee5f572cd601cb0aa7fd1bdd7770.tar.gz
vyos-1x-d4469e373df1ee5f572cd601cb0aa7fd1bdd7770.zip
Merge pull request #314 from thomas-mangin/T2186
airbag: T2186: report friendly user message and log to syslog
Diffstat (limited to 'python/vyos/version.py')
-rw-r--r--python/vyos/version.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/python/vyos/version.py b/python/vyos/version.py
index 383efbc1e..d51a940d6 100644
--- a/python/vyos/version.py
+++ b/python/vyos/version.py
@@ -44,7 +44,7 @@ def get_version_data(file=version_file):
file (str): path to the version file
Returns:
- dict: version data
+ dict: version data, if it can not be found and empty dict
The optional ``file`` argument comes in handy in upgrade scripts
that need to retrieve information from images other than the running image.
@@ -52,17 +52,20 @@ def get_version_data(file=version_file):
is an implementation detail and may change in the future, while the interface
of this module will stay the same.
"""
- with open(file, 'r') as f:
- version_data = json.load(f)
- return version_data
+ try:
+ with open(file, 'r') as f:
+ version_data = json.load(f)
+ return version_data
+ except FileNotFoundError:
+ return {}
def get_version(file=None):
"""
- Get the version number
+ Get the version number, or an empty string if it could not be determined
"""
version_data = None
if file:
version_data = get_version_data(file=file)
else:
version_data = get_version_data()
- return version_data["version"]
+ return version_data.get('version','')