summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-03-06 21:38:27 +0100
committerlupoDharkael <izhe@hotmail.es>2024-03-08 12:43:10 +0100
commit9970c8e33d7a422e807a23af712236db01284f9a (patch)
tree844b3cbbd68d4ab75ecef2d1c8f903c92966cf21
parentaa34704b4d28225afb3e9a0d563826c7bb58a378 (diff)
utils: handle missing file in getlinuxversion function
The function getlinuxversion receives a path to the os-release file. The case of not being able to open it was not handled and thus causing an unwanted exception.
-rw-r--r--src/utils/probe.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/utils/probe.py b/src/utils/probe.py
index 8c77bf9..c6e3680 100644
--- a/src/utils/probe.py
+++ b/src/utils/probe.py
@@ -9,6 +9,7 @@
import os
import subprocess
import platform
+import logging
from enum import Enum
from subprocess import PIPE
@@ -25,17 +26,20 @@ def getlinuxversion(osrelease):
"""
mountpoint = find_mountpoint(osrelease)
- with open(osrelease, 'r') as f:
- for line in f:
- if line.find('=') == -1:
- continue
- key, value = line.split('=')
- if key == 'PRETTY_NAME':
- value = value.replace('\n', '')
- value = value.strip('"')
- bits = ' 64 bits' if linux_is64bit(mountpoint) else ''
- return f'{value}{bits}'
- return 'Linux'
+ try:
+ with open(osrelease, 'r') as f:
+ for line in f:
+ if line.find('=') == -1:
+ continue
+ key, value = line.split('=')
+ if key == 'PRETTY_NAME':
+ value = value.replace('\n', '')
+ value = value.strip('"')
+ bits = ' 64 bits' if linux_is64bit(mountpoint) else ''
+ return f'{value}{bits}'
+ except FileNotFoundError as e:
+ logging.error(f'os-release file not found at "{osrelease}"')
+ return 'Linux'
def getwindowsversion(winreghives):