Skip to content

Commit

Permalink
sourcing user config as default config; fixing pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebot committed Mar 18, 2023
1 parent 3f42509 commit f3e6913
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 48 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ coverage.xml
# any locally generated log stuff:
*.log

# Flask stuff:
instance/
.webassets-cache

# PyBuilder
target/

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yml → .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 12 additions & 12 deletions onboardme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -157,7 +157,7 @@ def main(log_level: str = "WARN",
configure_firewall(remote_host)

print_manual_steps()
return
return True


if __name__ == '__main__':
Expand Down
27 changes: 26 additions & 1 deletion onboardme/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
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
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")

Expand All @@ -33,3 +35,26 @@
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()
31 changes: 1 addition & 30 deletions onboardme/env_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,13 @@

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():
"""
Expand Down

0 comments on commit f3e6913

Please sign in to comment.