This repository has been archived by the owner on Feb 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.py
114 lines (80 loc) · 4.48 KB
/
install.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
import sys
import os
import shutil
from pathlib import Path
from subprocess import call
from platform import system
def main(cont):
# Sensors
sensor = cont.sensors[0]
if sensor.positive:
# Other
ext_exe = '.exe' if system() == 'Windows' else ''
system_supported = system() in ['Windows', 'Linux']
# Paths
path_current = Path('.').resolve()
path_bgcython = Path(Path(__file__).resolve().parent.as_posix() + '/bgcython').resolve()
path_blender = Path(sys.executable).resolve()
path_python = None
path_sitepkg = None
# Set remaining path variables, walking through blender files structure
for _path, _folders, _files in os.walk(path_blender.parent.as_posix()):
# python/bin folder
if _path.endswith('bin'):
for _file in _files:
_p = Path(_path + '/' + _file).resolve()
# Check if file is a python executable
if _file.startswith('python') and _file.endswith(ext_exe) and os.access(_p.as_posix(), os.X_OK):
path_python = _p
# Get folder site-packages from python library
if _path.endswith('site-packages'):
path_sitepkg = Path(_path).resolve()
# Break loop to avoid reading unecessary files
if path_python and path_sitepkg:
break
### START ###
### Only continue if all paths exists ###
if system_supported and path_bgcython.exists() and path_blender.exists() and path_python.exists() and path_sitepkg.exists():
# Change working directory to Python binaries directory
os.chdir(path_python.parent.as_posix())
# Print main paths
print('\n> Blender path is:\n' + path_blender.as_posix() + '\n' +
'\n> Python path is:\n' + path_python.as_posix() + '\n' +
'\n> site-packages path is:\n' + path_sitepkg.as_posix() + '\n')
# If pip is not installed
if not 'pip' in os.listdir(path_sitepkg.as_posix()):
print('pip is not installed, installing it through ensurepip\n')
# Execute ensurepip
print('Execute ensurepip')
import ensurepip
ensurepip._main()
print('pip successfully installed\n')
# Continue if pip is installed
if 'pip' in os.listdir(path_sitepkg.as_posix()):
# If Cython is not installed
if not 'Cython' in os.listdir(path_sitepkg.as_posix()):
print('Cython is not installed, installing it through pip\n')
# Install Cython through pip
call(path_python.name + ' -m pip install Cython')
print('Cython successfully installed\n')
# If bgcython is not installed
if not 'bgcython' in os.listdir(path_sitepkg.as_posix()):
print('bgcython is not installed, installing it\n')
# Copy bgcython package to site-packages
print('Copying bgcython package to site-packages')
shutil.copytree(
path_bgcython.as_posix(),
path_sitepkg.as_posix() + '/bgcython/'
)
# Copy settings.txt to package folder
print('Copying settings.txt package folder')
shutil.copyfile(
path_bgcython.as_posix() + '/settings.txt',
path_sitepkg.as_posix() + '/bgcython/settings.txt'
)
print('bgcython successfully installed\n')
# Open settings file for editing
os.startfile(path_sitepkg.as_posix() + '/bgcython/settings.txt')
print('Installation successfully finished')
# Change working directory back to current
os.chdir(path_current.as_posix())