fix, refactor: debugged circular class ref via refactor & renaming
This commit is contained in:
133
softman.py
133
softman.py
@@ -24,78 +24,83 @@ class SoftPathGroup(Enum):
|
||||
MEM = 2
|
||||
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", {
|
||||
SoftPathGroup.CONFIG.name: {
|
||||
SoftScope.PERSONAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.LOCAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.GLOBAL.name: IdlePath | list[IdlePath]
|
||||
},
|
||||
SoftPathGroup.DATA.name: {
|
||||
SoftScope.PERSONAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.LOCAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.GLOBAL.name: IdlePath | list[IdlePath]
|
||||
},
|
||||
SoftPathGroup.MEM.name: {
|
||||
SoftScope.PERSONAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.LOCAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.GLOBAL.name: IdlePath | list[IdlePath]
|
||||
},
|
||||
SoftPathGroup.EXE.name: {
|
||||
SoftScope.PERSONAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.LOCAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.GLOBAL.name: IdlePath | list[IdlePath]
|
||||
}
|
||||
}, total=False)
|
||||
_SubAppParams = Dict("_SubAppParams", {
|
||||
_AppParams = Dict("_AppParams", {
|
||||
SoftPathGroup.CONFIG.name: {
|
||||
SoftScope.PERSONAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.LOCAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.GLOBAL.name: IdlePath | list[IdlePath]
|
||||
},
|
||||
SoftPathGroup.DATA.name: {
|
||||
SoftScope.PERSONAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.LOCAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.GLOBAL.name: IdlePath | list[IdlePath]
|
||||
},
|
||||
SoftPathGroup.MEM.name: {
|
||||
SoftScope.PERSONAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.LOCAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.GLOBAL.name: IdlePath | list[IdlePath]
|
||||
},
|
||||
SoftPathGroup.EXE.name: {
|
||||
SoftScope.PERSONAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.LOCAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.GLOBAL.name: IdlePath | list[IdlePath]
|
||||
}, total=False)
|
||||
|
||||
__app_input = {
|
||||
SoftPathGroup.CONFIG.name: {
|
||||
SoftScope.PERSONAL.name: [],
|
||||
SoftScope.LOCAL.name: [],
|
||||
SoftScope.GLOBAL.name: []
|
||||
},
|
||||
SoftPathGroup.DATA.name: {
|
||||
SoftScope.PERSONAL.name: [],
|
||||
SoftScope.LOCAL.name: [],
|
||||
SoftScope.GLOBAL.name: []
|
||||
},
|
||||
SoftPathGroup.MEM.name: {
|
||||
SoftScope.PERSONAL.name: [],
|
||||
SoftScope.LOCAL.name: [],
|
||||
SoftScope.GLOBAL.name: []
|
||||
},
|
||||
SoftPathGroup.EXE.name: {
|
||||
SoftScope.PERSONAL.name: [],
|
||||
SoftScope.LOCAL.name: [],
|
||||
SoftScope.GLOBAL.name: []
|
||||
}
|
||||
}
|
||||
_Apps = type("_Apps", (), __app_input)
|
||||
}, total=False)
|
||||
_SubAppParams = Dict("_SubAppParams", {
|
||||
SoftScope.PERSONAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.LOCAL.name: IdlePath | list[IdlePath],
|
||||
SoftScope.GLOBAL.name: IdlePath | list[IdlePath]
|
||||
}, 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 = {
|
||||
SoftPathGroup.CONFIG.name: {
|
||||
SoftScope.PERSONAL.name: [],
|
||||
SoftScope.LOCAL.name: [],
|
||||
SoftScope.GLOBAL.name: []
|
||||
},
|
||||
SoftPathGroup.DATA.name: {
|
||||
SoftScope.PERSONAL.name: [],
|
||||
SoftScope.LOCAL.name: [],
|
||||
SoftScope.GLOBAL.name: []
|
||||
},
|
||||
SoftPathGroup.MEM.name: {
|
||||
SoftScope.PERSONAL.name: [],
|
||||
SoftScope.LOCAL.name: [],
|
||||
SoftScope.GLOBAL.name: []
|
||||
},
|
||||
SoftPathGroup.EXE.name: {
|
||||
SoftScope.PERSONAL.name: [],
|
||||
SoftScope.LOCAL.name: [],
|
||||
SoftScope.GLOBAL.name: []
|
||||
},
|
||||
"__init__": _AppsInit
|
||||
}
|
||||
_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
|
||||
|
||||
def __init__(self):
|
||||
self._fqdn: str | None = None
|
||||
|
||||
# @TODO fix NameError for 'Software' in parameter type check
|
||||
def declare(self, name: str, **kwpaths: Software._SubAppParams) -> Software._AppParams:
|
||||
keyword_args: Software._AppParams = kwpaths
|
||||
def declare(self, name: str, **kwpaths: _SubAppParams) -> _AppParams:
|
||||
keyword_args: _AppParams = kwpaths
|
||||
|
||||
app = Software._Apps(**keyword_args)
|
||||
app = _Apps(**keyword_args)
|
||||
setattr(self, name, app)
|
||||
return app
|
||||
|
||||
def __getitem__(self, key: str) -> Software._AppParams | Never:
|
||||
def __getitem__(self, key: str) -> _AppParams | Never:
|
||||
if hasattr(self, key):
|
||||
app: Software._Apps = getattr(self, key)
|
||||
app: _Apps = getattr(self, key)
|
||||
else:
|
||||
raise KeyError
|
||||
return app
|
||||
@@ -104,13 +109,13 @@ class Software:
|
||||
if len(value) < 1 or len(value) > 3:
|
||||
raise ValueError
|
||||
|
||||
app_params: Software._SubAppParams = value
|
||||
app_params: _SubAppParams = value
|
||||
|
||||
if hasattr(self, key[0]):
|
||||
app: Software._Apps = getattr(self, key[0])
|
||||
app: _Apps = getattr(self, key[0])
|
||||
|
||||
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():
|
||||
v = [v] if not isinstance(v, list) else v
|
||||
@@ -133,14 +138,14 @@ class Software:
|
||||
if len(key) == 1:
|
||||
delattr(self, key[0])
|
||||
elif len(key) > 1:
|
||||
app: Software._Apps = getattr(self, key[0])
|
||||
app: _Apps = getattr(self, key[0])
|
||||
delattr(app, key[1])
|
||||
setattr(self, key[0], app)
|
||||
|
||||
def list(self, contents: bool = False) -> tuple[str]:
|
||||
apps: tuple[str] | tuple[Software._Apps] = tuple(
|
||||
apps: tuple[str] | tuple[_Apps] = tuple(
|
||||
filter(
|
||||
lambda a: isinstance(getattr(self, a), Software._Apps),
|
||||
lambda a: isinstance(getattr(self, a), _Apps),
|
||||
dir(self)
|
||||
)
|
||||
)
|
||||
@@ -158,7 +163,7 @@ class Software:
|
||||
def __len__(self) -> int:
|
||||
apps: tuple[str] = tuple(
|
||||
filter(
|
||||
lambda a: isinstance(getattr(self, a), Software._Apps),
|
||||
lambda a: isinstance(getattr(self, a), _Apps),
|
||||
dir(self)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user