os_release #
Operating System Identification
os_release module implements the /etc/os-release file parser per freedesktop.org standard. Learn more at os-release(5).
Usage example:
import os_release
fn main() {
release_data := os_release.os_release()
os_name := release_data['NAME'] or { 'Linux' }
os_id := release_data['ID'] or { 'linux' }
println('OS Name: ${os_name}')
println('OS ID: ${os_id}')
}
Constants #
const options = ['NAME', 'ID', 'ID_LIKE', 'PRETTY_NAME', 'CPE_NAME', 'VARIANT', 'VARIANT_ID',
'VERSION', 'VERSION_ID', 'VERSION_CODENAME', 'BUILD_ID', 'IMAGE_ID', 'IMAGE_VERSION',
'RELEASE_TYPE', 'HOME_URL', 'DOCUMENTATION_URL', 'SUPPORT_URL', 'BUG_REPORT_URL',
'PRIVACY_POLICY_URL', 'SUPPORT_END', 'LOGO', 'ANSI_COLOR', 'VENDOR_NAME', 'VENDOR_URL',
'EXPERIMENT', 'EXPERIMENT_URL', 'DEFAULT_HOSTNAME', 'ARCHITECTURE', 'SYSEXT_LEVEL',
'CONFEXT_LEVEL', 'SYSEXT_SCOPE', 'CONFEXT_SCOPE', 'PORTABLE_PREFIXES']!
options contains list of default os-release, initrd-release, extension-release options.
fn os_release #
fn os_release() map[string]string
os_release reads /etc/os-release and /usr/lib/os-release files and returns parsed os-release data. Empty map will be returned if files does not exits or reading issues caused. The resulting map will contain only options that is present in actual os-release file.
fn parse #
fn parse(content string) map[string]string
parse parses the content string and returns map of os-release key-value pairs.
Example
assert os_release.parse('PRETTY_NAME="Debian GNU/Linux 13 (trixie)"') == {'PRETTY_NAME': 'Debian GNU/Linux 13 (trixie)'}
fn parse_file #
fn parse_file(file string) !map[string]string
parse_file reads the file and returns map of os-release key-value pairs.