summaryrefslogtreecommitdiff
path: root/apply/apply.py
diff options
context:
space:
mode:
Diffstat (limited to 'apply/apply.py')
-rwxr-xr-xapply/apply.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/apply/apply.py b/apply/apply.py
new file mode 100755
index 0000000..8042a1d
--- /dev/null
+++ b/apply/apply.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+
+import yaml
+import os
+from pathlib import Path
+import argparse
+
+from .resolv import Resolver
+from .writer import Writer
+from .state import StateFile
+
+
+class DirReader:
+ def __init__(self, config, resolv):
+ self.resolv = resolv
+ self.config = config
+
+ def read_package(self, name):
+ package_root = name
+
+ # Walk down and link dir og file
+ for root, dirs, files in os.walk(package_root):
+ rootrel = os.path.relpath(root, start=package_root)
+
+ # Check if we can just link this folder
+ if rootrel not in self.config["do_not_link"]:
+ ok = self.resolv.do_folder_link(name, Path(rootrel))
+
+ if ok:
+ # Do not go further down
+ dirs.clear()
+ continue
+
+ # Link files
+ for f in files:
+ self.resolv.do_link(name, Path(rootrel, f))
+
+
+def cmd_args(parser: argparse.ArgumentParser):
+ parser.add_argument("packages", nargs="*", help="Packages to apply")
+
+
+def cmd_func(args, config):
+ writer = Writer()
+ state = StateFile(args.apply_dir)
+ resolv = Resolver(args.apply_dir, writer, state,
+ args.override_existing)
+
+ reader = DirReader(config, resolv)
+ for pack in args.packages:
+ reader.read_package(pack)
+
+ writer.apply(dry_run=args.dry_run)
+ if not args.dry_run:
+ state.dump_state()
+
+
+cmd_help = "Apply modules from current directory"