Compare commits

...

2 Commits

2 changed files with 114 additions and 50 deletions

View File

@@ -21,7 +21,7 @@ class Config:
parent_dir = self.__controller.get_scope(scope, index) parent_dir = self.__controller.get_scope(scope, index)
filepath = Path(parent_dir) / filepath filepath = Path(parent_dir) / filepath
filename: str = filepath.stem filename: str = filepath.name
self.parse_method = "YML" self.parse_method = "YML"
if "." in filename: if "." in filename:

View File

@@ -10,7 +10,7 @@ from typing import TypedDict as Dict
from glob import glob as globbify from glob import glob as globbify
from whereami import USER_PATH from whereami import USER_PATH
from softman import Softs from softman import Softs
import os # import os
class RootFate(Enum): class RootFate(Enum):
disposal = 0 disposal = 0
@@ -225,7 +225,8 @@ class SSHKey:
def reverse(self) -> Never: def reverse(self) -> Never:
if isinstance(self.__value, tuple): if isinstance(self.__value, tuple):
v1, v2 = *self.__value v1 = self.__value[0]
v2 = self.__value[1]
result = self.update(v2, v1) result = self.update(v2, v1)
else: else:
result = self result = self
@@ -253,6 +254,7 @@ def stream_unequal(s1, s2) -> bool | Never:
# @TODO create unit tests for below class # @TODO create unit tests for below class
class SSHKeyCollection(Sequence): class SSHKeyCollection(Sequence):
__user_path: ExecutedPath = USER_PATH __user_path: ExecutedPath = USER_PATH
__ssh_path: ExecutedPath = __user_path / ".ssh"
def __init__(self): def __init__(self):
self.__current: SSHKey | None = None self.__current: SSHKey | None = None
@@ -260,21 +262,54 @@ class SSHKeyCollection(Sequence):
self.__last: SSHKey | None = None self.__last: SSHKey | None = None
self.__indices: range | None = None self.__indices: range | None = None
def __getitem__(self, key: int) -> SSHKey | Never: # @TODO adjust item magic methods for slicing purposes
def __getitem__(self, key: int | slice) -> SSHKey | Never:
self.__current = self.__first self.__current = self.__first
if self.__current is None: if self.__current is None:
raise KeyError raise KeyError
elif int(self.__current) == key:
return self.__current
else:
while int(self.__current) != key:
self.__current = next(self.__current)
if isinstance(key, int):
if int(self.__current) == key:
return self.__current
else:
while int(self.__current) != key:
if self.__current is None:
raise KeyError
self.__current = next(self.__current)
result = self.__current
elif isinstance(key, slice):
step = key.step
sshkcoll = SSHKeyCollection()
range_args = []
if hasattr(key, "start") and getattr(key, "start") is not None:
range_args.append(key.start)
if hasattr(key, "stop") and getattr(key, "stop") is not None:
range_args.append(key.stop)
if hasattr(key, "step") and getattr(key, "step") is not None:
range_args.append(key.step)
indices = range(*range_args)
# test_coll = []
while int(self.__current) < key.stop:
if self.__current is None: if self.__current is None:
raise KeyError raise KeyError
elif int(self.__current) < key.start:
continue
elif int(self.__current) >= key.start:
if int(self.__current) in indices:
sshkcoll.append(self.__current)
test_coll.append(self.__current)
else:
continue
return self.__current self.__current = next(self.__current)
# print(test_coll)
result = sshkcoll
return result
def __len__(self) -> int: def __len__(self) -> int:
if self.__indices is None: if self.__indices is None:
@@ -364,64 +399,72 @@ class SSHKeyCollection(Sequence):
#print(self.__current) #print(self.__current)
return self.__current return self.__current
def __setitem__(self, key: int, *value: ExecutedPath | str) -> None | Never: def __setitem__(self, key: int | slice, *value: ExecutedPath | str) -> None | Never:
if len(value) < 1 or len(value) > 2: if len(value) < 1 or len(value) > 2:
raise ValueError raise ValueError
value = tuple(map(lambda s: Path(s) if isinstance(s, str) else s, value)) value = tuple(map(lambda s: Path(s) if isinstance(s, str) else s, value))
self.__current = self.__first self.__current = self.__first
if self.__current is None: if self.__current is None:
raise KeyError raise KeyError
elif int(self.__current) == key:
if self.__current() is None or len(self.__current()) < 1: if isinstance(key, int):
self.__current(*value)
else:
if int(self.__current) == key: if int(self.__current) == key:
return self.__current(*value) if self.__current() is None or len(self.__current()) < 1:
self.__current(*value)
else:
if int(self.__current) == key:
return self.__current(*value)
while int(self.__current) != key: while int(self.__current) != key:
self.__current = next(self.__current) if self.__current is None:
raise KeyError
if self.__current is None: self.__current = next(self.__current)
raise KeyError
self.__current(*value) self.__current(*value)
elif isinstance(key, slice):
raise NotImplementedError
def __delitem__(self, key: int) -> None | Never: def __delitem__(self, key: int | slice) -> None | Never:
self.__current = self.__first self.__current = self.__first
if self.__current is None: if self.__current is None:
raise KeyError raise KeyError
if key == -1: if isinstance(key, int):
if self.__last is not None: if key == -1:
self.__last._SSHKey__prev._SSHKey__next = None if self.__last is not None:
self.__last = self.__last._SSHKey__prev self.__last._SSHKey__prev._SSHKey__next = None
self.__last = self.__last._SSHKey__prev
self.__current = self.__last self.__current = self.__last
else:
self.__first = None
return past
elif key <= -2:
raise NotImplementedError
else: else:
self.__first = None while int(self.__current) != key:
return past self.__current = next(self.__current)
elif key <= -2:
if self.__current is None:
raise KeyError
count = self.__current._SSHKey__idx
prior = self.__current._SSHKey__prev
posterior = self.__current._SSHKey__next
posterior._SSHKey__prev = prior
posterior._SSHKey__prev._SSHKey__next = posterior
self.__current = posterior
while self.__current is not None:
self.__current._SSHKey__idx = count
self.__current = next(self.__current)
count += 1
elif isinstance(key, slice):
raise NotImplementedError raise NotImplementedError
else:
while int(self.__current) != key:
self.__current = next(self.__current)
if self.__current is None:
raise KeyError
count = self.__current._SSHKey__idx
prior = self.__current._SSHKey__prev
posterior = self.__current._SSHKey__next
posterior._SSHKey__prev = prior
posterior._SSHKey__prev._SSHKey__next = posterior
self.__current = posterior
while self.__current is not None:
self.__current._SSHKey__idx = count
self.__current = next(self.__current)
count += 1
@property @property
def head(self) -> SSHKey | None: def head(self) -> SSHKey | None:
@@ -440,15 +483,31 @@ class SSHKeyCollection(Sequence):
def __missing__(self) -> Never: def __missing__(self) -> Never:
raise NotImplementedError raise NotImplementedError
def __iter__(self) -> Self | Never: def __next__(self):
raise NotImplementedError raise NotImplementedError
def __iter__(self) -> Self | Never:
self.__Current = self.__first
return self.__current
def count(self, query: RegEx | str) -> int | Never: def count(self, query: RegEx | str) -> int | Never:
raise NotImplementedError raise NotImplementedError
# @TODO make sure to implement below method # @TODO make sure to implement below method
def pull(self, query: RegEx | str = "*") -> Never: def pull(self, query: RegEx | str = "*") -> Never:
raise NotImplementedError if isinstance(query, RegEx):
keypaths = self.__ssh_path.glob("*")
for p in keypaths:
if query.fullmatch(p.name):
self.append(p)
else:
continue
else:
keypaths = self.__ssh_path.glob(query)
for p in keypaths:
self.append(p)
def reverse(self) -> None | Never: def reverse(self) -> None | Never:
raise NotImplementedError raise NotImplementedError
@@ -465,3 +524,8 @@ class UserSSH:
self.keys = keys self.keys = keys
self.password = password self.password = password
self.fate = fate self.fate = fate
sshkey_coll = SSHKeyCollection()
sshkey_coll.pull()
# print(len(sshkey_coll) + 2)
print(sshkey_coll[0:4][3])