forked from hlorus/CAD_Sketcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_op.py
61 lines (46 loc) · 1.91 KB
/
install_op.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
import bpy
from bpy.types import Operator
from .. import global_data
from ..declarations import Operators
from ..utilities.install import check_module
from ..utilities.install import install_package, ensure_pip, show_package_info
class View3D_OT_slvs_install_package(Operator):
"""Install module from local .whl file or from PyPi"""
bl_idname = Operators.InstallPackage
bl_label = "Install"
package: bpy.props.StringProperty(subtype="FILE_PATH")
@classmethod
def poll(cls, context):
return not global_data.registered
def execute(self, context):
if not ensure_pip():
self.report(
{"WARNING"},
"PIP is not available and cannot be installed, please install PIP manually",
)
return {"CANCELLED"}
if not self.package:
self.report({"WARNING"}, "Specify package to be installed")
return {"CANCELLED"}
if install_package(self.package):
try:
check_module("py_slvs")
from ..registration import register_full
register_full()
self.report({"INFO"}, "Package successfully installed")
except ModuleNotFoundError:
msg = """Package should be available but cannot be found, check console for detailed info.
Try restarting blender, otherwise get in contact."""
self.report(
{"WARNING"},
msg,
)
show_package_info("py_slvs")
else:
self.report({"WARNING"}, "Cannot install package: {}".format(self.package))
return {"CANCELLED"}
return {"FINISHED"}
def register():
bpy.utils.register_class(View3D_OT_slvs_install_package)
def unregister():
bpy.utils.unregister_class(View3D_OT_slvs_install_package)