summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-07-05 08:27:52 +0200
committerGitHub <noreply@github.com>2024-07-05 08:27:52 +0200
commit9cddfd9fde5504cd5e42ed75560f21619aca646b (patch)
tree0c40f78ee866c5987e7cc8e9b963ca8d66f9ba2b
parentc3bf4b80cd25dc8e64826b6d2f7ad0b3d1ae06c0 (diff)
parentbd42f131ea2ceec2c591303ea69b7d3a36e41a7c (diff)
downloadvyos-1x-9cddfd9fde5504cd5e42ed75560f21619aca646b.tar.gz
vyos-1x-9cddfd9fde5504cd5e42ed75560f21619aca646b.zip
Merge pull request #3788 from jestabro/check-component-version
migration: T6007: add missing check for None in utility function
-rw-r--r--python/vyos/component_version.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/python/vyos/component_version.py b/python/vyos/component_version.py
index 0c305e5e0..94215531d 100644
--- a/python/vyos/component_version.py
+++ b/python/vyos/component_version.py
@@ -129,6 +129,7 @@ def component_from_string(string: str) -> dict:
return {k: int(v) for k, v in re.findall(r'([\w,-]+)@(\d+)', string)}
def version_info_from_file(config_file) -> VersionInfo:
+ """Return config file component and release version info."""
version_info = VersionInfo()
try:
with open(config_file) as f:
@@ -166,9 +167,7 @@ def version_info_from_file(config_file) -> VersionInfo:
return version_info
def version_info_from_system() -> VersionInfo:
- """
- Return system component versions.
- """
+ """Return system component and release version info."""
d = component_version()
sort_d = dict(sorted(d.items(), key=lambda x: x[0]))
version_info = VersionInfo(
@@ -180,20 +179,18 @@ def version_info_from_system() -> VersionInfo:
return version_info
def version_info_copy(v: VersionInfo) -> VersionInfo:
- """
- Make a copy of dataclass.
- """
+ """Make a copy of dataclass."""
return replace(v)
def version_info_prune_component(x: VersionInfo, y: VersionInfo) -> VersionInfo:
- """
- In place pruning of component keys of x not in y.
- """
+ """In place pruning of component keys of x not in y."""
+ if x.component is None or y.component is None:
+ return
x.component = { k: v for k,v in x.component.items() if k in y.component }
def add_system_version(config_str: str = None, out_file: str = None):
- """
- Wrap config string with system version and write to out_file.
+ """Wrap config string with system version and write to out_file.
+
For convenience, calling with no argument will write system version
string to stdout, for use in bash scripts.
"""