#!/usr/bin/python3 # # flufigut # # flufigut, the flumotion configuration utility, is a simple tool # that generates flumotion configuration files using pyhton jinja2 # template engine. flufigut generates planet.xml and worker.xml # files from configuration templates and an easy to understand # representation of the flow structure written in json or yaml. # # # Copyright (C) 2018 Christian Pointner # # This file is part of flufigut. # # flufigut 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. # # flufigut 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 flufigut. If not, see . # import string import random import sys import yaml # from jinja2 import Environment, FileSystemLoader # helper functions ############################################ # def rand_string(size=8, chars=string.ascii_lowercase + string.ascii_uppercase + string.digits): return ''.join(random.choice(chars) for x in range(size)) # a flufigut stream description ############################### # class Description: def __init__(self): self.globals = {} self.input = {} self.mux = {} self.stream = {} self.record = {} def _sanity_check(self): # TODO: add more sanity checks components = {} for _, worker in self.globals['workers'].items(): for c in worker: if c in components: raise Exception("ERROR: component '%s' is assigned to more than one worker!" % c) else: components[c] = 1 def parse(self, config_file): cf = open(config_file, 'r') config = yaml.load(cf) cf.close() self.globals = config['globals'] self.input = config['input'] self.mux = config['mux'] self.stream = config['stream'] if 'record' in config: self.record = config['record'] return self._sanity_check() # a flumtion planet configuration ############################# # class Planet: def __init__(self): self.atmosphere = {} self.flow = {} # Main ######################################################## # if __name__ == '__main__': import traceback import pprint __pp = pprint.PrettyPrinter(indent=4, width=160) if len(sys.argv) <= 1: print("ERROR: No configuration file given") sys.exit(-1) config_file = sys.argv[1] ret = 0 try: desc = Description() desc.parse(config_file) except Exception as e: print("ERROR: while running app: %s" % e) # print(traceback.format_exc()) sys.exit(1) sys.exit(ret)