diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/flufigut.py | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/flufigut.py b/src/flufigut.py index 37d5ee9..aa01a02 100755 --- a/src/flufigut.py +++ b/src/flufigut.py @@ -34,6 +34,8 @@ import sys import simplejson as json from exceptions import * from jinja2 import Environment, FileSystemLoader +import shutil +import os ### helper functions ############################################ # @@ -315,10 +317,44 @@ if error != 0: ### initialize and render templates ############################# # + +import shutil +shutil.rmtree('output', ignore_errors=True) + env = Environment(loader=FileSystemLoader('../templates/%s/' % (sys.argv[1])), line_statement_prefix = '%%') + +port = 9000 +for w in worker: + if worker[w] > 0: + machine_name = "" + for machine in globals['machines']: + if w in globals['machines'][machine]: + machine_name = machine + break + print "generating config for worker '%s/%s'" % (machine_name, w) + password = rand_string(12) + template = env.get_template('worker.xml') + ports = "%i-%i" % (port, port+1) + port+=2 + workerconf = template.render(globals=globals, name=w, password=password, portrange=ports) + dir = 'output/%s/worker' % machine + if not os.path.exists(dir): + os.makedirs(dir) + f = open('%s/%s.xml' % (dir, w), 'w') + f.write(workerconf.encode("utf8")) + f.write('\n') + f.close() + +print "generating planet '%s/%s'" % (globals['manager']['machine'], globals['name']) template = env.get_template('planet.xml') planet = template.render(globals=globals, atmosphere=atmosphere, flow=flow) -sys.stdout.write(planet.encode("utf8")) +dir = 'output/%s/manager' % globals['manager']['machine'] +if not os.path.exists(dir): + os.makedirs(dir) +f = open('%s/planet.xml' % (dir), 'w') +f.write(planet.encode("utf8")) +f.write('\n') +f.close() ### end ######################################################### |