1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
#!/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 <equinox@spreadspace.org>
#
# 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 <http://www.gnu.org/licenses/>.
#
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)
|