Add READMEs

This commit is contained in:
Edgar P. Burkhart 2023-05-16 09:32:52 +02:00
parent fbdcc4ec39
commit b85cf3b580
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
9 changed files with 14 additions and 159 deletions

1
.gitignore vendored
View file

@ -1 +0,0 @@
__pycache__

2
README.md Normal file
View file

@ -0,0 +1,2 @@
# Config
Config files for the software I use.

View file

@ -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", ""])

View file

@ -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)

View file

@ -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

2
src/Git/README.md Normal file
View file

@ -0,0 +1,2 @@
# Git
Install to `~/.gitconfig`.

5
src/Neovim/README.md Normal file
View file

@ -0,0 +1,5 @@
# Neovim
## Linux
Install to `~/.config/nvim/init.vim`.
## Windows
Install to `$HOME\AppData\Local\nvim\init.vim`.

5
src/PowerShell/README.md Normal file
View file

@ -0,0 +1,5 @@
# Powershell
Install to `$HOME\Documents\PowerShell\Profile.ps1`.
## Older versions
Install to `$HOME\Documents\WindowsPowerShell\Profile.ps1`.

View file

@ -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"