You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
903 B
Python

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>'