#!/usr/bin/python # # flufig # # flufig is a simple flumotion configuration generator using # pyhton jinja2 template engine and simplejson. flufig generates # planet.xml and worker.xml files from configuration templates and # an easy representation of the flow structure written in json. # # # Copyright (C) 2012 Christian Pointner # Michael Gebetsroither # # This file is part of flufig. # # flufig is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # any later version. # # flufig is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with flufig. If not, see . # import sys import simplejson as json from exceptions import * from jinja2 import Environment, FileSystemLoader if len(sys.argv) <= 2: raise SystemExit("No template and or data file given") df = open(sys.argv[2], 'r') data = json.load(df); df.close(); env = Environment(loader=FileSystemLoader('../templates/%s/' % (sys.argv[1]))) template = env.get_template('planet.xml') planet = template.render(globals=data['globals'], atmosphere=data['atmosphere'], flow=data['flow']) sys.stdout.write(planet.encode("utf8"))