feat(commit): individual packages from config respected
This commit is contained in:
+4
-4
@@ -30,18 +30,18 @@ if __name__ == "__main__":
|
|||||||
\\___/
|
\\___/
|
||||||
""")
|
""")
|
||||||
|
|
||||||
print(load_config("config.yml"))
|
conf = load_config("config.yml")
|
||||||
try:
|
try:
|
||||||
if args.cmd == "commit":
|
if args.cmd == "commit":
|
||||||
commit.commit(args.force, args.no_render)
|
commit.commit(conf, args.force, args.no_render)
|
||||||
elif args.cmd == "config":
|
elif args.cmd == "config":
|
||||||
config.config()
|
config.config(conf)
|
||||||
elif args.cmd == "init":
|
elif args.cmd == "init":
|
||||||
init.init(args.force)
|
init.init(args.force)
|
||||||
elif args.cmd == "setup":
|
elif args.cmd == "setup":
|
||||||
setup.setup()
|
setup.setup()
|
||||||
elif args.cmd == "pull":
|
elif args.cmd == "pull":
|
||||||
pull.pull(args.rebase, args.apply)
|
pull.pull(conf, args.rebase, args.apply)
|
||||||
elif args.cmd == "push":
|
elif args.cmd == "push":
|
||||||
push.push(args.force)
|
push.push(args.force)
|
||||||
except KeyboardInterrupt as e:
|
except KeyboardInterrupt as e:
|
||||||
|
|||||||
+3
-2
@@ -3,9 +3,10 @@ from commands.util.diff import pkg_diff
|
|||||||
from commands.util.input_mgr import confirm, password
|
from commands.util.input_mgr import confirm, password
|
||||||
|
|
||||||
from commands.util.printing.diff import print_diff
|
from commands.util.printing.diff import print_diff
|
||||||
|
from config.dtype import ArchMgrConfig
|
||||||
|
|
||||||
|
|
||||||
def commit(force: bool = False, no_render: bool = False):
|
def commit(config: ArchMgrConfig, force: bool = False, no_render: bool = False):
|
||||||
"""Commit the changes to the system
|
"""Commit the changes to the system
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -15,7 +16,7 @@ def commit(force: bool = False, no_render: bool = False):
|
|||||||
"""
|
"""
|
||||||
# TODO: Make sure we don't uninstall critical system packages by accident (i.e. prompt user)
|
# TODO: Make sure we don't uninstall critical system packages by accident (i.e. prompt user)
|
||||||
# Probably do that check in the pacman util lib tho
|
# Probably do that check in the pacman util lib tho
|
||||||
add, remove = pkg_diff([], pacman.list_explicitly_installed())
|
add, remove = pkg_diff(config["pkgs"]["individual"] or [], pacman.list_explicitly_installed())
|
||||||
print_diff(add, remove)
|
print_diff(add, remove)
|
||||||
if confirm(False, "Do you really want to proceed?"):
|
if confirm(False, "Do you really want to proceed?"):
|
||||||
pacman.install_package_list(add)
|
pacman.install_package_list(add)
|
||||||
|
|||||||
+5
-1
@@ -1,4 +1,8 @@
|
|||||||
def config():
|
from config.dtype import ArchMgrConfig
|
||||||
|
|
||||||
|
|
||||||
|
def config(config: ArchMgrConfig):
|
||||||
print("""
|
print("""
|
||||||
Your config can be found at
|
Your config can be found at
|
||||||
""")
|
""")
|
||||||
|
print(config)
|
||||||
|
|||||||
+4
-1
@@ -1,2 +1,5 @@
|
|||||||
def pull(rebase: bool = False, apply: bool = False):
|
from config.dtype import ArchMgrConfig
|
||||||
|
|
||||||
|
|
||||||
|
def pull(config: ArchMgrConfig, rebase: bool = False, apply: bool = False):
|
||||||
print("pull")
|
print("pull")
|
||||||
|
|||||||
+18
-6
@@ -12,11 +12,23 @@ def pkg_diff(target: List[str], actual: List[str]) -> tuple[List[str], List[str]
|
|||||||
A tuple with first the missing (not installed) packages
|
A tuple with first the missing (not installed) packages
|
||||||
and second the extraneous (to be uninstalled) packages
|
and second the extraneous (to be uninstalled) packages
|
||||||
"""
|
"""
|
||||||
for i, pkg in enumerate(actual):
|
removed = []
|
||||||
|
diffed_out = []
|
||||||
|
for pkg in actual:
|
||||||
try:
|
try:
|
||||||
idx = target.index(pkg)
|
diffed_out.append(target.index(pkg))
|
||||||
target.pop(idx)
|
|
||||||
actual.pop(i)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
removed.append(pkg)
|
||||||
return (target, actual)
|
|
||||||
|
diffed_out.reverse()
|
||||||
|
new_pkgs = []
|
||||||
|
if len(diffed_out) > 0:
|
||||||
|
curr = diffed_out.pop()
|
||||||
|
for i, pkg in enumerate(target):
|
||||||
|
if i != curr:
|
||||||
|
new_pkgs.append(pkg)
|
||||||
|
else:
|
||||||
|
if len(diffed_out) > 0:
|
||||||
|
curr = diffed_out.pop()
|
||||||
|
|
||||||
|
return (new_pkgs, removed)
|
||||||
|
|||||||
+3
-1
@@ -6,7 +6,9 @@ requires:
|
|||||||
|
|
||||||
pkgs:
|
pkgs:
|
||||||
individual:
|
individual:
|
||||||
- pkg_name
|
- acpi
|
||||||
|
- tk
|
||||||
|
- tldr
|
||||||
bundles:
|
bundles:
|
||||||
- name: hyprland
|
- name: hyprland
|
||||||
repos:
|
repos:
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ def _load_config_file(file: str):
|
|||||||
|
|
||||||
|
|
||||||
def default_config() -> ArchMgrConfig:
|
def default_config() -> ArchMgrConfig:
|
||||||
|
"""Get the default configuration
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The default config
|
||||||
|
"""
|
||||||
return {
|
return {
|
||||||
"pkgs": {
|
"pkgs": {
|
||||||
"individual": [],
|
"individual": [],
|
||||||
@@ -59,6 +64,14 @@ def default_config() -> ArchMgrConfig:
|
|||||||
|
|
||||||
|
|
||||||
def load_config(file: str) -> ArchMgrConfig:
|
def load_config(file: str) -> ArchMgrConfig:
|
||||||
|
"""Load the configuration from the specified file path
|
||||||
|
|
||||||
|
Args:
|
||||||
|
file: Path to the file to be loaded
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The loaded, validated and parsed config
|
||||||
|
"""
|
||||||
# Load and validate initial config
|
# Load and validate initial config
|
||||||
try:
|
try:
|
||||||
loaded_conf = _load_config_file(file)
|
loaded_conf = _load_config_file(file)
|
||||||
|
|||||||
@@ -3,6 +3,16 @@ from config.dtype import ArchMgrConfig
|
|||||||
|
|
||||||
|
|
||||||
def merge_configs(config: ArchMgrConfig, new_config: ArchMgrConfig) -> ArchMgrConfig:
|
def merge_configs(config: ArchMgrConfig, new_config: ArchMgrConfig) -> ArchMgrConfig:
|
||||||
|
"""Merge two configs, with the new_config taking precedence over the config
|
||||||
|
in the conflicting fields with arrays and dicts merged
|
||||||
|
|
||||||
|
Args:
|
||||||
|
config: Base config
|
||||||
|
new_config: Config to merge into the base config
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The merged config
|
||||||
|
"""
|
||||||
if len(new_config) == 0 or len(config) == 0:
|
if len(new_config) == 0 or len(config) == 0:
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|||||||
+9
-1
@@ -5,7 +5,15 @@ with open("config.schema.json") as file:
|
|||||||
schema = json.load(file)
|
schema = json.load(file)
|
||||||
|
|
||||||
|
|
||||||
def validate(config):
|
def validate(config: dict | list):
|
||||||
|
"""Validate the specified config
|
||||||
|
|
||||||
|
Args:
|
||||||
|
config: The raw configuration
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
True if the config is valid, False otherwise
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
jsonschema.validate(config, schema)
|
jsonschema.validate(config, schema)
|
||||||
except jsonschema.SchemaError:
|
except jsonschema.SchemaError:
|
||||||
|
|||||||
Reference in New Issue
Block a user