# coding=utf-8
import os
import os.path
import subprocess
import sys
import time
# print "ssssss"
os.chdir(sys.argv[1])
subprocess.Popen("chmod a+x "+"./gradlew", shell=True)
# s=subprocess.Popen("./gradlew clean build", shell=True)
# if s.wait()==0:
# print "-------"
# else:
# print "======="
# subprocess.Popen("rm "+sys.argv[0], shell=True)
# print "Command execution completed"
c=subprocess.Popen('./gradlew clean', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if c.wait()==0:
print 'clean 執行成功'
b=subprocess.Popen('./gradlew build', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, err = b.communicate()
for line in out.splitlines():
print(line)
# if b.wait()==0:
# print '編譯成功'
# else:
# print '編譯失敗'
else:
print 'clean 執行失敗'