Skip to content

Commit 9d1aa08

Browse files
committed
Check /etc/os-release for Ubuntu version
Signed-off-by: Jono Yang <jyang@nexb.com>
1 parent b2bf13a commit 9d1aa08

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/extractcode/vmimage.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
import logging
1111
import os
1212
import pathlib
13+
import platform
1314
import shutil
1415
import warnings
1516

1617
import attr
18+
import pytest
1719

1820
from commoncode import fileutils
1921
from commoncode.system import on_linux
@@ -74,6 +76,32 @@ def get_command(env_var=EXTRACTCODE_GUESTFISH_PATH_ENVVAR, command='guestfish'):
7476
return cmd_loc
7577

7678

79+
def get_etc_os_release_info(os_release_path='/etc/os-release'):
80+
cfg_kv = {}
81+
with open(os_release_path) as f:
82+
for line in f:
83+
split_line = line.split('=')
84+
if not split_line:
85+
continue
86+
k = split_line[0].strip()
87+
v = split_line[-1].strip()
88+
cfg_kv[k] = v
89+
return cfg_kv
90+
91+
92+
def is_on_ubuntu_22():
93+
if not on_linux:
94+
return False
95+
os_release_info = get_etc_os_release_info()
96+
print(os_release_info)
97+
return os_release_info['ID'] == 'ubuntu' and '22' in os_release_info['VERSION_ID']
98+
99+
on_ubuntu_22 = is_on_ubuntu_22()
100+
101+
del is_on_ubuntu_22
102+
103+
104+
@pytest.mark.skipif(on_ubuntu_22, reason='Kernel is not readable on Ubuntu 22.04')
77105
def check_linux_kernel_is_readable():
78106
"""
79107
Return True if the kernel executable file can be read. This is required by

0 commit comments

Comments
 (0)