@@ -13,9 +13,7 @@ def clean_var(string):
13
13
Converts a string to a suitable variable name by removing not allowed
14
14
characters.
15
15
"""
16
- for ch in ['-' , '.' , '*' ]:
17
- string = string .replace (ch , '_' )
18
- string = string .replace ('[]' , '' )
16
+ string = string .replace ('-' , '_' ).replace ('[]' , '' )
19
17
return string
20
18
21
19
@@ -33,10 +31,8 @@ def generate_classes():
33
31
f .write ("#!/usr/bin/env python\n " )
34
32
f .write ("# -*- coding: utf-8 -*-\n " )
35
33
f .write ("\n " )
36
- f .write ("# THIS FILE WAS GENERATED BY generate_classes.py - "
37
- "DO NOT EDIT #\n " )
38
- f .write ("# (Generated on {}) #\n " .format (
39
- datetime .now ().isoformat (" " )))
34
+ f .write ("# THIS FILE WAS GENERATED BY generate_classes.py - DO NOT EDIT #\n " )
35
+ f .write ("# (Generated on {}) #\n " .format (datetime .now ().isoformat (" " )))
40
36
f .write ("\n " )
41
37
f .write ("from .base_classes import Base{}\n " .format (event ))
42
38
f .write ("\n \n " )
@@ -51,12 +47,10 @@ def generate_classes():
51
47
if len (i ['params' ]) > 0 :
52
48
f .write (" :Arguments:\n " )
53
49
for a in i ['params' ]:
54
- f .write (" *{}*\n " .format (
55
- clean_var (a ['name' ])))
56
- f .write (" type: {}\n " .format (
57
- a ['type' ]))
58
- f .write (" {}\n " .format (
59
- a ['description' ]))
50
+ a ['name' ] = a ['name' ].replace ("[]" , ".*" )
51
+ f .write (" *{}*\n " .format (clean_var (a ['name' ])))
52
+ f .write (" type: {}\n " .format (a ['type' ]))
53
+ f .write (" {}\n " .format (a ['description' ]))
60
54
if 'optional' in a ['type' ]:
61
55
arguments_default .append (a ['name' ])
62
56
else :
@@ -69,34 +63,35 @@ def generate_classes():
69
63
if len (i ['returns' ]) > 0 :
70
64
f .write (" :Returns:\n " )
71
65
for r in i ['returns' ]:
72
- f .write (" *{}*\n " .format (
73
- clean_var (r ['name' ])))
74
- f .write (" type: {}\n " .format (
75
- r ['type' ]))
76
- f .write (" {}\n " .format (
77
- r ['description' ]))
66
+ r ['name' ] = r ['name' ].replace ("[]" , ".*" )
67
+ f .write (" *{}*\n " .format (clean_var (r ['name' ])))
68
+ f .write (" type: {}\n " .format (r ['type' ]))
69
+ f .write (" {}\n " .format (r ['description' ]))
78
70
returns .append (r ['name' ])
79
71
except KeyError :
80
72
pass
81
73
74
+ arguments = set ([x .split ("." )[0 ] for x in arguments ])
75
+ arguments_default = set ([x .split ("." )[0 ] for x in arguments_default ])
76
+ arguments_default = set ([x for x in arguments_default if x not in arguments ])
77
+ returns = set ([x .split ("." )[0 ] for x in returns ])
78
+
82
79
f .write (" \" \" \" \n \n " )
83
80
f .write (" def __init__({}):\n " .format (
84
81
", " .join (
85
- ["self" ] +
86
- [clean_var (a ) for a in arguments ] +
87
- [clean_var (a ) + "=None" for a in arguments_default ]
82
+ ["self" ]
83
+ + [clean_var (a ) for a in arguments ]
84
+ + [clean_var (a ) + "=None" for a in arguments_default ]
88
85
)
89
86
))
90
87
f .write (" Base{}.__init__(self)\n " .format (event ))
91
88
f .write (" self.name = '{}'\n " .format (i ['name' ]))
92
89
for r in returns :
93
90
f .write (" self.datain['{}'] = None\n " .format (r ))
94
91
for a in arguments :
95
- f .write (" self.dataout['{}'] = {}\n " .format (
96
- a , clean_var (a )))
92
+ f .write (" self.dataout['{}'] = {}\n " .format (a , clean_var (a )))
97
93
for a in arguments_default :
98
- f .write (" self.dataout['{}'] = {}\n " .format (
99
- a , clean_var (a )))
94
+ f .write (" self.dataout['{}'] = {}\n " .format (a , clean_var (a )))
100
95
f .write ("\n " )
101
96
for r in returns :
102
97
cc = "" .join (x .capitalize () for x in r .split ('-' ))
0 commit comments