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.
44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
import configparser
|
|
import json
|
|
import pathlib
|
|
import sys
|
|
from functools import cached_property
|
|
|
|
from . import host
|
|
from . import sections
|
|
from . import targets
|
|
from .options import Options
|
|
from .resource import Resource
|
|
|
|
class Installer:
|
|
"""
|
|
manages the installation of preferences files
|
|
"""
|
|
def __init__(self):
|
|
self.options = Options.from_cli_args()
|
|
|
|
@cached_property
|
|
def config(self):
|
|
path = self.options.config_path
|
|
with open(path, 'r', encoding='utf-8') as config_file:
|
|
parser = configparser.ConfigParser()
|
|
# make keys case-sensitive
|
|
parser.optionxform = str
|
|
parser.read_file(config_file)
|
|
return parser
|
|
|
|
def run(self):
|
|
for name in self.config.sections():
|
|
section = self.config[name]
|
|
if self.when(section):
|
|
r = Resource.from_section(name, section)
|
|
print(f"RUN [{name}]")
|
|
r.run()
|
|
else:
|
|
print(f"SKIP [{name}]")
|
|
|
|
def when(self, section):
|
|
if clause := section.get('when', None):
|
|
return eval(clause)
|
|
return True
|