python执行gradle脚本

时间:2023-03-09 16:40:05
python执行gradle脚本
 import os
import shutil
import subprocess #拷贝文件
def copyFile(srcFile, dstFile):
#检查源文件是否存在
if not os.path.isfile(srcFile):
print('%s not exist' % srcFile)
return False
#如果目的路径不存在创建目录
fpath, fname = os.path.split(dstFile)
if not os.path.exists(fpath):
os.makedirs(fpath)
shutil.copyfile(srcFile, dstFile)
print('copy %s -> %s' %(srcFile,dstFile))
return True #删除文件
def deleteFile(path) :
if os.path.exists(path):
os.remove(path) #执行gradle task
def gradleBuild(task, gradlePath, **kwargs):
args = ''
for key in kwargs:
args += '-P' + key + '=' + '\"' + kwargs[key] + '\"' + " " cmd = 'gradle %s %s -b %s/build.gradle' % (task, args, gradlePath)
mystr = os.popen(cmd)
mystr = mystr.read()
#print(mystr)
if mystr.find('BUILD SUCCESSFUL') != -1:
print('execute task succ:%s' % cmd)
return True print('execute task failed:%s' % cmd)
return False