mirror of https://git.48k.eu/ogclient
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.master
parent
aa34704b4d
commit
9970c8e33d
|
@ -9,6 +9,7 @@
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import platform
|
import platform
|
||||||
|
import logging
|
||||||
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from subprocess import PIPE
|
from subprocess import PIPE
|
||||||
|
@ -25,6 +26,7 @@ def getlinuxversion(osrelease):
|
||||||
"""
|
"""
|
||||||
mountpoint = find_mountpoint(osrelease)
|
mountpoint = find_mountpoint(osrelease)
|
||||||
|
|
||||||
|
try:
|
||||||
with open(osrelease, 'r') as f:
|
with open(osrelease, 'r') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
if line.find('=') == -1:
|
if line.find('=') == -1:
|
||||||
|
@ -35,6 +37,8 @@ def getlinuxversion(osrelease):
|
||||||
value = value.strip('"')
|
value = value.strip('"')
|
||||||
bits = ' 64 bits' if linux_is64bit(mountpoint) else ''
|
bits = ' 64 bits' if linux_is64bit(mountpoint) else ''
|
||||||
return f'{value}{bits}'
|
return f'{value}{bits}'
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
logging.error(f'os-release file not found at "{osrelease}"')
|
||||||
return 'Linux'
|
return 'Linux'
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue