xiwrap

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

commit
ebd43e64811c84d572ee4caa3e75d04bad0e0f84
parent
fbdbeb1970b083fa58ec1479389d3d4dcfa04e0b
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-06-20 15:16
fix expandvars on missing HOME

Diffstat

M xiwrap.py 12 +++++++-----

1 files changed, 7 insertions, 5 deletions


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

@@ -62,7 +62,7 @@ def expandvars(path, env):
   62    62         return path
   63    63 
   64    64     for var, default in [
   65    -1         ('HOME', None),
   -1    65         ('HOME', ''),
   66    66         ('XDG_DATA_HOME', '.local/share'),
   67    67         ('XDG_CONFIG_HOME', '.config'),
   68    68         ('XDG_STATE_HOME', '.local/state'),
@@ -72,8 +72,8 @@ def expandvars(path, env):
   72    72         if path.startswith(f'${var}'):
   73    73             if env.get(var):
   74    74                 head = Path(env.get(var))
   75    -1             elif default is not None:
   76    -1                 head = Path(env.get('HOME')) / default
   -1    75             elif default is not None and 'HOME' in env:
   -1    76                 head = Path(env['HOME']) / default
   77    77             else:
   78    78                 raise ValueError(
   79    79                     f'Invalid path {path}: {var} is not defined in this context.'
@@ -81,10 +81,12 @@ def expandvars(path, env):
   81    81             if '/' in path:
   82    82                 tail = path.removeprefix(f'${var}/')
   83    83                 return str(head / tail)
   84    -1             else:
   -1    84             elif path == f'${var}':
   85    85                 return str(head)
   -1    86             else:
   -1    87                 raise ValueError(f'Invalid path {path}')
   86    88 
   87    -1     raise ValueError(path)
   -1    89     raise ValueError(f'Invalid path {path}')
   88    90 
   89    91 
   90    92 class RuleSet: