-
Notifications
You must be signed in to change notification settings - Fork 11
/
houdini_install.py
233 lines (206 loc) · 7.82 KB
/
houdini_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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import sys, re, os, shutil, argparse
import getpass
try:
import requests
except ImportError:
print 'This script require requests module.\n Install: pip install requests'
sys.exit()
try:
from bs4 import BeautifulSoup
except ImportError:
print 'This scrip require BeautifulSoup package (https://www.crummy.com/software/BeautifulSoup/bs4/doc/#).' \
'\nInstall: pip install beautifulsoup4'
sys.exit()
# VARIABLES ################################
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--install_dir", type=str, help="Installation dir")
parser.add_argument("-u", "--username", type=str, help="SideFx account username")
parser.add_argument("-p", "--password", type=str, help="SideFx account password")
parser.add_argument("-s", "--server", type=str, help="Install License server (y/yes, n/no, a/auto, default auto)")
# parser.add_argument("-hq", "--hqserver", type=str, help="Install HQ server (y/yes, n/no, a/auto, default auto)")
_args, other_args = parser.parse_known_args()
username = _args.username
password = _args.password
if not username or not password:
print 'Please set username and password'
print 'Example: -u username -p password'
sys.exit()
install_dir = _args.install_dir
if not install_dir:
print 'ERROR: Please set installation folder in argument -i. For example: -i "%s"' % ('/opt/houdini' if os.name == 'postx' else 'c:\\cg\\houdini')
sys.exit()
install_dir = install_dir.replace('\\', '/').rstrip('/')
tmp_folder = os.path.expanduser('~/temp_houdini')
# license server
lic_server = False
if os.name == 'nt':
if not os.path.exists('C:/Windows/System32/sesinetd.exe'):
lic_server = True
elif os.name == 'posix':
if not os.path.exists('/usr/lib/sesi/sesinetd'):
lic_server = True
if _args.server:
if _args.server in ['y', 'yes']:
lic_server = True
elif _args.server in ['n', 'no']:
lic_server = False
# hq server
# hq_server = False
# if os.name == 'nt':
# if not os.path.exists('C:/Windows/System32/sesinetd.exe'):
# lic_server = True
# elif os.name == 'posix':
# if not os.path.exists(''):
# lic_server = True
############################################################# START #############
def create_output_dir(istall_dir, build):
"""
Change this to define installation folder
"""
if os.name == 'nt':
return os.path.join(install_dir, build).replace('/', '\\')
else:
return '/'.join([install_dir.rstrip('/'), build])
def windows_is_admin():
import ctypes
try:
is_admin = os.getuid() == 0
except AttributeError:
is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0
return is_admin
# define OS
if os.name == 'nt':
category = 'win'
if not windows_is_admin():
print 'Run this script as administrator'
sys.exit()
elif os.name == 'posix':
category = 'linux'
else:
raise Exception('This OS not supported')
# create client
client = requests.session()
# Retrieve the CSRF token first
URL = 'https://www.sidefx.com/login/'
print 'Login on %s ...' % URL
client.get(URL) # sets cookie
csrftoken = client.cookies['csrftoken']
# create login data
login_data = dict(username=username, password=password, csrfmiddlewaretoken=csrftoken, next='/')
# login
r = client.post(URL, data=login_data, headers=dict(Referer=URL))
# goto daily builds page
print 'Get last build version...'
page = client.get('http://www.sidefx.com/download/daily-builds/')
# parse page
s = BeautifulSoup(page.content, 'html.parser')
# get all versions
# lin = s.findAll('div', {'class': lambda x: x and 'category-' + categorys['linux'] in x.split()})
# get last version
a = s.find('div', {'class': lambda x: x and 'category-'+category in x.split()}).find('a')
# get build
build = re.match(r".*?(\d+\.\d+\.\d+).*", str(a.text)).group(1)
print 'Last build is ', build
# check your last version here
if not os.path.exists(install_dir):
os.makedirs(install_dir)
if build in os.listdir(install_dir):
print 'Build {} already installed'.format(build)
sys.exit()
# if your version is lower go to download
print 'Start download...'
# download url
url = 'http://www.sidefx.com' + a.get('href').split('=')[-1] + 'get/'
print ' DOWNLOAD URL:', url
# create local file path
if not os.path.exists(tmp_folder):
os.makedirs(tmp_folder)
local_filename = os.path.join(tmp_folder, a.text).replace('\\', '/')
print ' Local File:', local_filename
# get content
resp = client.get(url, stream=True)
total_length = int(resp.headers.get('content-length'))
need_to_download = True
if os.path.exists(local_filename):
# compare file size
if not os.path.getsize(local_filename) == total_length:
os.remove(local_filename)
else:
# skip downloading if file already exists
print 'Skip download'
need_to_download = False
if need_to_download:
# download file
print 'Total size %sMb' % int(total_length/1024.0/1024.0)
block_size = 1024*4
dl = 0
with open(local_filename, 'wb') as f:
for chunk in resp.iter_content(chunk_size=block_size):
if chunk:
f.write(chunk)
f.flush()
dl += len(chunk)
done = int(50 * dl / total_length)
sys.stdout.write("\r[%s%s] %sMb of %sMb" % ('=' * done,
' ' * (50-done),
int(dl/1024.0/1024.0),
int(total_length/1024.0/1024.0)
)
)
sys.stdout.flush()
print
print 'Download complete'
# start silent installation
print 'Start install Houdini'
if os.name == 'posix':
# unzip
print 'Unpack "%s" to "%s"' % (local_filename, tmp_folder)
cmd = 'sudo tar xf {} -C {}'.format(local_filename, tmp_folder)
os.system(cmd)
# os.remove(local_filename)
install_file = os.path.join(tmp_folder, os.path.splitext(os.path.splitext(os.path.basename(local_filename))[0])[0], 'houdini.install')
print 'Install File', install_file
# ./houdini.install --auto-install --accept-EULA --make-dir /opt/houdini/16.0.705
out_dir = create_output_dir(install_dir, build)
flags = '--auto-install --accept-EULA --make-dir'
if lic_server:
pass
cmd = 'sudo ./houdini.install {flags} {dir}'.format(
flags=flags,
dir=out_dir
)
print 'Create output folder', out_dir
if not os.path.exists(out_dir):
print 'Create folder:', out_dir
os.makedirs(out_dir)
print 'Start install...'
# print 'CMD:\n'+cmd
print 'GoTo', os.path.dirname(install_file)
os.chdir(os.path.dirname(install_file))
os.system(cmd)
# sudo chown -R paul: /opt/houdini/16.0.705
# sudo chmod 777 -R
# whoami
# setup permission
os.system('chown -R %s: %s' % (getpass.getuser(), out_dir))
os.system('chmod 777 -R ' + out_dir)
# delete downloaded file
# shutil.rmtree(tmp_folder)
else:
out_dir = create_output_dir(install_dir, build)
print 'Create output folder', out_dir
if not os.path.exists(out_dir):
os.makedirs(out_dir)
cmd = '"{houdini_install}" /S /AcceptEula=yes /LicenseServer={lic_server} /DesktopIcon=No ' \
'/FileAssociations=Yes /HoudiniServer=No /EngineUnity=No ' \
'/EngineMaya=No /EngineUnreal=No /HQueueServer=No ' \
'/HQueueClient=No /IndustryFileAssociations=Yes /InstallDir="{install_dir}" ' \
'/ForceLicenseServer={lic_server} /MainApp=Yes /Registry=Yes'.format(
lic_server='Yes' if lic_server else 'No',
houdini_install=local_filename,
install_dir=out_dir
)
print 'CMD:\n' + cmd
print 'Start install...'
os.system(cmd)
print 'If installation not happen, repeat process.'