xiwrap

slightly higher-level container setup utility
git clone https://git.ce9e.org/xiwrap.git

commit
19cff3d1b17fd00705ccd80602fec2f7086ab808
parent
bb9a54105a5a188a05a59d0010677e2c4ccda5f0
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-08-04 13:03
refactor: destructure push_rule args

Diffstat

M xiwrap.py 25 ++++++++++++-------------

1 files changed, 12 insertions, 13 deletions


diff --git a/xiwrap.py b/xiwrap.py

@@ -104,13 +104,13 @@ class DBusProxy:
  104   104             self.cmd.append(f'--{typ}={value}')
  105   105 
  106   106         wrapper = RuleSet()
  107    -1         wrapper.push_rule('tmpfs', ['/tmp'])
  108    -1         wrapper.push_rule('dev', ['/dev'])
  109    -1         wrapper.push_rule('proc', ['/proc'])
   -1   107         wrapper.push_rule('tmpfs', '/tmp')
   -1   108         wrapper.push_rule('dev', '/dev')
   -1   109         wrapper.push_rule('proc', '/proc')
  110   110         for path in ['/bin', '/lib', '/lib64', '/usr', '/etc', '/run']:
  111    -1             wrapper.push_rule('bind', [path])
   -1   111             wrapper.push_rule('bind', path)
  112   112         if app_id:
  113    -1             wrapper.push_rule('app-id', [app_id])
   -1   113             wrapper.push_rule('app-id', app_id)
  114   114 
  115   115         self.cmd = wrapper.build(self.cmd)
  116   116         self.fds = [sync_fd, *wrapper.fds]
@@ -167,7 +167,7 @@ class RuleSet:
  167   167         if self.sync_fds is None:
  168   168             self.sync_fds = os.pipe2(0)
  169   169 
  170    -1     def push_rule(self, key, args, *, cwd=None):
   -1   170     def push_rule(self, key, *args, cwd=None):
  171   171         if key == 'include':
  172   172             if len(args) != 1:
  173   173                 raise RuleError(key, args)
@@ -178,7 +178,7 @@ class RuleSet:
  178   178                 raise RuleError(key, args)
  179   179             self.app_id = args[0]
  180   180             info = f'[Application]\nname={self.app_id}\n'
  181    -1             self.push_rule('bind-text', [info, '/.flatpak-info'])
   -1   181             self.push_rule('bind-text', info, '/.flatpak-info')
  182   182         elif key in ['share-ipc', 'share-pid', 'share-net']:
  183   183             if len(args) != 0:
  184   184                 raise RuleError(key, args)
@@ -187,7 +187,7 @@ class RuleSet:
  187   187             if len(args) != 1:
  188   188                 raise RuleError(key, args)
  189   189             self.ensure_sync_fds()
  190    -1             self.push_rule('ro-bind', [DBUS_SESSION_SRC, DBUS_SESSION_DEST])
   -1   190             self.push_rule('ro-bind', DBUS_SESSION_SRC, DBUS_SESSION_DEST)
  191   191             self.dbus_session[args[0]] = key.removeprefix('dbus-')
  192   192         elif key in [
  193   193             'dbus-system-see',
@@ -199,7 +199,7 @@ class RuleSet:
  199   199             if len(args) != 1:
  200   200                 raise RuleError(key, args)
  201   201             self.ensure_sync_fds()
  202    -1             self.push_rule('ro-bind', [DBUS_SYSTEM_SRC, DBUS_SYSTEM_DEST])
   -1   202             self.push_rule('ro-bind', DBUS_SYSTEM_SRC, DBUS_SYSTEM_DEST)
  203   203             self.dbus_system[args[0]] = key.removeprefix('dbus-system-')
  204   204         elif key == 'setenv':
  205   205             var, value = self.parse_env(key, args)
@@ -237,8 +237,7 @@ class RuleSet:
  237   237                 if not line or line.startswith('#'):
  238   238                     continue
  239   239                 try:
  240    -1                     parts = line.split()
  241    -1                     self.push_rule(parts[0], parts[1:], cwd=path.parent)
   -1   240                     self.push_rule(*line.split(), cwd=path.parent)
  242   241                 except RuleError as e:
  243   242                     raise SyntaxError(str(e), (path, lineno, 1, line)) from e
  244   243 
@@ -248,7 +247,7 @@ class RuleSet:
  248   247         for i, token in enumerate(argv):
  249   248             if token == '--':
  250   249                 if key is not None:
  251    -1                     self.push_rule(key, args, cwd=Path.cwd())
   -1   250                     self.push_rule(key, *args, cwd=Path.cwd())
  252   251                 return argv[i + 1:]
  253   252             elif token in ['-h', '--help']:
  254   253                 self.usage = True
@@ -256,7 +255,7 @@ class RuleSet:
  256   255                 self.debug = True
  257   256             elif token.startswith('--'):
  258   257                 if key is not None:
  259    -1                     self.push_rule(key, args, cwd=Path.cwd())
   -1   258                     self.push_rule(key, *args, cwd=Path.cwd())
  260   259                 key = token.removeprefix('--')
  261   260                 args = []
  262   261             else: