X-Git-Url: https://git.ralfj.de/bubblebox.git/blobdiff_plain/1a71f2b54e8248af43e8d82a3c009a35a1d8f1aa..2852b9f44cd053bab63c0d063fdcfeb84e41a2c4:/bubblebox.py diff --git a/bubblebox.py b/bubblebox.py index d7c6cb0..5b82322 100644 --- a/bubblebox.py +++ b/bubblebox.py @@ -122,6 +122,13 @@ class Access: Write = 1 Device = 2 + def WriteTo(host_path): + '''Bind-mount a particular host path here (writable)''' + access = Access() + access.flag = "--bind" + access.host_path = host_path + return access + def flag(val): if val == Access.Read: return "--ro-bind" @@ -131,6 +138,7 @@ class Access: return "--dev-bind" else: raise Exception(f"invalid access value: {val}") + def host_access(dirs): def expand(root, names): """`names` is one or more strings that can contain globs. Expand them all relative to `root`.""" @@ -144,7 +152,10 @@ def host_access(dirs): path = path.replace("//", "/") path = path.removesuffix("/.") # glob expansion - yield from glob.glob(path) + globbed = glob.glob(path) + if len(globbed) == 0: + raise Exception(f"Path does not exist: {path}") + yield from globbed def recursive_host_access(root, dirs, out): for names, desc in dirs.items(): for path in expand(root, names): @@ -152,8 +163,11 @@ def host_access(dirs): # Recurse into children recursive_host_access(path, desc, out) else: + assert isinstance(desc, Access) or isinstance(desc, int), f"unexpected access object: {desc}" # Allow access to this path - out.extend((Access.flag(desc), path, path)) + host_path = desc.host_path if isinstance(desc, Access) else path + flag = desc.flag if isinstance(desc, Access) else Access.flag(desc) + out.extend((flag, path, host_path)) # Start the recursive traversal out = [] recursive_host_access("", dirs, out) @@ -162,5 +176,8 @@ def host_access(dirs): def home_access(dirs): return host_access({ HOME: dirs }) +def home_symlink(dest, link): + return bwrap_flags("--symlink", HOME + dest, HOME + link) + # Profile the profiles when importing bubblebox. import profiles