From d18ee126788c01075d169b2b4dde4bfd2bb1f6f9 Mon Sep 17 00:00:00 2001 From: shujunqiao Date: Fri, 21 Mar 2014 14:15:59 +0800 Subject: [PATCH] for test close project in cocos-console-test.py. --- tools/jenkins-scripts/cocos-console-test.py | 49 ++++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/tools/jenkins-scripts/cocos-console-test.py b/tools/jenkins-scripts/cocos-console-test.py index a40e05b6d4..201b36c84b 100755 --- a/tools/jenkins-scripts/cocos-console-test.py +++ b/tools/jenkins-scripts/cocos-console-test.py @@ -5,31 +5,33 @@ import os import sys import json - +import time # get payload argvs -console_param = '[console create]' +console_param = '[console run]' # payload = '' if os.environ.has_key('payload'): payload_str = os.environ['payload'] payload = json.loads(payload_str) if payload.has_key('console'): console_param = payload['console'] -console_param = console_param[1:len(strConsole)-1] +console_param = console_param[1:len(console_param)-1] print 'console_param:',console_param console_param_arr = console_param.split(' ') -project_types = ['cpp', 'lua'] +# project_types = ['cpp', 'lua'] +project_types = ['cpp'] PROJ_SUFFIX = 'Proj' -phonePlats = ['mac','ios','android'] +# phonePlats = ['mac','ios','android'] +phonePlats = ['ios'] #need use console's position, perhaps should be set an env-param cocos_console_dir = 'tools/cocos2d-console/bin/' #now cocos2d-console suport different run on Platforms, e.g: only run android on win runSupport = { - 'darwin' : [1, 1, 1], + 'darwin' : [1, 1, 0], 'win' : [0, 0, 1], 'linux' : [0, 0, 1] } @@ -56,6 +58,36 @@ def create_project(): print proj,'cmd:',cmd info_create = os.system(cmd) #call cmd on win is diff print 'create project',proj,' is:', not info_create + +def getAppPID(name): + cmd = 'ps -eo pid,comm | grep '+name + output = os.popen(cmd) + result = output.read() + arrProcess = result.split('\n') + print 'arrProcess:', arrProcess + def getProcessId(proInfo): + if len(proInfo) > 0: + arrInfo = proInfo.split(' ') + return int(arrInfo[0]) + return -1 + arrProIdx = [] + for content in arrProcess: + idx = getProcessId(content) + if idx > 0: + arrProIdx.append(idx) + return arrProIdx +def close_proj(proj): + print 'close running project' + if curPlat == 'darwin': + print 'will close proj:',proj,', on',curPlat + arrPids = getAppPID(proj+PROJ_SUFFIX) + print 'arrPids:', arrPids + for pid in arrPids: + cmd = 'kill ' + cmd += str(pid) + print 'cmd:',cmd + os.system(cmd) + def build_run(): print 'will build and run' for proj in project_types: @@ -66,6 +98,10 @@ def build_run(): if runSupport[curPlat][idx]: info_run = os.system(cmd) print 'run project', proj, 'is:', not info_run + if info_run == 0: + time.sleep(5) + close_proj(proj) + time.sleep(2) idx += 1 def main(): @@ -73,6 +109,7 @@ def main(): create_project() if console_param_arr.count('run'): build_run() + # close_proj('cpp') # -------------- main -------------- if __name__ == '__main__':