-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathgenerate_forum_post.py
executable file
·119 lines (97 loc) · 3 KB
/
generate_forum_post.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
117
118
119
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
if sys.hexversion < 0x3040000:
print('Python >= 3.4 required')
sys.exit(1)
import os
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
DISPLAY_NAMES = {
'c': 'C/C++',
'csharp': 'C#',
'delphi': 'Delphi/Lazarus',
'go': 'Go',
'java': 'Java',
'javascript': 'JavaScript',
'labview': 'LabVIEW',
'mathematica': 'Mathematica',
'matlab': 'MATLAB/Octave',
'mqtt': 'MQTT',
'perl': 'Perl',
'php': 'PHP',
'python': 'Python',
'ruby': 'Ruby',
'rust': 'Rust',
'saleae': 'Saleae',
'shell': 'Shell',
'vbnet': 'Visual Basic .NET',
'uc': 'C/C++ for Microcontrollers'
}
BINDINGS_ORDER = [
'c',
'uc',
'csharp',
'delphi',
'go',
'java',
'javascript',
'labview',
'mathematica',
'matlab',
'mqtt',
'perl',
'php',
'python',
'ruby',
'rust',
'saleae',
'shell',
'vbnet'
]
def main():
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_forum_post')):
continue
if binding not in ['.git', '.vscode', '.m2', '__pycache__', 'configs', 'docker']:
bindings.append(binding)
result = {}
for binding in bindings:
if len(sys.argv) > 1 and binding not in sys.argv[1:]:
continue
path = os.path.join(generators_dir, binding)
version = common.get_changelog_version(path)
result[binding] = ('{0} {1}.{2}.{3}'.format(DISPLAY_NAMES[binding], *version),
'<a href="https://download.tinkerforge.com/bindings/{0}/tinkerforge_{0}_bindings_{2}_{3}_{4}.zip">{1}</a>'
.format(binding, DISPLAY_NAMES[binding], *version))
sorted_result = []
for binding in BINDINGS_ORDER:
try:
sorted_result.append(result[binding])
except KeyError:
pass
print("""<p><strong>Bindings:
{0}
</strong></p>
<ul>
<li>...</li>
</ul>
<p>Download:
{1}
</p>
""".format(',\n'.join([item[0] for item in sorted_result]), ',\n'.join([item[1] for item in sorted_result])))
if __name__ == '__main__':
main()