dots/addins/version.xsh

36 lines
940 B
Plaintext
Raw Normal View History

2021-10-20 03:09:24 +00:00
import platform
2021-09-22 07:52:45 +00:00
from pathlib import Path
__all__ = ['Version']
2021-10-20 03:09:24 +00:00
class Platform:
def __init__(self):
self.architecture = platform.architecture()
self.machine = platform.machine()
self.node = platform.node()
self.platform = platform.platform()
self.processor = platform.processor()
self.release = platform.release()
self.system = platform.system()
self.version = platform.version()
2021-09-22 07:52:45 +00:00
class Version:
2021-10-20 03:09:24 +00:00
def __init__(self):
data = self._load_dict()
for key, value in data.items():
setattr(self, key.lower(), value)
if hasattr(self, "id_like"): # special handling for ID_LIKE
self.id_like = self.id_like.split()
if not hasattr(self, "platform"):
self.platform = Platform()
2021-09-22 07:52:45 +00:00
2021-10-20 03:09:24 +00:00
def _load_dict(self):
data = {}
os_files = Path('/etc').glob("*-release")
for i in os_files:
with i.open() as f:
for line in f:
line = line.split("=")
data[line[0]] = line[1].strip().replace('"', '')
return data