forked from SmartThingsCommunity/st-device-sdk-c-ref
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·87 lines (71 loc) · 2.31 KB
/
setup.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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import platform
import os
import sys
REPLACE_LIST = [
["from", "to"]
]
STDK_REF_PATH = os.path.dirname(os.path.abspath(__file__))
STDK_CORE_PATH = os.path.join(STDK_REF_PATH, "iot-core")
os.environ["STDK_REF_PATH"] = STDK_REF_PATH
os.environ["STDK_CORE_PATH"] = STDK_CORE_PATH
def print_usage():
print("")
print("Usage: python setup.py [BSP_NAME]")
print("--------------------------------------------------")
for dir in os.listdir(os.path.join(STDK_REF_PATH, "tools")):
dirpath = os.path.join(STDK_REF_PATH, "tools", dir)
if (os.path.exists(os.path.join(dirpath, "setup_"+ dir + ".py")) or
os.path.exists(os.path.join(dirpath, "setup_"+ dir + ".sh"))):
print(" ex) python setup.py " + dir)
print("")
def find_setup_script(bsp_name):
if os.path.exists(os.path.join("tools", bsp_name, "setup_" + bsp_name + ".py")):
return "python " + os.path.join("tools", bsp_name, "setup_" + bsp_name + ".py")
if "SHELL" in os.environ:
if os.path.exists(os.path.join("tools", bsp_name, "setup_" + bsp_name + ".sh")):
return os.path.join("tools", bsp_name, "setup_" + bsp_name + ".sh")
print("Fail to find setup script")
print_usage()
exit(1)
def update_submodule(path):
cwd = os.getcwd()
try:
print("Update submodule " + path)
os.system("git submodule sync " + path)
os.system("git submodule init " + path)
os.system("git submodule update " + path)
os.chdir(path)
os.system("git reset --hard HEAD")
except:
print("Failed to update submodule " + path)
os.chdir(cwd)
update_submodule(STDK_CORE_PATH)
if len(sys.argv) == 1:
print_usage()
exit(1)
BSP_NAME = sys.argv[1]
EXTRA_ARGS = sys.argv[2:]
for item in REPLACE_LIST:
if BSP_NAME == item[0]:
BSP_NAME = item[1]
setup_script = find_setup_script(BSP_NAME)
BSP_PATH = os.path.join(STDK_REF_PATH, "bsp", BSP_NAME)
if BSP_PATH and os.path.isdir(BSP_PATH):
update_submodule(BSP_PATH)
setup_cmd = setup_script + " " + BSP_NAME
for args in EXTRA_ARGS:
setup_cmd = setup_cmd + " " + args
ret_val = os.system(setup_cmd)
if ret_val:
print_usage()
exit(1)
else:
print("")
print("======================================================================")
print("")
print("To use SmartThings Device SDK build script, run following command:")
print("")
print(" python build.py " + BSP_NAME + " [APP_NAME]")
print("")