comparison lemuriformes/waiter.py @ 17:4793f99b73e0

[lemuriformes] utility functions
author Jeff Hammel <k0scist@gmail.com>
date Sun, 10 Dec 2017 17:42:52 -0800
parents
children
comparison
equal deleted inserted replaced
16:9b1bb9eee962 17:4793f99b73e0
1 """
2 interpolate (etc) bash waiter script for subcommand parallelism
3 """
4
5 import os
6 import tempita
7
8 here = os.path.dirname(os.path.abspath(__file__))
9
10 class BashWaiter(object):
11
12 template_path = os.path.join(here, 'waiter.sh')
13
14 def __init__(self, *commands):
15 assert os.path.exists(self.template_path)
16 self.template = tempita.Template.from_filename(self.template_path)
17
18 self.commands = []
19 for command in commands:
20 self.add(command)
21
22 def add(self, command):
23 self.commands.append(command)
24
25
26 def __str__(self):
27 """render the template"""
28 variables = {'commands': self.commands}
29 return self.template.substitute(**variables)
30