-
Notifications
You must be signed in to change notification settings - Fork 32
/
generate_all.py
executable file
·116 lines (88 loc) · 3.95 KB
/
generate_all.py
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
115
116
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
if sys.hexversion < 0x3040000:
print('Python >= 3.4 required')
sys.exit(1)
import os
import re
import socket
import importlib.util
import importlib.machinery
generators_dir = os.path.dirname(os.path.realpath(__file__))
def create_generators_module():
if sys.hexversion < 0x3050000:
generators_module = importlib.machinery.SourceFileLoader('generators', os.path.join(generators_dir, '__init__.py')).load_module()
else:
generators_spec = importlib.util.spec_from_file_location('generators', os.path.join(generators_dir, '__init__.py'))
generators_module = importlib.util.module_from_spec(generators_spec)
generators_spec.loader.exec_module(generators_module)
sys.modules['generators'] = generators_module
if 'generators' not in sys.modules:
create_generators_module()
from generators import common
def main(args):
all_generators = ['bindings', 'examples', 'doc', 'zip', 'debian_package']
if socket.gethostname() == 'tinkerforge.com':
active_generators = {'doc'}
else:
active_generators = {'bindings', 'doc', 'zip'}
if args.generators != None:
try:
active_generators = common.apply_item_changes('generator', active_generators, all_generators, args.generators[0].split(','))
except Exception as e:
print('error: {0}'.format(e))
return 1
all_bindings = []
for binding in os.listdir(generators_dir):
if not os.path.isdir(binding) or os.path.exists(os.path.join(generators_dir, binding, 'skip_generate_all')):
continue
if binding not in ['.git', '.m2', '.vscode', '__pycache__', 'configs', 'docker']:
all_bindings.append(binding)
all_bindings = sorted(all_bindings)
active_bindings = set(all_bindings)
if args.bindings != None:
try:
active_bindings = common.apply_item_changes('binding', active_bindings, all_bindings, args.bindings[0].split(','))
except Exception as e:
print('error: {0}'.format(e))
return 1
languages = {
'bindings': ['en'],
'examples': ['en'],
'doc': ['en', 'de'],
'zip': ['en'],
'debian_package': ['en']
}
has_internal_argument = [
'bindings',
'examples',
'doc',
'zip'
]
for generator in all_generators:
if generator not in active_generators:
continue
for binding in all_bindings:
if binding not in active_bindings:
continue
print('\033[01;32m>>> running {0} generator for {1} bindings\033[0m'.format(generator, binding))
try:
module = importlib.import_module('generators.{0}.generate_{0}_{1}'.format(binding, generator))
except ImportError: # FIXME: Python 3.6 has ModuleNotFoundError, which would be better to use here, but Debian Stretch has only Python 3.5
print('\033[01;36m### generator missing\033[0m')
else:
for language in languages[generator]:
root_dir = os.path.join(generators_dir, binding)
if generator in has_internal_argument:
module.generate(root_dir, language, args.internal)
else:
module.generate(root_dir, language)
print('\033[01;35m>>> done\033[0m')
return 0
if __name__ == '__main__':
def add_arguments(parser):
parser.add_argument('-g', '--generators', nargs=1, help='comma separated list of generators, each prefixed by +/-/>=/>/<=/<')
parser.add_argument('-b', '--bindings', nargs=1, help='comma separated list of bindings, each prefixed by +/-/>=/>/<=/<')
# FIXME: set mount_m2_volume and mount_gnupg_volume based on -g/-b
sys.exit(main(common.dockerize('', __file__, add_internal_argument=True, add_arguments=add_arguments, mount_m2_volume=True, mount_gnupg_volume=True)))