-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path__init__.py
199 lines (164 loc) · 6.62 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import bpy
import os
from .functions import install_dependencies
deps_check = None
class Install_Dependencies_Operator(bpy.types.Operator):
"""Installs the dependencies needed (~8GB disk space)"""
bl_idname = "rotoforge.install_dependencies"
bl_label = "Install dependencies"
bl_description = "Install dependencies (Downloads up to ~8GB)"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
# Run the script "install_packages"
if not install_dependencies.test_packages():
install_dependencies.install_packages()
# Run the script "download_models"
if not install_dependencies.test_models():
install_dependencies.download_models()
# Reload the scripts
print("RotoForge AI: Reloading scripts")
bpy.ops.script.reload()
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_confirm(self, event)
class Test_Dependencies_Operator(bpy.types.Operator):
"""Tests the dependencies needed"""
bl_idname = "rotoforge.test_dependencies"
bl_label = "Check Dependencies"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
print('--- RotoForge AI: Dependencies Debug Info ---')
debug_info = []
install_dependencies.ensure_package_path()
packages = install_dependencies.test_packages()
models = install_dependencies.test_models()
global deps_check
if not packages:
debug_info.append('Issue found with packages')
if not models:
debug_info.append('Issue found with models')
if packages and models:
debug_info.append('No issues found')
deps_check = 'passed'
else:
debug_info.append('Check the system console for more information')
deps_check = 'failed'
# Draw function for the popup menu
def draw(self, context):
# Add each string as a separate line
for line in debug_info:
self.layout.label(text=line)
context.window_manager.popup_menu(title='Dependencies Debug Info', draw_func=draw)
return {'FINISHED'}
class Forceupdate_Dependencies_Operator(bpy.types.Operator):
"""Reinstalls the dependencies needed (~8GB disk space)"""
bl_idname = "rotoforge.forceupdate_dependencies"
bl_label = "Forceupdate dependencies (Redownloads ~8GB)"
bl_options = {'REGISTER', 'UNDO'}
packages: bpy.props.BoolProperty(
name="Forceupdate Packages (~3GB)",
description="Forceupdate Packages (Redownloads ~3GB)",
default=True
) # type: ignore
models: bpy.props.BoolProperty(
name="Forceupdate Models (~5GB)",
description="Forceupdate Models (Redownloads ~5GB)",
default=False
) # type: ignore
def execute(self, context):
# Run the script "install_packages"
if self.packages:
install_dependencies.install_packages(override=True)
# Run the script "download_models"
if self.models:
install_dependencies.download_models(override=True)
# Reload the scripts
print("RotoForge AI: Reloading scripts")
bpy.ops.script.reload()
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_confirm(self, event)
class RotoForge_Preferences(bpy.types.AddonPreferences):
bl_idname = __package__
dependencies_path: bpy.props.StringProperty(
name="Install path",
description="Directory where additional dependencies for the addon are downloaded (NEEDS ~8GB SPACE)",
subtype='DIR_PATH',
default=os.path.realpath(os.path.expanduser("~/MVD-addons dependencies/RotoForge AI"))
) # type: ignore
def draw(self,context):
layout = self.layout
layout.prop(self, "dependencies_path")
row = layout.split(factor=0.7)
labels = row.column()
operators = row.column()
operators.operator("rotoforge.test_dependencies")
global deps_check
if deps_check == None:
labels.label(text="Please check the dependencies with the button to the right:")
return
if deps_check == 'passed':
labels.label(text="Dependencies are installed, nothing to do here!")
return
labels.label(text="Dependencies need to be installed,")
labels.label(text="please press the button to the right:")
install = operators.column_flow()
install.scale_y = 2.0
install.operator("rotoforge.install_dependencies")
classes = [RotoForge_Preferences,
Install_Dependencies_Operator,
Forceupdate_Dependencies_Operator,
Test_Dependencies_Operator
]
def register():
for cls in classes:
bpy.utils.register_class(cls)
print("RotoForge AI: Registering extension...")
try:
install_dependencies.register()
from .functions import data_manager
data_manager.register()
from .functions import setup_ui
setup_ui.register()
from .functions import overlay
overlay.register()
except ImportError as e:
print('RotoForge AI: An ImportError occured when importing the dependencies')
if hasattr(e, 'message'):
print(e.message)
else:
print(e)
except Exception as e:
print('RotoForge AI: Something went very wrong importing the dependencies, please get that checked')
if hasattr(e, 'message'):
print(e.message)
else:
print(e)
def unregister():
print("RotoForge AI: Unregistering extension...")
try:
install_dependencies.unregister()
from .functions import data_manager
data_manager.unregister()
from .functions import setup_ui
setup_ui.unregister()
from .functions import overlay
overlay.unregister()
except ImportError as e:
print('RotoForge AI: An ImportError occured when importing the dependencies')
if hasattr(e, 'message'):
print(e.message)
else:
print(e)
except Exception as e:
print('RotoForge AI: Something went very wrong importing the dependencies, please get that checked')
if hasattr(e, 'message'):
print(e.message)
else:
print(e)
for cls in classes:
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()