view lemuriformes/waiter.py @ 18:56596902e9ae default tip

add some setup + tests
author Jeff Hammel <k0scist@gmail.com>
date Sun, 10 Dec 2017 17:57:03 -0800
parents 4793f99b73e0
children
line wrap: on
line source

"""
interpolate (etc) bash waiter script for subcommand parallelism
"""

import os
import tempita

here = os.path.dirname(os.path.abspath(__file__))

class BashWaiter(object):

    template_path = os.path.join(here, 'waiter.sh')

    def __init__(self, *commands):
        assert os.path.exists(self.template_path)
        self.template = tempita.Template.from_filename(self.template_path)

        self.commands = []
        for command in commands:
            self.add(command)

    def add(self, command):
        self.commands.append(command)


    def __str__(self):
        """render the template"""
        variables = {'commands': self.commands}
        return self.template.substitute(**variables)