fix, refactor: debugged circular class ref via refactor & renaming
This commit is contained in:
41
softman.py
41
softman.py
@@ -24,11 +24,6 @@ class SoftPathGroup(Enum):
|
|||||||
MEM = 2
|
MEM = 2
|
||||||
EXE = 3
|
EXE = 3
|
||||||
|
|
||||||
# @TODO continue adding magic methods to below class
|
|
||||||
# @NOTE https://rszalski.github.io/magicmethods/#sequence
|
|
||||||
class Software:
|
|
||||||
# @TODO move below 2 class variables declarations outside of class, but make class variables equal to them
|
|
||||||
# @TODO when done with above, rename all intra-class references to such variables appropriately
|
|
||||||
_AppParams = Dict("_AppParams", {
|
_AppParams = Dict("_AppParams", {
|
||||||
SoftPathGroup.CONFIG.name: {
|
SoftPathGroup.CONFIG.name: {
|
||||||
SoftScope.PERSONAL.name: IdlePath | list[IdlePath],
|
SoftScope.PERSONAL.name: IdlePath | list[IdlePath],
|
||||||
@@ -57,6 +52,11 @@ class Software:
|
|||||||
SoftScope.GLOBAL.name: IdlePath | list[IdlePath]
|
SoftScope.GLOBAL.name: IdlePath | list[IdlePath]
|
||||||
}, total=False)
|
}, total=False)
|
||||||
|
|
||||||
|
def _AppsInit(self, CONFIG = None, DATA = None, MEM = None, EXE = None):
|
||||||
|
self.CONFIG = CONFIG
|
||||||
|
self.DATA = DATA
|
||||||
|
self.MEM = MEM
|
||||||
|
self.EXE = EXE
|
||||||
__app_input = {
|
__app_input = {
|
||||||
SoftPathGroup.CONFIG.name: {
|
SoftPathGroup.CONFIG.name: {
|
||||||
SoftScope.PERSONAL.name: [],
|
SoftScope.PERSONAL.name: [],
|
||||||
@@ -77,25 +77,30 @@ class Software:
|
|||||||
SoftScope.PERSONAL.name: [],
|
SoftScope.PERSONAL.name: [],
|
||||||
SoftScope.LOCAL.name: [],
|
SoftScope.LOCAL.name: [],
|
||||||
SoftScope.GLOBAL.name: []
|
SoftScope.GLOBAL.name: []
|
||||||
}
|
},
|
||||||
|
"__init__": _AppsInit
|
||||||
}
|
}
|
||||||
_Apps = type("_Apps", (), __app_input)
|
_Apps = type("_Apps", (), __app_input)
|
||||||
|
|
||||||
|
# @TODO continue adding magic methods to below class
|
||||||
|
# @NOTE https://rszalski.github.io/magicmethods/#sequence
|
||||||
|
class Software:
|
||||||
__user_path: ExecutedPath = USER_PATH
|
__user_path: ExecutedPath = USER_PATH
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._fqdn: str | None = None
|
self._fqdn: str | None = None
|
||||||
|
|
||||||
# @TODO fix NameError for 'Software' in parameter type check
|
# @TODO fix NameError for 'Software' in parameter type check
|
||||||
def declare(self, name: str, **kwpaths: Software._SubAppParams) -> Software._AppParams:
|
def declare(self, name: str, **kwpaths: _SubAppParams) -> _AppParams:
|
||||||
keyword_args: Software._AppParams = kwpaths
|
keyword_args: _AppParams = kwpaths
|
||||||
|
|
||||||
app = Software._Apps(**keyword_args)
|
app = _Apps(**keyword_args)
|
||||||
setattr(self, name, app)
|
setattr(self, name, app)
|
||||||
return app
|
return app
|
||||||
|
|
||||||
def __getitem__(self, key: str) -> Software._AppParams | Never:
|
def __getitem__(self, key: str) -> _AppParams | Never:
|
||||||
if hasattr(self, key):
|
if hasattr(self, key):
|
||||||
app: Software._Apps = getattr(self, key)
|
app: _Apps = getattr(self, key)
|
||||||
else:
|
else:
|
||||||
raise KeyError
|
raise KeyError
|
||||||
return app
|
return app
|
||||||
@@ -104,13 +109,13 @@ class Software:
|
|||||||
if len(value) < 1 or len(value) > 3:
|
if len(value) < 1 or len(value) > 3:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
|
||||||
app_params: Software._SubAppParams = value
|
app_params: _SubAppParams = value
|
||||||
|
|
||||||
if hasattr(self, key[0]):
|
if hasattr(self, key[0]):
|
||||||
app: Software._Apps = getattr(self, key[0])
|
app: _Apps = getattr(self, key[0])
|
||||||
|
|
||||||
if hasattr(app, key[1]):
|
if hasattr(app, key[1]):
|
||||||
app_child: Software._SubAppParams = getattr(app, key[1])
|
app_child: _SubAppParams = getattr(app, key[1])
|
||||||
|
|
||||||
for k, v in app_params.items():
|
for k, v in app_params.items():
|
||||||
v = [v] if not isinstance(v, list) else v
|
v = [v] if not isinstance(v, list) else v
|
||||||
@@ -133,14 +138,14 @@ class Software:
|
|||||||
if len(key) == 1:
|
if len(key) == 1:
|
||||||
delattr(self, key[0])
|
delattr(self, key[0])
|
||||||
elif len(key) > 1:
|
elif len(key) > 1:
|
||||||
app: Software._Apps = getattr(self, key[0])
|
app: _Apps = getattr(self, key[0])
|
||||||
delattr(app, key[1])
|
delattr(app, key[1])
|
||||||
setattr(self, key[0], app)
|
setattr(self, key[0], app)
|
||||||
|
|
||||||
def list(self, contents: bool = False) -> tuple[str]:
|
def list(self, contents: bool = False) -> tuple[str]:
|
||||||
apps: tuple[str] | tuple[Software._Apps] = tuple(
|
apps: tuple[str] | tuple[_Apps] = tuple(
|
||||||
filter(
|
filter(
|
||||||
lambda a: isinstance(getattr(self, a), Software._Apps),
|
lambda a: isinstance(getattr(self, a), _Apps),
|
||||||
dir(self)
|
dir(self)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -158,7 +163,7 @@ class Software:
|
|||||||
def __len__(self) -> int:
|
def __len__(self) -> int:
|
||||||
apps: tuple[str] = tuple(
|
apps: tuple[str] = tuple(
|
||||||
filter(
|
filter(
|
||||||
lambda a: isinstance(getattr(self, a), Software._Apps),
|
lambda a: isinstance(getattr(self, a), _Apps),
|
||||||
dir(self)
|
dir(self)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user