diff options
author | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-06 16:29:30 +0100 |
---|---|---|
committer | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-08 14:49:31 +0100 |
commit | 495012f7737302f458ff60fe2a93d0972cd3443d (patch) | |
tree | 3e7a78bb07afa5c6db29eee0758d6531828b2671 /python/vyos/version.py | |
parent | 3d65f12e38f721ae37b65e058f0c59a24d6a6886 (diff) | |
download | vyos-1x-495012f7737302f458ff60fe2a93d0972cd3443d.tar.gz vyos-1x-495012f7737302f458ff60fe2a93d0972cd3443d.zip |
version: T2186: do not raise if not version info
The code attempted to access the information on the file system
During the package build this is not available, therefore the
code was modified to return empty object when no data is there
Diffstat (limited to 'python/vyos/version.py')
-rw-r--r-- | python/vyos/version.py | 15 |
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','') |