diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lemuriformes/waiter.py	Sun Dec 10 17:42:52 2017 -0800
@@ -0,0 +1,30 @@
+"""
+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)
+