-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path__init__.py
69 lines (57 loc) · 1.92 KB
/
__init__.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
bl_info = {
"name": "Color Helper",
"author": "Atticus",
"blender": (4, 0, 0),
"version": (0, 5, 2),
"category": "Color",
"support": "COMMUNITY",
"doc_url": "",
"tracker_url": "",
"description": "",
'warning': "Alpha, Support Windows / MacOS",
"location": "3D View/Node Editor's N panel",
}
import importlib
import sys
import os
from itertools import groupby
# get folder name
__folder_name__ = __name__
__dict__ = {}
addon_dir = os.path.dirname(__file__)
# get all .py file dir
py_paths = [os.path.join(root, f) for root, dirs, files in os.walk(addon_dir) for f in files if
f.endswith('.py') and f != '__init__.py']
for path in py_paths:
name = os.path.basename(path)[:-3]
correct_path = path.replace('\\', '/')
# split dir with folder name
dir_list = [list(g) for k, g in groupby(correct_path.split('/'), lambda x: x == __folder_name__) if
not k]
# combine dir and make dict like this: 'name:folder.name'
if 'colorthief' not in dir_list[-1]:
r_name_raw = __folder_name__ + '.' + '.'.join(dir_list[-1])
__dict__[name] = r_name_raw[:-3]
# auto reload
for name in __dict__.values():
if name in sys.modules:
importlib.reload(sys.modules[name])
else:
globals()[name] = importlib.import_module(name)
setattr(globals()[name], 'modules', __dict__)
def register():
for name in __dict__.values():
if name in sys.modules and hasattr(sys.modules[name], 'register'):
try:
sys.modules[name].register()
except ValueError: # open template file may cause this problem
pass
def unregister():
for name in __dict__.values():
if name in sys.modules and hasattr(sys.modules[name], 'unregister'):
try:
sys.modules[name].unregister()
except Exception:
pass
if __name__ == '__main__':
register()