From b85cf3b5801085bbfb88d0c8ab325e49e659d682 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Tue, 16 May 2023 09:32:52 +0200 Subject: [PATCH] Add READMEs --- .gitignore | 1 - README.md | 2 + config/__init__.py | 16 -------- config/__main__.py | 84 ---------------------------------------- config/log.conf | 27 ------------- src/Git/README.md | 2 + src/Neovim/README.md | 5 +++ src/PowerShell/README.md | 5 +++ src/windows.toml | 31 --------------- 9 files changed, 14 insertions(+), 159 deletions(-) delete mode 100644 .gitignore create mode 100644 README.md delete mode 100644 config/__init__.py delete mode 100644 config/__main__.py delete mode 100644 config/log.conf create mode 100644 src/Git/README.md create mode 100644 src/Neovim/README.md create mode 100644 src/PowerShell/README.md delete mode 100644 src/windows.toml diff --git a/.gitignore b/.gitignore deleted file mode 100644 index bee8a64..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -__pycache__ diff --git a/README.md b/README.md new file mode 100644 index 0000000..6e7e4f3 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Config +Config files for the software I use. diff --git a/config/__init__.py b/config/__init__.py deleted file mode 100644 index b28de85..0000000 --- a/config/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -import pathlib - - -def make_abs_path(path, root): - if not path.is_absolute(): - return root.joinpath(path) - return path - -def get_io(conf, root): - return ( - make_abs_path(pathlib.Path(conf.get("in")).expanduser(), root), - make_abs_path(pathlib.Path(conf.get("out")).expanduser(), root), - ) - -def get_yn(args, prompt): - return args.default_yes or (not args.default_no and input(prompt).strip().lower() in ["y", ""]) diff --git a/config/__main__.py b/config/__main__.py deleted file mode 100644 index 41591c7..0000000 --- a/config/__main__.py +++ /dev/null @@ -1,84 +0,0 @@ -import argparse -import logging -import logging.config -import pathlib -import shutil -import subprocess -import sys -import tomllib - -from . import get_io, get_yn - - -logging.config.fileConfig(pathlib.Path(__file__).with_name("log.conf")) -log = logging.getLogger("config") - -_argp = argparse.ArgumentParser( - prog="Config", - description="Install custom configurations", -) - -_argp.add_argument("-c", "--config", default="config.toml", type=pathlib.Path, help="Configuration file location") -_argp.add_argument("-y", "--default-yes", action="store_true", help="Default yes to questions") -_argp.add_argument("-n", "--default-no", action="store_true", help="Default no to questions") - -args = _argp.parse_args() - -log.info("Config installation starting") - -log.info(f"Loading configuration file <{args.config}>.") -try: - with open(args.config, "rb") as _config_file: - config = tomllib.load(_config_file) -except FileNotFoundError: - log.error(f"Configuration file <{args.config}> does not exist.") - sys.exit(1) - -_root = args.config.parent - -for _name, _conf in config.items(): - match _name.lower(): - case "winget": - log.info("Installing packages using winget.") - for _package in _conf.get("packages"): - _test = subprocess.run(("winget", "list", "--id", _package)) - if _test.returncode == 0: - if not get_yn(args, f"<{_package}> is already installed; reinstall [Yn] ? "): - log.info(f"> Skipping <{_package}> install.") - continue - log.info(f"> Installing {_package} using winget.") - subprocess.run(("winget", "install", _package)) - case "windowsoptionalfeatures": - log.info("Enabling Windows Optional Features.") - for _feature in _conf.get("features"): - log.info(f"> Enabling {_feature}.") - subprocess.run(("dism", "-Online", "-Add-Capability", f"-CapabilityName:{_feature}")) - case _: - _in, _out = get_io(_conf, _root) - log.info(f"Installing {_name} configuration from <{_in}> to <{_out}>.") - if not _in.is_file(): - log.error(f"> {_name} configuration <{_in}> could not be found.") - sys.exit(1) - - if _out.exists(): - if _out.is_file(): - if not get_yn(args, f"<{_out}> already exists; replace [Yn] ? "): - log.info(f"> Skipping {_name} configuration.") - continue - else: - log.info(f"> Installing {_name} configuration.") - else: - log.error(f"> <{_out}> already exists and is not a file.") - sys.exit(1) - - if not _out.parent.exists(): - _out.parent.mkdir(parents=True) - elif not _out.parent.is_dir(): - log.error(f"> {_name} configuration could not be installed as <{_out.parent}> is not a directory.") - sys.exit(1) - - try: - shutil.copyfile(_in, _out) - except OSError: - log.error(f"> {_name} could not be configured: destination <{_out}> is not writable.") - sys.exit(1) diff --git a/config/log.conf b/config/log.conf deleted file mode 100644 index 45dca6f..0000000 --- a/config/log.conf +++ /dev/null @@ -1,27 +0,0 @@ -[loggers] -keys=root,config - -[handlers] -keys=consoleHandler - -[formatters] -keys=simpleFormatter - -[logger_root] -level=INFO -handlers=consoleHandler - -[logger_config] -level=INFO -handlers=consoleHandler -qualName=config -propagate=0 - -[handler_consoleHandler] -class=StreamHandler -level=INFO -formatter=simpleFormatter -args=(sys.stdout,) - -[formatter_simpleFormatter] -format=%(asctime)s - %(name)s#%(levelname)s %(message)s diff --git a/src/Git/README.md b/src/Git/README.md new file mode 100644 index 0000000..9b70e42 --- /dev/null +++ b/src/Git/README.md @@ -0,0 +1,2 @@ +# Git +Install to `~/.gitconfig`. diff --git a/src/Neovim/README.md b/src/Neovim/README.md new file mode 100644 index 0000000..58ea513 --- /dev/null +++ b/src/Neovim/README.md @@ -0,0 +1,5 @@ +# Neovim +## Linux +Install to `~/.config/nvim/init.vim`. +## Windows +Install to `$HOME\AppData\Local\nvim\init.vim`. diff --git a/src/PowerShell/README.md b/src/PowerShell/README.md new file mode 100644 index 0000000..303c75c --- /dev/null +++ b/src/PowerShell/README.md @@ -0,0 +1,5 @@ +# Powershell +Install to `$HOME\Documents\PowerShell\Profile.ps1`. + +## Older versions +Install to `$HOME\Documents\WindowsPowerShell\Profile.ps1`. diff --git a/src/windows.toml b/src/windows.toml deleted file mode 100644 index 374ede6..0000000 --- a/src/windows.toml +++ /dev/null @@ -1,31 +0,0 @@ -[Winget] -packages = [ - "Git.Git", - "Neovim.Neovim", - "GnuPG.GnuPG", - "SyncTrayzor.SyncTrayzor", - "Discord.Discord", - "Microsoft.PowerToys", - #"Microsoft.Office", - "Mozilla.Thunderbird", - "Valve.Steam", - "EpicGames.EpicGamesLauncher", - "GOG.Galaxy", -] - -[WindowsOptionalFeatures] -features = [ - "Media.MediaFeaturePack" -] - -[PowerShell] -in="PowerShell/profile.ps1" -out="~/Documents/WindowsPowerShell/profile.ps1" - -[Git] -in="Git/gitconfig-win" -out="~/.gitconfig" - -[Neovim] -in="Neovim/init.vim" -out="~/AppData/Local/nvim/init.vim"