workin on a new structure for the setup stuff

master
Jordan Orelli 2 years ago
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>'

@ -7,6 +7,7 @@ from . import host
from . import sections
from . import targets
from .options import Options
from .resource import Resource
class Installer:
"""
@ -19,6 +20,10 @@ class Installer:
"""
runs the install process
"""
if self.options.x:
self.run_x()
return
if host.is_windows and not host.is_admin:
print("You are not admin: admin is required on Windows")
sys.exit(1)
@ -49,6 +54,15 @@ class Installer:
if host.is_windows:
self.map_section('map.windows')
def run_x(self):
config = self.options.config
for section_name in config.sections():
print("sections:")
print(f" {section_name}")
if r := Resource.from_name(section_name):
print(f" {r}")
r.parse_section(config[section_name])
@cached_property
def targets(self):
"""

@ -18,16 +18,7 @@ class Options:
"""
creates an options object by parsing the command-line
"""
parser = argparse.ArgumentParser(
prog = 'install',
description = """
installs preferences files. This is designed to work on a bunch
of different systems, and can manage Windows preferences from
WSL.
""")
parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('-q', '--quiet', action='store_true')
parser.add_argument('-c', '--config', help="path to config file")
parser = cls.create_cli_parser()
options = cls()
parser.parse_args(namespace=options)
@ -39,6 +30,19 @@ class Options:
return options
@classmethod
def create_cli_parser(cls):
parser = argparse.ArgumentParser(
prog = 'install',
description = """
installs preferences files.
""")
parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('-q', '--quiet', action='store_true')
parser.add_argument('-c', '--config', help="path to config file")
parser.add_argument('-x', action='store_true')
return parser
@property
def quiet(self):
# pylint: disable=missing-function-docstring

@ -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…
Cancel
Save