From 67f465f7ede6a231d554e57d5ee9b1daf9516aef Mon Sep 17 00:00:00 2001 From: elburg Date: Wed, 25 Jan 2023 12:21:42 -0800 Subject: [PATCH] started project --- README.rst | 2 ++ src/__init__.py | 5 +++++ src/platform/__init__.py | 27 +++++++++++++++++++++++++++ src/platform/osinfo.py | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 README.rst create mode 100644 src/__init__.py create mode 100644 src/platform/__init__.py create mode 100644 src/platform/osinfo.py diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..32020f6 --- /dev/null +++ b/README.rst @@ -0,0 +1,2 @@ +System Information Library for Python +===================================== diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..bbe8b49 --- /dev/null +++ b/src/__init__.py @@ -0,0 +1,5 @@ +__all__ = ['platform'] + +_LIBMETA={ + 'version': [0,0,0] +} diff --git a/src/platform/__init__.py b/src/platform/__init__.py new file mode 100644 index 0000000..73e810a --- /dev/null +++ b/src/platform/__init__.py @@ -0,0 +1,27 @@ +_rC = { + 0: None # osinfo.py 'osFamily' +} + +def _resetCache() -> bool: + try: + for x in _rC: + x = None + return True + except IndexError as e: + from warnings import warn + warn('IndexError was unusually thrown whilst clearing cache ({}). ignoring it...'.format(e.message)) + return True + except: + return False + +def _reload(): + import osinfo + _rC[0]=osinfo.getOSValue('osFamily') + +def getAll() -> dict: + return { + 'os': { + 'family': _rC[0] + } + } + diff --git a/src/platform/osinfo.py b/src/platform/osinfo.py new file mode 100644 index 0000000..e154fb3 --- /dev/null +++ b/src/platform/osinfo.py @@ -0,0 +1,33 @@ +# from .._internal.methods import platform as _discover + +def _match(x: int, y: int) -> str: + try: + if x==0: # Kernal Family + return { + 0: 'Unknown', + 1: 'Unknown POSIX', + 2: 'Unix', + 3: 'Linux', + 4: 'Windows NT', + 5: 'BSD', + 6: 'Unknown BSD' + }[y] + else: + raise RuntimeError('invalid x id from discovery methods') + except IndexError: + return { + 0: 'Unknown' + }[x] + except RuntimeError as e: + raise e + +def getOSValue(item: str) -> list: + try: + return { + 'osFamily': _match(0,_discover.find('OS_FAMILY')) + }[item] + except IndexError as e: + return None + +def dumpOSInfo() -> dict: + return