workin on a new structure for the setup stuff
parent
dada83ed81
commit
850120dc57
@ -0,0 +1,33 @@
|
|||||||
|
class Home:
|
||||||
|
def __init__(self, label = None):
|
||||||
|
self.label = label
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_name(cls, name):
|
||||||
|
"""
|
||||||
|
Builds a Home struct from a given name
|
||||||
|
"""
|
||||||
|
if name.startswith('home'):
|
||||||
|
label = name.removeprefix('home').strip()
|
||||||
|
return cls(label)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def parse_section(self, section):
|
||||||
|
mapping = {
|
||||||
|
'files': self.parse_files
|
||||||
|
}
|
||||||
|
for key in section:
|
||||||
|
if fn := mapping.get(key):
|
||||||
|
val = section[key]
|
||||||
|
fn(val)
|
||||||
|
else:
|
||||||
|
raise KeyError(f"Home has no such config key: {key}")
|
||||||
|
|
||||||
|
def parse_files(self, text):
|
||||||
|
lines = [s for s in text.splitlines() if s]
|
||||||
|
print(f" parse_files: {lines}")
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
if self.label:
|
||||||
|
return f'<Home: {self.label}>'
|
||||||
|
return '<Home>'
|
@ -0,0 +1,17 @@
|
|||||||
|
from .home import Home
|
||||||
|
|
||||||
|
class Resource:
|
||||||
|
resource_types = [Home]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_name(cls, name):
|
||||||
|
"""
|
||||||
|
from_name is to be implemented by resource classes
|
||||||
|
"""
|
||||||
|
for T in cls.resource_types:
|
||||||
|
if r := T.from_name(name):
|
||||||
|
return r
|
||||||
|
return None
|
||||||
|
|
||||||
|
def when(self, when_text):
|
||||||
|
pass
|
Loading…
Reference in New Issue