about summary refs log tree commit diff
path: root/libs
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2025-09-07 17:32:13 +0200
committerRobert Günzler <r@gnzler.io>2025-09-25 12:56:47 +0200
commit332d333fa24c8b1943799aadb017f61e642008e1 (patch)
treeab16099639357fc94984c0c85322856b875ed403 /libs
parent38be6c13f76e893cf47636257071b440dec0c5b2 (diff)
libs: refactor recursive files helper
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to 'libs')
-rw-r--r--libs/gen.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/libs/gen.py b/libs/gen.py
index 7d68496..b5c7c93 100644
--- a/libs/gen.py
+++ b/libs/gen.py
@@ -1,15 +1,40 @@
 from pathlib import Path
 from os.path import join
 
+from bundlewrap.items.files import File
+
 
 def add_files_recursive(files, root, common={}, target_root="/", files_root=None):
     if files_root == None:
         files_root = root
 
-    for p in Path(root).rglob("**/*"):
+    root = Path(root)
+    for p in root.rglob("**/*"):
         if not p.is_dir():
             rel = str(p.relative_to(files_root))
             key = join(target_root, rel)
             files[key] = (files[key] if key in files else {}) | common | {
                 "source": rel,
             }
+
+
+def tree(root, common={}, target_dir="/",
+                         keep_parent=True):
+    files = {}
+
+    root = Path(root)
+    for p in Path(root).rglob("**/*"):
+        if not p.is_dir():
+            key = join(target_dir, p.relative_to(
+                root.parent if keep_parent else root))
+            files[key] = (files[key] if key in files else {}) | common | {
+                "source": str(p),
+            }
+
+    return files
+
+def merge(a, b):
+    for key in b.keys():
+        a[key] = (a[key] if key in a else {}) | b[key]
+
+