forked from Samsung/WATT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch
More file actions
executable file
·789 lines (687 loc) · 27 KB
/
launch
File metadata and controls
executable file
·789 lines (687 loc) · 27 KB
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
#!/usr/bin/env python
import argparse, json, os, platform, re, select, stat, subprocess, sys, shutil, tarfile, zipfile
class Log:
level = 0
@classmethod
def set_level(cls, l):
cls.level = l
@classmethod
def err(cls, s, newline=True):
cls.__write(3, s, newline)
@classmethod
def warn(cls, s, newline=True):
cls.__write(2, s, newline)
@classmethod
def info(cls, s, newline=True):
cls. __write(1, s, newline)
@classmethod
def trace(cls, s, newline=True):
cls. __write(0, s, newline)
@classmethod
def __write(cls, l, s, newline):
if cls.level > l: return
# refer https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
style = ['', '\033[1;34m', '\033[1;32m', '\033[1;31m']
RESET = '\033[0m'
sys.stdout.write(style[l] + s + RESET + ('\n' if newline else ''))
sys.stdout.flush()
SERVICE = 'WATT'
supported = ('trusty', 'xenial')
root_path = os.path.abspath(os.path.dirname(__file__))
tool_path = os.path.join(root_path, 'tools')
os_name = platform.system()
if os_name == 'Linux':
try:
os_name = subprocess.check_output(['lsb_release', '-i']).strip().split('\t')[1]
os_dist = subprocess.check_output(['lsb_release', '-c']).strip().split('\t')[1]
except subprocess.CalledProcessError:
Log.err('Unsupport os')
sys.exit(1)
if os_name != 'Ubuntu' and os_name != 'Darwin':
Log.err('Unsupport %s os' % os_name)
sys.exit(1)
def import_additional():
status = subprocess.call('which pip > /dev/null', shell=True)
if status != 0 and not install_deb_package('pip'):
Log.err('Fail to install pip')
sys.exit(1)
additional_packages = ['psutil', 'requests']
for package in additional_packages:
try:
module = __import__(package)
except ImportError:
Log.info('Install %s packages. (sudo privileges required)' % package)
status = subprocess.call(['sudo', 'pip', 'install', package])
if status != 0:
Log.err('Fail to install %s' % package)
module = __import__(package)
globals()[package] = module
import_additional()
def install_nodejs():
if os_name == 'Darwin':
Log.info('Install nodejs with "brew"')
cmds = ['brew update', 'brew install node']
else:
status = subprocess.call('which curl > /dev/null', shell=True)
if status != 0 and not install_deb_package('curl'):
Log.err('Fail to install curl')
sys.exit(1)
Log.info('Install nodejs with "apt-get" (sudo privileges required)')
cmds = ['curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -', \
'sudo apt-get install -y nodejs']
try:
for cmd in cmds: subprocess.check_call(cmd, shell=True)
except subprocess.CalledProcessError:
Log.err('Exception is occurred during install nodejs.')
return False
return True
def get_version(s):
# Remove unnecessary character and split the string by dot
v = re.sub('[v\n]', '', s).split('.')
return map(int, v)
def ensure_nodejs():
status = subprocess.call('which node > /dev/null', shell=True)
if status != 0 and not install_nodejs():
Log.err('''Fail to install nodejs. Please install nodejs manually.
(https://nodejs.org/en/download/)''')
return False
ver = get_version(subprocess.check_output('node --version', shell=True))
active = 10
if ver[0] < active:
Log.err('''Current nodejs is to old to run this.
Please remove nodejs and install newer version nodejs or re-run this.''')
return False
if ver[0] != active:
Log.warn('''Current nodejs is not active lts version.
(https://github.com/nodejs/LTS#lts-schedule1)''')
return True
def install_grunt(path):
try:
pre = subprocess.check_output('npm config get prefix', shell=True).strip()
subprocess.check_call('npm config set prefix %s' % path, shell=True)
subprocess.check_call('npm install -g grunt-cli', shell=True)
except:
Log.err('Exception is occurred during install grunt')
return False
finally:
if pre == 'undefined' or pre == '/usr':
subprocess.check_call('npm config delete prefix', shell=True)
elif isinstance(pre, str):
subprocess.check_call('npm config set prefix %s' % pre, shell=True)
return True
def install_nodejs_dependencies(path, mode, option):
dest = os.path.join(path, 'node_modules')
if mode == 'quick':
if os.path.isdir(dest):
Log.info('Skip installing nodejs dependencies of %s in quick mode' % path)
return True
if mode == 'reinstall':
if os.path.isdir(dest):
Log.info('Remove previously dependencies of %s in reinstall mode' % path)
subprocess.call('rm -rf %s;git checkout %s 2>/dev/null' % (dest, dest), shell=True)
Log.info('Install nodejs dependencies in %s' % path)
cmd = 'cd %s && npm install %s' % (path, option)
try:
subprocess.check_call(cmd, shell=True)
except:
Log.err('''Fail to install nodejs dependencies of %s.
(If your network works in proxy, then you may need to set some keys of "npm config".)
(proxy, https-proxy, strict-ssl, cafile, etc.) (https://docs.npmjs.com/misc/config)''' % path)
return False
return True
def prepare_nodejs(mode, pwe):
Log.info('Check nodejs')
if not ensure_nodejs():
return False, ''
Log.info('Check grunt')
npm_path = os.path.join(tool_path, 'npm')
bin_path = os.path.join(npm_path, 'bin')
if not os.path.isfile(os.path.join(bin_path, 'grunt')) \
and not install_grunt(npm_path):
Log.err('Fail to install grunt.')
return False, ''
install_option = []
pathlist = ['.',
'libs/brackets-server',
'libs/brackets-server/embedded-ext/brackets-iotjs/node',
'libs/brackets-server/embedded-ext/brackets-minify/node',
'libs/brackets-server/embedded-ext/file-extension/node',
'libs/brackets-server/embedded-ext/interactive3D/node',
'libs/brackets-server/embedded-ext/project/node',
'libs/brackets-server/embedded-ext/swmitra.html-designer/i3d/node',
'libs/brackets-server/embedded-ext/tizen-profile/node',
'libs/tau-wysiwig',
'tools/crx',
'tools/cli']
if pwe:
pathlist.append('libs/brackets-server/embedded-ext/pwe/node')
install_option = ' '.join(install_option)
for path in pathlist:
if not install_nodejs_dependencies(path, mode, install_option):
Log.err('Fail to install dependencies in %s' % path)
return False, ''
return True, bin_path
def prepare_DE():
#TODO consider moving this code to WATT's build option
Log.info('Preparing Design Editor')
cmd = 'cd libs/tau-wysiwig && npm install && npm run-script build-watt > prepare_DE.log'
try:
subprocess.check_call(cmd, shell=True)
except:
Log.err('Failed to prepare Design Editor')
return False
Log.info('Design Editor prepared successfully')
return True
def install_mongodb():
if os_name == 'Darwin':
Log.info('Install mongodb with "brew"')
cmds = ['brew update', 'brew install mongodb']
elif (os_name == 'Ubuntu') and (os_dist in supported):
Log.info('Install mongodb with "apt-get" (sudo privileges required)')
cmds = ['sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80' \
+ ' --recv 0C49F3730359A14518585931BC711F9BA15703C6', '', \
'sudo apt-get update', 'sudo apt-get install -y mongodb-org']
if os_dist == 'trusty':
cmds[1] = 'echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu' \
+ ' trusty/mongodb-org/3.4 multiverse"' \
+ ' | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list'
else:
cmds[1] = 'echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/' \
+ 'ubuntu xenial/mongodb-org/3.4 multiverse"' \
+ ' | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list'
else:
Log.err('Cannot install mongodb automatically in %s(%s)' \
% (os_name, os_dist))
return False
try:
for cmd in cmds: subprocess.check_call(cmd, shell=True)
except subprocess.CalledProcessError:
Log.err('Exception is occurred during install mongodb.')
return False
return True
def is_run_process(name):
for p in psutil.process_iter():
if p.name() == name:
return True
return False
def check_libgconf():
Log.info('Check libgconf-2-4 library')
status = subprocess.call('ldconfig -p | grep libgconf-2 > /dev/null', shell=True)
if status != 0 and not install_deb_package('libgconf-2-4'):
Log.err('''Fail to install libgconf-2.4 Please install libgconf-2.4 manually.''')
return False
return True
def check_mongodb():
Log.info('Check mongodb service')
if os.environ.get('NODE_ENV') == 'docker':
Log.info('WATT will connect to external mongodb')
return True
if is_run_process('mongod'):
Log.info('mongodb service is started already.')
return True
Log.warn('mongodb service is not started.')
status = subprocess.call('which mongod > /dev/null', shell=True)
if status != 0 and not install_mongodb():
Log.err('''Fail to install mongodb. Please install mongodb manually.
(https://docs.mongodb.com/manual/installation/)''')
return False
Log.info('Try to start mongodb service. (sudo privileges required)')
try:
if os_name == 'Ubuntu':
subprocess.check_call(['sudo', 'service', 'mongod', 'start'])
else:
subprocess.Popen(['mongod', '--dbpath', root_path])
except subprocess.CalledProcessError:
Log.err(u'''Fail to start mongodb service.
If use mongodb 3.2 version in ubuntu 16.04, then check systemd service name.
(https://docs.mongodb.com/v3.2/tutorial/install-mongodb-on-ubuntu/#ubuntu-16-04-only-create-systemd-service-file)''')
return False
return True
def download_file(url, dest_path):
parent_dir = os.path.dirname(dest_path)
file_object = None
try:
if not os.path.isdir(parent_dir): os.makedirs(parent_dir)
res = requests.get(url)
file_object = open(dest_path, 'wb')
file_object.write(res.content)
except requests.exceptions.SSLError:
Log.err(u'''SSLError is occured.
Please check REQUESTS_CA_BUNDLE environ variable for certificate.
(eq. set /etc/ssl/certs/ca-certificates.crt)''')
return False
except:
Log.err('Fail to download %s' % url)
return False
finally:
if file_object: file_object.close()
return True
def preinstall_emsdk():
if os.environ.get('NODE_ENV') == 'docker':
Log.info('Skip preinstall_emsdk in docker')
return True
pkgs = [ 'build-essential', 'cmake', 'git-core' ]
for pkg in pkgs:
if not install_deb_package(pkg):
return False
return True
def ensure_emsdk(emsdk_path):
bin_path = os.path.join(emsdk_path, 'emsdk')
if os.path.isfile(bin_path): return True
if not preinstall_emsdk(): return False
work_path = os.path.dirname(emsdk_path)
Log.warn('Download emsdk tool')
url = 'https://s3.amazonaws.com/mozilla-games/emscripten/releases/'
file_name = 'emsdk-portable.tar.gz'
dest_path = os.path.join(work_path, file_name)
if not download_file(url + file_name, dest_path): return False
tar = tarfile.open(dest_path)
tar.extractall(work_path)
tar.close()
os.remove(dest_path)
portable_path = os.path.join(work_path, 'emsdk-portable')
os.rename(portable_path, emsdk_path)
return True
def get_emscripten_path(version):
Log.info('Check emscripten')
emsdk_path = os.path.join(tool_path, 'emsdk')
emscripten_path = os.path.join(emsdk_path, 'emscripten', version)
if platform.machine().endswith('64'):
clang_version = 'clang-e%s-64bit' % version
clang_path = os.path.join(emsdk_path, 'clang', 'e%s_64bit' % version)
else:
clang_version = 'clang-tag-e%s-32bit' % version
clang_path = os.path.join(emsdk_path, 'clang', 'tag-e%s' % version)
os.putenv('LLVM', clang_path)
if os.path.isdir(emscripten_path): return emscripten_path
if not ensure_emsdk(emsdk_path):
Log.err('''Fail to install emscripten. Please install emscripten manually.
(https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html)''')
return ''
Log.warn('Download emscripten. (version:%s). It takes a lot of time.' % version)
bin_path = os.path.join(emsdk_path, 'emsdk')
cmds = [
'%s update-tags' % bin_path,
'%s install %s emscripten-%s' % (bin_path, clang_version, version)
]
try:
for cmd in cmds: subprocess.check_call(cmd, shell=True)
except subprocess.CalledProcessError:
Log.err('Exception is occurred during download emscripten.')
return ''
return emscripten_path
def build_wabt():
Log.info('Build wabt if necessary.')
try:
subprocess.check_call('cd tools/wabt; make gcc-release-no-tests', shell=True)
except:
Log.err('Fail to build wabt. Please try rerun after fix build break.')
return False
return True
def ensure_wabt(wabt_path):
wabt_bin_path = os.path.join(wabt_path, 'bin')
if os.path.isdir(wabt_bin_path): return True
Log.warn('Download wabt tool')
url = 'https://github.com/WebAssembly/wabt/archive/'
file_name = '1.0.0.tar.gz'
dest_path = os.path.join(tool_path, file_name)
if not download_file(url + file_name, dest_path): return False
tar = tarfile.open(dest_path)
tar.extractall(tool_path)
tar.close()
os.remove(dest_path)
portable_path = os.path.join(tool_path, 'wabt-1.0.0')
os.rename(portable_path, wabt_path)
return build_wabt()
def get_wabt_path():
Log.info('Check wabt')
wabt_path = os.path.join(tool_path, 'wabt')
wabt_bin_path = os.path.join(wabt_path, 'bin')
if os.path.isdir(wabt_bin_path): return wabt_bin_path
if not ensure_wabt(wabt_path):
Log.err('Fail to install wabt. Please install wabt manually.(https://github.com/WebAssembly/wabt)')
return ''
return wabt_bin_path
def ensure_deb_package(name):
Log.info('Check %s package' % name)
status = subprocess.call('dpkg -l | grep %s > /dev/null' % name, shell=True)
if status != 0 and not install_deb_package(name):
Log.err('''Fail to install %s. Please install it manually.''' % name)
return False
return True
def install_deb_package(name):
Log.info('Install %s package (sudo privileges required)' % name)
try:
subprocess.check_call('sudo apt-get update && sudo apt-get install -y %s' % name, shell=True)
except subprocess.CalledProcessError:
Log.err('Exception is occurred during install %s.' % name)
return False
return True
def ensure_nacl(nacl_path):
bin_path = os.path.join(nacl_path, 'naclsdk')
if os.path.isfile(bin_path): return True
work_path = os.path.dirname(nacl_path)
Log.info('Download NaCl tool')
url = 'http://storage.googleapis.com/nativeclient-mirror/nacl/nacl_sdk/'
file_name = 'nacl_sdk.zip'
dest_path = os.path.join(work_path, file_name)
if not download_file(url + file_name, dest_path): return False
zip = zipfile.ZipFile(dest_path)
zip.extractall(work_path)
zip.close()
os.remove(dest_path)
return True
def update_nacl_cert(update_nacl_cmd, nacl_path, invalidCertErrorString):
Log.info('Update nacl cacerts.txt')
# NaCl's SDK has out of dated CA, https://groups.google.com/forum/#!topic/native-client-discuss/ViBofmhWpyM
if not ensure_deb_package('ca-certificates'):
return False;
global_ca_path = os.path.join(os.sep, 'etc', 'ssl', 'certs', 'GlobalSign_Root_CA_-_R2.pem')
if not os.path.exists(global_ca_path):
Log.err('Could not find root CA at ' + global_ca_path)
return False;
nacl_ca_path = os.path.join(nacl_path, 'sdk_tools', 'cacerts.txt')
if not os.path.exists(nacl_ca_path):
Log.err('Could not find nacl CA at ' + nacl_ca_path)
return False;
shutil.copy(global_ca_path, nacl_ca_path)
try:
subprocess.check_output(update_nacl_cmd, stderr=subprocess.STDOUT, shell=True)
except subprocess.CalledProcessError as e:
# First call to update overwrites cacerts.txt, copy cert and call update again.
if invalidCertErrorString in e.output:
shutil.copy(global_ca_path, nacl_ca_path)
try:
subprocess.check_call(update_nacl_cmd, shell=True)
Log.info('Successfully run %s' % update_nacl_cmd)
except subprocess.CalledProcessError:
Log.err('Exception occurred during nacl CA update.')
Log.warn(e.output)
return False
return True;
def get_nacl_path():
Log.info('Check Google Native client SDK')
nacl_path = os.path.join(tool_path, 'nacl_sdk')
nacl_pepper_path = os.path.join(nacl_path, 'pepper_49')
if os.path.isdir(nacl_pepper_path): return nacl_pepper_path
if not ensure_nacl(nacl_path):
Log.err('''Fail to install Chrome Native Client SDK. Please install NaCl SDK manually.
(https://developer.chrome.com/native-client/sdk/download)''')
return ''
if not ensure_deb_package('libc6:i386'):
return False;
bin_path = os.path.join(nacl_path, 'naclsdk')
st = os.stat(bin_path)
os.chmod(bin_path, st.st_mode | stat.S_IEXEC)
update_cmd = '%s update %s' % (bin_path, 'pepper_49')
try:
subprocess.check_output(update_cmd, stderr=subprocess.STDOUT, shell=True)
except subprocess.CalledProcessError as e:
invalidCertError = 'InvalidCertificateException: Host storage.googleapis.com returned an invalid certificate'
if invalidCertError in e.output:
Log.warn('Invalid CA in naclsdk')
if update_nacl_cert(update_cmd, nacl_path, invalidCertError):
return nacl_pepper_path
else:
return ''
else:
Log.err('Exception occurred during download NaCl SDK.')
Log.warn(e.output)
return ''
def get_tizen_path():
path = os.path.join(os.path.expanduser('~'), 'tizen-studio')
tizen_path = os.path.join(path, 'tools', 'ide', 'bin', 'tizen')
if not os.path.isdir(path) or not os.path.isfile(tizen_path):
Log.warn('''Can not find tizen studio.
Please ensure to execute tizen command if use WGT packaging.''')
return ''
return os.path.dirname(tizen_path)
def build_brackets():
Log.info('Build brackets if necessary.')
try:
subprocess.check_call('cd libs/brackets-server/brackets-dist 2>/dev/null' \
'|| { cd libs/brackets-server; grunt build; }', shell=True)
except:
Log.err('Fail to build. Please try rerun after fix build break.')
return False
return True
def sync_tau_wysiwig():
Log.info('Syncing TAU WYSIWIG extension')
try:
subprocess.call('cd libs/brackets-server/embedded-ext' \
'&& test -L ./tau' \
'|| ln -s ../../tau-wysiwig/dist/watt tau', shell=True);
except:
Log.err('Failed to sync TAU WYSIWIG extension')
return False
return True
def preinstall_iotjs():
pkgs = [ 'gyp', 'cmake', 'build-essential', 'valgrind' ]
for pkg in pkgs:
if not install_deb_package(pkg):
return False
return True
def ensure_iotjs(iotjs_path, version):
if os.path.isdir(iotjs_path): return True
if not preinstall_iotjs(): return False
try:
subprocess.check_call('cd tools/; git clone https://github.com/Samsung/iotjs.git', shell=True)
except subprocess.CalledProcessError:
Log.err('Exception is occurred during git clone')
return False
return True
def get_iotjs_path(version):
Log.info('Check iotjs')
iotjs_path = os.path.join(tool_path, 'iotjs')
if platform.machine().endswith('64'):
iotjs_build_path = os.path.join(iotjs_path, 'build', 'x86_64-linux', 'debug', 'bin')
else:
iotjs_build_path = os.path.join(iotjs_path, 'build', 'x86-linux', 'debug', 'bin')
iotjs_bin_path = os.path.join(iotjs_build_path, 'iotjs')
if os.path.isfile(iotjs_bin_path): return iotjs_build_path
if not ensure_iotjs(iotjs_path, version):
Log.err('Fail to install IoT.js. Please install IoT.js manually.(https://github.com/Samsung/iotjs)')
return ''
Log.warn('Build iot.js')
try:
subprocess.check_call('cd tools/iotjs/; ./tools/build.py --no-check-test', shell=True)
except subprocess.CalledProcessError:
Log.err('Exception is occurred during IoT.js build.')
return ''
return iotjs_build_path
def run_service(args):
print_msg = True
need_rebuild = False
watch_srv = None
srv_cmd = ['node', 'app.js']
rlist = [sys.stdin]
devnull = open(os.devnull, 'w')
if args.pwe:
try:
module = __import__('validators')
except ImportError:
Log.info('Install validators packages. (sudo privileges required)')
status = subprocess.call(['sudo', 'pip', 'install', 'validators'])
if status != 0:
Log.err('Fail to install validators package')
sys.exit(1)
module = __import__('validators')
globals()['validators'] = module
os.putenv('NODE_ENV', 'pwe')
Log.info('Start in pwe mode.')
config_path = os.path.join(root_path, 'config/pwe.json')
file_object = open(config_path, 'r')
json_object = json.load(file_object)
if 'HUB_URL' in json_object:
Log.info('S-HUB_URL: ' + json_object['HUB_URL'])
else:
input_url = raw_input('Please input S-Hub URL(ex. https://domain.com): ')
if not validators.url(input_url):
Log.err('Invalid url. Please try rerun and input valid url')
sys.exit(1)
json_object['HUB_URL'] = input_url
file_object.close()
file_object = open(config_path, 'w')
data = json.dumps(json_object)
file_object.write(data)
file_object.close()
if args.verbose:
out = None
err = None
else:
out = devnull
err = subprocess.PIPE
service = subprocess.Popen(srv_cmd, stdout=out, stderr=err)
Log.info('%s is started' % SERVICE)
try:
while True:
if print_msg:
Log.info('Enter command (build | b, deps | d, rerun | r, watch | w, exit | x)\n> ', False)
print_msg = False
ready_rlist, _, _ = select.select(rlist, [], [], 5)
if watch_srv and watch_srv.stdout in ready_rlist:
msg = watch_srv.stdout.readline().strip()
if msg.startswith('[WatchEvent]'):
if args.verbose: Log.trace(msg)
if not need_rebuild: Log.info('File changing is detected')
need_rebuild = True
if sys.stdin in ready_rlist:
print_msg = True
cmd_list = sys.stdin.readline().strip().lower().split()
cmd = cmd_list[0] if len(cmd_list) > 0 else ''
if cmd == 'build' or cmd == 'b':
try:
subprocess.check_call('cd libs/brackets-server; grunt build', shell=True)
except:
Log.err('Fail to build. Please try rerun after fix build break.')
need_rebuild = False
elif cmd == 'deps' or cmd == 'd':
if len(cmd_list) == 1:
Log.info('mode value is missing. It will use update mode.')
cmd_list.append('update')
prepare_nodejs(cmd_list[1], args.pwe)
prepare_DE()
elif cmd == 'rerun' or cmd == 'r':
if (need_rebuild):
Log.warn('Need rebuild')
try:
subprocess.check_call('cd libs/brackets-server; grunt build', shell=True)
except:
Log.err('Fail to build. Please try rerun after fix build break.')
continue
need_rebuild = False
service.terminate()
service.communicate()
service = subprocess.Popen(srv_cmd, stdout=out, stderr=err)
Log.info('%s is restarted' % SERVICE)
elif cmd == 'watch' or cmd == 'w':
watch_srv = subprocess.Popen(['grunt', 'watch'], stdout=subprocess.PIPE, stderr=err)
rlist.append(watch_srv.stdout)
Log.info('watch service start (File changing is not handled in initialize time)')
elif cmd == 'exit' or cmd == 'x':
break
else:
Log.warn('Invalid command (%s) was entered.' % cmd)
pid, _ = os.waitpid(service.pid, os.WNOHANG)
if pid == service.pid:
Log.err('%s needs restarting because of implicityly termination' % SERVICE)
if service.stderr and (not service.stderr.closed):
Log.trace(service.stderr.read())
service = subprocess.Popen(srv_cmd, stdout=out, stderr=err)
except KeyboardInterrupt:
pass
finally:
if watch_srv:
watch_srv.terminate()
watch_srv.communicate()
service.terminate()
service.communicate()
if service.returncode != 0:
Log.err('%s is terminated with abnormal code.(%d)' \
% (SERVICE, service.returncode))
if service.stderr and (not service.stderr.closed):
Log.trace(service.stderr.read())
return service.returncode
def main():
parser = argparse.ArgumentParser(description=('Launch %s' % SERVICE))
parser.add_argument('-v', '--verbose', action='store_true',
help='Print message from %s' % SERVICE)
parser.add_argument('-d', '--dry', action='store_true',
help='Launch with dry mode')
parser.add_argument('-n', '--npm', choices=['quick', 'update', 'reinstall'],
default='quick', help='Check mode for installing dependency packages')
parser.add_argument('-bpnacl', '--bypass_nacl_sdk', action='store_true',
help='Bypass downloading NaCl')
group = parser.add_mutually_exclusive_group()
group.add_argument('-ep', '--emscripten_path',
help='Use the emscripten of the specific path')
group.add_argument('-ev', '--emscripten_version', default='1.38.11',
help='Use the emscripten of the specific version')
parser.add_argument('-i', '--iotjs', action='store_true',
help='Support iot.js extension')
parser.add_argument('-p', '--pwe', action='store_true',
help='Launch with pwe mode')
parser.add_argument('-s', '--sthings', action='store_true',
help='Support sthings extension')
parser.add_argument('-bdc', '--bypassDEcompilation', action='store_true',
default=False, help='Bypass Design Editor compilation')
parser.add_argument('-bp', '--bypass', action='store_true',
help='Bypass submodule update')
args = parser.parse_args()
if args.bypass == 0:
Log.info('Update submodules')
if (subprocess.check_call('./update_submodules' + (' --verbose' if args.verbose else ''), shell=True)) != 0:
Log.err('Fail to initialize or update submodules.')
return 1
ret, grunt_path = prepare_nodejs(args.npm, args.pwe)
if not ret:
return 1
if args.sthings and not ensure_deb_package('android-tools-adb'):
return 1
if not args.bypassDEcompilation and not prepare_DE():
return 1
if not check_mongodb():
return 1
if args.sthings and not check_libgconf():
return 1
if args.emscripten_path == None or not os.path.isdir(args.emscripten_path):
if args.emscripten_path != None:
Log.warn('emscripten path (%s) is not valid.' % args.emscripten_path)
emscripten_path = ''
else:
emscripten_path = args.emscripten_path
if emscripten_path == '':
emscripten_path = get_emscripten_path(args.emscripten_version)
if emscripten_path == '': return 1
Log.info('Use emscripten at %s' % emscripten_path)
wabt_bin_path = get_wabt_path()
pathlist = [grunt_path, emscripten_path, os.path.join(tool_path, 'WebIDLBinder'), wabt_bin_path, '']
tizen_path = get_tizen_path()
if tizen_path != '':
pathlist.insert(-1, tizen_path)
# Temporary path for API-Grepper
pathlist.insert(-1, os.path.join(tool_path, 'api_grepper'))
os.putenv('PATH', os.pathsep.join(pathlist) + os.environ['PATH'])
if not args.bypass_nacl_sdk:
# Path for NACL_SDK_ROOT for pepper.js
os.putenv('NACL_SDK_ROOT', get_nacl_path())
if args.iotjs:
if (os_name == 'Ubuntu') and (os_dist in supported):
iotjs_path = get_iotjs_path('1.0')
if iotjs_path == '': return 1
os.putenv('SUPPORT_IOT_JS', 'true')
os.putenv('IOT_JS_ROOT', iotjs_path)
else:
Log.err('Ubuntu 14.04 or 16.04 are recommended.')
sys.exit(1)
if args.sthings:
os.putenv('SUPPORT_STHINGS', 'true')
sync_tau_wysiwig()
if not build_brackets():
return 1
if args.dry:
Log.warn('Skip run service')
return 0
return run_service(args)
if __name__ == '__main__':
returncode = main()