sourcing user config as default config; fixing pre-commit

This commit is contained in:
JesseBot 2023-03-18 17:25:21 +01:00
parent 3f42509a86
commit f3e69133c7
No known key found for this signature in database
GPG key ID: C01D207CE04D55D9
5 changed files with 40 additions and 48 deletions

4
.gitignore vendored
View file

@ -54,10 +54,6 @@ coverage.xml
# any locally generated log stuff:
*.log
# Flask stuff:
instance/
.webassets-cache
# PyBuilder
target/

View file

@ -5,4 +5,4 @@ repos:
# make sure the poetry config does not get committed in a broken state
- id: poetry-check
# make sure the lock file is up-to-date when committing changes
- id: poetry-lock
# - id: poetry-lock

View file

@ -91,17 +91,17 @@ def setup_logger(level="", log_file=""):
@option('--remote_host', '-r', metavar="IP_ADDR", multiple=True,
help=HELP['remote_host'])
@option('--version', is_flag=True, help=HELP['version'])
def main(log_level: str = "WARN",
log_file: str = "",
steps: str = STEPS.join(','),
git_url: str = "https://github.com/jessebot/dot_files.git",
git_branch: str = "main",
overwrite: bool = False,
pkg_managers: str = PKG_MNGRS.join(','),
pkg_groups: str = "default",
firewall: bool = False,
remote_host: str = "",
version: bool = False):
def main(log_level: str = USR_CONFIG_FILE['log']['level'],
log_file: str = USR_CONFIG_FILE['log']['file'],
steps: str = USR_CONFIG_FILE['steps'][OS[0]],
git_url: str = USR_CONFIG_FILE['dot_files']['git_url'],
git_branch: str = USR_CONFIG_FILE['dot_files']['git_branch'],
overwrite: bool = USR_CONFIG_FILE['dot_files']['overwrite'],
pkg_managers: str = USR_CONFIG_FILE['package']['managers'][OS[0]],
pkg_groups: str = USR_CONFIG_FILE['package']['groups'],
firewall: bool = USR_CONFIG_FILE['firewall'],
remote_host=USR_CONFIG_FILE['remote_hosts'],
version=False) -> bool:
"""
If present, config: XDG_CONFIG_HOME/onboardme/[packages.yml, config.yml]
If run with no options on Linux, it will install brew, pip3.11, apt,
@ -157,7 +157,7 @@ def main(log_level: str = "WARN",
configure_firewall(remote_host)
print_manual_steps()
return
return True
if __name__ == '__main__':

View file

@ -8,6 +8,9 @@ DESCRIPTION:
from importlib.metadata import version as get_version
from xdg_base_dirs import xdg_config_home
from os import getenv, path, uname
from pathlib import Path
import wget
import yaml
# version of onboardme
@ -15,7 +18,6 @@ VERSION = get_version('onboardme')
# pathing
XDG_CONFIG_DIR = xdg_config_home()
ONBOARDME_CONFIG_DIR = path.join(xdg_config_home(), 'onboardme')
PWD = path.dirname(__file__)
HOME_DIR = getenv("HOME")
@ -33,3 +35,26 @@ if OS[0] == 'Darwin':
PKG_MNGRS = ['brew','pip3.11']
if OS[0] == 'Linux':
PKG_MNGRS.extend(['apt','snap','flatpak'])
default_dotfiles = ("https://raw.githubusercontent.com/jessebot/dot_files/"
"main/.config/onboardme/")
def load_cfg(config_file='config.yml') -> dict:
"""
load yaml config files for onboardme
"""
config_dir = path.join(xdg_config_home(), 'onboardme')
config_full_path = path.join(config_dir, config_file)
# defaults
if not path.exists(config_full_path):
Path(config_dir).mkdir(exist_ok=True)
wget.download(default_dotfiles + config_file, config_full_path)
with open(config_full_path, 'r') as yaml_file:
return yaml.safe_load(yaml_file)
USR_CONFIG_FILE = load_cfg()

View file

@ -4,42 +4,13 @@ config variable processing library for onboardme
import logging as log
# for system data, environment data, and checking/joining paths
from os import path
from pathlib import Path
# rich helps pretty print everything
from rich.prompt import Confirm
import yaml
# custom libs
from .constants import OS, ONBOARDME_CONFIG_DIR
from .constants import OS, USR_CONFIG_FILE
from .console_logging import print_panel
import wget
default_dotfiles = ("https://raw.githubusercontent.com/jessebot/dot_files/"
"main/.config/onboardme/")
def load_cfg(config_file: str) -> dict:
"""
load yaml config files for onboardme
"""
config_full_path = path.join(ONBOARDME_CONFIG_DIR, config_file)
# defaults
if not path.exists(config_full_path):
Path(ONBOARDME_CONFIG_DIR).mkdir(exist_ok=True)
wget.download(default_dotfiles + config_file, config_full_path)
with open(config_full_path, 'r') as yaml_file:
return yaml.safe_load(yaml_file)
USR_CONFIG_FILE = load_cfg("config.yml")
def check_os_support():
"""