-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocgen_plugin_infos.py
62 lines (52 loc) · 2.01 KB
/
docgen_plugin_infos.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
# | Copyright 2017 Karlsruhe Institute of Technology
# |
# | Licensed under the Apache License, Version 2.0 (the "License");
# | you may not use this file except in compliance with the License.
# | You may obtain a copy of the License at
# |
# | http://www.apache.org/licenses/LICENSE-2.0
# |
# | Unless required by applicable law or agreed to in writing, software
# | distributed under the License is distributed on an "AS IS" BASIS,
# | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# | See the License for the specific language governing permissions and
# | limitations under the License.
import os, sys, json, logging
from python_compat import lmap
def main():
if sys.argv[1:]:
base_dir = sys.argv[1]
else:
base_dir = '../../packages'
sys.path.append(base_dir)
from hpfwk.hpf_plugin import get_plugin_list, import_modules
clsdata = {}
for package in os.listdir(base_dir):
package = os.path.abspath(os.path.join(base_dir, package))
if os.path.isdir(package):
plugin_list = get_plugin_list(import_modules(os.path.abspath(package), _select))
for cls in sorted(plugin_list, key=lambda c: c.__name__):
cls_name = cls.__name__.split('.')[-1]
clsdata.setdefault(cls_name, {})['alias'] = cls.get_class_name_list()[1:]
if not clsdata.setdefault(cls_name, {})['alias']:
logging.warning('%r', cls)
if cls.config_section_list:
clsdata.setdefault(cls_name, {})['config'] = cls.config_section_list
clsdata.setdefault(cls_name, {}).setdefault('scope', {})['config'] = cls.config_section_list
bases = lmap(lambda x: x.__name__, cls.iter_class_bases())[1:] + ['object']
bases.reverse()
if bases:
clsdata.setdefault(cls_name, {})['bases'] = bases
else:
logging.error('%r %r', clsdata, bases)
sys.exit(0)
fp = open('docgen_plugin_infos.json', 'w')
json.dump(clsdata, fp, indent=2)
fp.close()
def _select(path):
for pat in ['/share', '_compat_', '/requests', '/xmpp']:
if pat in path:
return False
return True
if __name__ == '__main__':
main()