forked from Tinkerforge/generators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_forum_post.py
executable file
·89 lines (70 loc) · 2.44 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
#!/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'
}
def main():
bindings = []
for binding in sorted(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)
display_names = []
downloads = []
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)
display_names.append('{0} {1}.{2}.{3}'.format(DISPLAY_NAMES[binding], *version))
downloads.append('<a href="https://download.tinkerforge.com/bindings/{0}/tinkerforge_{0}_bindings_{2}_{3}_{4}.zip">{1}</a>'
.format(binding, DISPLAY_NAMES[binding], *version))
print("""<p><strong>Bindings:
{0}
</strong></p>
<ul>
<li>...</li>
</ul>
<p>Download:
{1}
</p>
""".format(',\n'.join(display_names), ',\n'.join(downloads)))
if __name__ == '__main__':
main()