-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmakefile.py
More file actions
129 lines (102 loc) · 3.54 KB
/
makefile.py
File metadata and controls
129 lines (102 loc) · 3.54 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (C) 2015-2018 Shenzhen Auto-link world Information Technology Co., Ltd.
All Rights Reserved
Name: makefile.py
Purpose: Build all CommonAPI-Examples simplify
Created By: Clive Lau <liuxusheng@auto-link.com.cn>
Created Date: 2018-03-05
Changelog:
Date Desc
2018-03-05 Created by Clive Lau
"""
# Builtin libraries
import os
import sys
import getopt
import shutil
import logging
import platform
import commands
import subprocess
# Third-party libraries
# Customized libraries
################################################################################
def usage():
print('Usage: ' + sys.argv[0] + ' [OPTION...]\n'
'Build all CommonAPI-Examples simplify.\n'
'\n'
'-h, --help' + '\t\t' + 'Give this help list\n'
'-p, --project=NAME' + '\t' + 'Build the special project[E01HelloWorld / E02Attributes / E03Methods / E04PhoneBook / E05Manager / E06Unions / E07Mainloop]\n'
'-V, --version' + '\t\t' + 'Print program version\n')
def is_windows_os():
return platform.system() == 'Windows'
def get_status_output(cmd):
output = ''
if is_windows_os():
try:
status = subprocess.call(cmd)
if not status:
output = subprocess.check_output(cmd)
except WindowsError:
status = 255
output = ''
else:
try:
(status, output) = commands.getstatusoutput(cmd)
except Exception:
status = 255
output = ''
return status, output
def check_valid_tbox_device():
status, output = get_status_output('adb devices')
if (len(output.split()[4:]) / 2) != 1:
return False
status, output = get_status_output('adb shell cat /etc/tbox/device_version')
if output.rfind('No such file or directory') != -1:
return False
return True
def build_and_install_project(proj):
client = proj + 'Client'
service = proj + 'Service'
lib = 'lib' + proj + '-dbus.so'
logger.debug('client:\t' + client)
logger.debug('service:\t' + service)
logger.debug('lib:\t' + lib)
build_path = os.getcwd() + '/' + proj + '/build'
if os.path.exists(build_path):
shutil.rmtree(build_path)
try:
os.makedirs(build_path)
except OSError, e:
logger.warn(str(e))
os.chdir(build_path)
status, output = get_status_output('cmake ../')
print(output)
status, output = get_status_output('make')
print(output)
status, output = get_status_output('adb push ' + client + ' /usr/bin/')
print(output)
status, output = get_status_output('adb push ' + service + ' /usr/bin/')
print(output)
status, output = get_status_output('adb push ' + lib + ' /usr/lib/')
print(output)
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s/%(name)s(+ %(lineno)d): %(message)s')
logger = logging.getLogger(__name__)
if check_valid_tbox_device() is False:
logger.error('Cannot detect valid TBox device')
logger.debug('Detected valid TBox device')
opts, args = getopt.getopt(sys.argv[1:], "hp:V", ['help', 'project=', 'version'])
for opt_name, opt_value in opts:
if opt_name in ('-h', '--help'):
logger.debug('help')
usage()
exit()
if opt_name in ('-p', '--project'):
build_and_install_project(opt_value)
exit()
if opt_name in ('-V', '--version'):
print('Version 0.1')
exit()