summaryrefslogtreecommitdiff
path: root/apply/writer.py
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-04-25 20:12:25 +0200
committerJulian T <julian@jtle.dk>2021-04-25 20:12:25 +0200
commit7e93444f28a6790ab66fbdd8cc7eed9ca8970d48 (patch)
treefec5eb7eb328948d5c30d2e1d56e4c570d5dcc4c /apply/writer.py
parent0c24ead1cb0126a1847c2ed971649e9ee25e920e (diff)
Add kind of working delete command
Diffstat (limited to 'apply/writer.py')
-rw-r--r--apply/writer.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/apply/writer.py b/apply/writer.py
index d6a5550..9c23128 100644
--- a/apply/writer.py
+++ b/apply/writer.py
@@ -7,6 +7,7 @@ class Writer:
self.links_todo = {}
self.dirs_todo = []
self.delete_todo = []
+ self.apply_hook = []
def create_link(self, target: Path, linkpath: Path):
if linkpath in self.links_todo:
@@ -26,14 +27,17 @@ class Writer:
self.delete_todo.append(path)
- def apply_dir(self, path: Path, dry_run):
+ def attach_hook(self, hook):
+ self.apply_hook.append(hook)
+
+ def __apply_dir(self, path: Path, dry_run):
print(f"mkdir {path}")
if not dry_run:
path.mkdir()
- def apply_delete(self, path: Path, dry_run):
- if path.is_dir():
- print(f"rmtree {path}!!!")
+ def __apply_delete(self, path: Path, dry_run):
+ if not path.is_symlink() and path.is_dir():
+ print(f"rmtree {path}")
if not dry_run:
shutil.rmtree(str(path))
else:
@@ -41,17 +45,20 @@ class Writer:
if not dry_run:
path.unlink()
- def apply_link(self, linkpath: Path, target: Path, dry_run):
+ def __apply_link(self, linkpath: Path, target: Path, dry_run):
print(f"link {linkpath} -> {target}")
if not dry_run:
linkpath.symlink_to(target)
def apply(self, dry_run=True):
for d in self.delete_todo:
- self.apply_delete(d, dry_run)
+ self.__apply_delete(d, dry_run)
for d in self.dirs_todo:
- self.apply_dir(d, dry_run)
+ self.__apply_dir(d, dry_run)
for link, target in self.links_todo.items():
- self.apply_link(link, target, dry_run)
+ self.__apply_link(link, target, dry_run)
+
+ for hook in self.apply_hook:
+ hook(dry_run)