Temporary backup from J621 porting
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
# common/os_utils.py
|
||||
import platform
|
||||
import os
|
||||
from functools import lru_cache
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def get_os_info():
|
||||
"""
|
||||
Detect Linux distribution and return (fontawesome_class, display_name).
|
||||
Falls back to generic Linux.
|
||||
"""
|
||||
system = platform.system()
|
||||
if system != 'Linux':
|
||||
return ('fa-brands fa-linux', system)
|
||||
|
||||
# Try to read /etc/os-release
|
||||
os_release_path = '/etc/os-release'
|
||||
distro_id = ''
|
||||
distro_name = ''
|
||||
try:
|
||||
with open(os_release_path, 'r') as f:
|
||||
for line in f:
|
||||
if line.startswith('ID='):
|
||||
distro_id = line.split('=', 1)[1].strip().strip('"').lower()
|
||||
elif line.startswith('NAME='):
|
||||
distro_name = line.split('=', 1)[1].strip().strip('"')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Map IDs to FontAwesome icons and display names
|
||||
mapping = {
|
||||
'debian': ('fa-brands fa-debian', 'Debian'),
|
||||
'ubuntu': ('fa-brands fa-ubuntu', 'Ubuntu'),
|
||||
'fedora': ('fa-brands fa-fedora', 'Fedora'),
|
||||
'rhel': ('fa-brands fa-redhat', 'RHEL'),
|
||||
'centos': ('fa-brands fa-centos', 'CentOS'),
|
||||
'opensuse': ('fa-brands fa-suse', 'openSUSE'),
|
||||
'suse': ('fa-brands fa-suse', 'SUSE'),
|
||||
}
|
||||
|
||||
if distro_id in mapping:
|
||||
return mapping[distro_id]
|
||||
|
||||
return ('fa-brands fa-linux', distro_name or 'Linux')
|
||||
Reference in New Issue
Block a user