Update wrapper recipe to make it simpler and more dev-friendly.

parent d0aebea0
...@@ -30,25 +30,32 @@ import shlex ...@@ -30,25 +30,32 @@ import shlex
from slapos.recipe.librecipe import GenericBaseRecipe from slapos.recipe.librecipe import GenericBaseRecipe
class Recipe(GenericBaseRecipe): class Recipe(GenericBaseRecipe):
def install(self): def install(self):
command_line = shlex.split(self.options['command-line']) command_line = shlex.split(self.options['command-line'])
wrapper_path = self.options['wrapper-path']
wait_files = self.options.get('wait-for-files') wait_files = self.options.get('wait-for-files')
environment = self.options.get('environment')
if not wait_files and not environment:
# Create a simple wrapper as shell script
return [self.createWrapper(
name=wrapper_path,
command=command_line[0],
parameters=command_line[1:],
)]
# More complex needs: create a Python script as wrapper
if wait_files is not None: if wait_files is not None:
wait_files = [filename.strip() for filename in wait_files.split() wait_files = [filename.strip() for filename in wait_files.split()
if filename.strip()] if filename.strip()]
environment = self.options.get('environment')
if environment is not None: if environment is not None:
environment = dict((k.strip(), v.strip()) for k, v in [ environment = dict((k.strip(), v.strip()) for k, v in [
line.split('=') line.split('=')
for line in environment.split('\n') for line in environment.split('\n')
]) ])
return [self.createPythonScript( return [self.createPythonScript(
self.options['output'], wrapper_path,
'slapos.recipe.librecipe.execute.generic_exec', 'slapos.recipe.librecipe.execute.generic_exec',
(command_line, wait_files, environment,), (command_line, wait_files, environment,),
)] )]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment