Skip to content

Commit b118354

Browse files
authored
Merge pull request #65 from nexB/os-release-parser
Use parse_os_release in commoncode.system
2 parents b61c636 + 5fed651 commit b118354

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Release notes
22
=============
33

4+
Version 31.2.1 - (2024-05-16)
5+
-----------------------------
6+
7+
- Remove ``commoncode.system.get_etc_os_release_info`` and replace it with ``commoncode.distro_os_release_parser``.
8+
9+
410
Version 31.2.0 - (2024-05-16)
511
-----------------------------
612

src/commoncode/system.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
# See https://aboutcode.org for more information about nexB OSS projects.
77
#
88

9-
import getpass
109
import os
1110
import sys
1211

12+
from commoncode.distro import parse_os_release
13+
1314

1415
def os_arch():
1516
"""
@@ -84,29 +85,13 @@ def is_on_macos_arm64():
8485
del is_on_macos_arm64
8586

8687

87-
def get_etc_os_release_info(os_release_path='/etc/os-release'):
88-
"""
89-
Return a dictionary of key-value pairs from /etc/os-release
90-
"""
91-
os_release_data = {}
92-
with open(os_release_path) as f:
93-
for line in f:
94-
split_line = line.split('=')
95-
if not split_line:
96-
continue
97-
k = split_line[0].strip()
98-
v = split_line[-1].strip()
99-
os_release_data[k] = v
100-
return os_release_data
101-
102-
103-
def is_on_ubuntu_22():
88+
def is_on_ubuntu_22(os_release_location='/etc/os-release'):
10489
"""
10590
Return True if the current OS is Ubuntu 22.XX.
10691
"""
10792
if not on_linux:
10893
return False
109-
os_release_info = get_etc_os_release_info()
94+
os_release_info = parse_os_release(os_release_location)
11095
return os_release_info['ID'] == 'ubuntu' and '22' in os_release_info['VERSION_ID']
11196

11297
on_ubuntu_22 = is_on_ubuntu_22()

0 commit comments

Comments
 (0)