-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathandroidlibs.py
More file actions
139 lines (119 loc) · 3.8 KB
/
Copy pathandroidlibs.py
File metadata and controls
139 lines (119 loc) · 3.8 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
#encoding=utf-8
import sys
import os
__version__ = "1.0"
current_path = os.path.abspath('.')
def show_help():
help_text = '''
使用说明: androidlibs [--version] [-c androidlibs.txt] [-h] [指令]
参数说明:
--version 版本号
-c 指定androidlibs.txt的完整路径
-h 帮助文档
指令说明:
update 更新代码。以同步方式更新,可以看到每个工程的更新结果
update-async 异步更新代码。无法看到每个工程的更新结果
clean 清除所有Library工程
'''
print help_text
def get_config():
if '-c' in sys.argv and sys.argv[sys.argv.index('-c')+1]:
config_arg = sys.argv[sys.argv.index('-c')+1]
else:
config_arg = 'androidlibs.txt'
config_file = open(config_arg, 'r')
config_str = [line.replace("\n","") for line in config_file.readlines()]
config_str = "".join(config_str)
exec(config_str)
print '找到以下Library工程,准备开始更新啦...'
print '============'
for tag in androidlibs_config:
print ' ', tag['name']
print '============'
return androidlibs_config
def run_cmd(cmd):
import subprocess
#print 'Run : %s' % cmd
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = [line for line in p.stdout.readlines()]
retval = p.wait()
return retval, result
def run_cmd_async(cmd):
import subprocess
subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
def do_update(async=False):
try:
print '首先更新最新的Library工程配置'
ret, result = run_cmd("git pull origin master")
if ret == 0:
print 'Library工程配置更新完毕'
else:
print 'Library工程配置更新失败!!!请检查你当前目录是否正确,再试一次。'
sys.exit()
except Exception, e:
print e
try:
config = get_config()
if config:
for lib in config:
if lib['tags']:
for tag in lib['tags']:
print '开始更新 %s 工程 %s 分支,请稍候……' % (lib['name'], tag)
target = '%s-lib/master' % lib['name'] if tag == 'master'else '%s-lib/releases/%s' % (lib['name'], tag)
if os.path.exists(target):
if tag == 'master':
os.chdir('%s/%s' % (current_path, target))
cmd = 'git pull origin master'
if async:
run_cmd_async(cmd)
else:
ret, result = run_cmd(cmd)
if ret != 0:
print 'master分支更新失败'
os.chdir(current_path)
else:
print '%s 已经有了,我就不更新啦。' % target
else:
if tag == 'master':
cmd = "git clone %s %s" % (lib['repo'], target)
else:
cmd = "git clone --single-branch -b %s %s %s" % (tag, lib['repo'], target)
if async:
run_cmd_async(cmd)
else:
ret, result = run_cmd(cmd)
if ret != 0:
print '%s分支更新失败' % tag
print ' %s 工程更新完毕。' % lib['name']
print ' '
except IOError, ioe:
print '找不到配置文件。', e
except Exception, e:
print '出错啦!', e
def do_clean():
run_cmd("rm -rf *-lib")
if len(sys.argv) <= 1:
show_help()
sys.exit()
if '-h' in sys.argv:
show_help()
sys.exit()
if 'update' in sys.argv:
try:
do_update()
except Exception, e:
print e
sys.exit()
if 'update-async' in sys.argv:
try:
do_update(True)
except Exception, e:
print e
sys.exit()
if 'clean' in sys.argv:
try:
do_clean()
except Exception, e:
print e
if '--version' in sys.argv:
print 'Version: %s' % __version__