From 0854f980fa99594a2bd591c4497bf6a981ae80a6 Mon Sep 17 00:00:00 2001 From: kompjoefriek Date: Thu, 29 Jan 2015 01:40:19 +0100 Subject: [PATCH] fixed indentation of Python files - Changed tabs to spaces - Changed 2 spaces to 4 spaces --- .../proj.android/build_native.py | 54 +- tools/jenkins-scripts/autotest.py | 264 +++++----- tools/jenkins-scripts/cocos-console-test.py | 458 ++++++++-------- tools/jenkins-scripts/configs/autotest.py | 2 +- .../configs/cocos-2dx-develop-android.py | 12 +- .../configs/cocos-2dx-develop-base-repo.py | 22 +- .../configs/cocos-2dx-develop-ios.py | 12 +- .../configs/cocos-2dx-develop-win32.py | 14 +- .../configs/cocos-2dx-doxygen.py | 14 +- ...-2dx-pull-request-build-comment-trigger.py | 4 +- .../cocos-2dx-pull-request-build-trigger.py | 4 +- .../configs/cocos-2dx-pull-request-build.py | 30 +- .../configs/cocos2d-console-test.py | 2 +- .../configs/cocostudiox-base-repo.py | 4 +- .../configs/cocostudiox-daily-build.py | 24 +- tools/jenkins-scripts/emptytest.py | 490 +++++++++--------- tools/jenkins-scripts/github-pr-watchdog.py | 96 ++-- tools/jenkins-scripts/post-build.py | 8 +- tools/jenkins-scripts/reboot.py | 60 +-- 19 files changed, 787 insertions(+), 787 deletions(-) diff --git a/templates/cpp-template-default/proj.android/build_native.py b/templates/cpp-template-default/proj.android/build_native.py index fdcdf9b0ac..dd948d6d9b 100755 --- a/templates/cpp-template-default/proj.android/build_native.py +++ b/templates/cpp-template-default/proj.android/build_native.py @@ -9,14 +9,14 @@ import shutil from optparse import OptionParser def get_num_of_cpu(): - ''' The build process can be accelerated by running multiple concurrent job processes using the -j-option. - ''' - try: - import multiprocessing - return multiprocessing.cpu_count() - except Exception: - print "Can't know cpuinfo, use default 1 cpu" - return 1 + ''' The build process can be accelerated by running multiple concurrent job processes using the -j-option. + ''' + try: + import multiprocessing + return multiprocessing.cpu_count() + except Exception: + print "Can't know cpuinfo, use default 1 cpu" + return 1 def check_environment_variables_sdk(): ''' Checking the environment ANDROID_SDK_ROOT, which will be used for building @@ -69,17 +69,17 @@ def do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,and if os.system(command) != 0: raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!") elif android_platform is not None: - sdk_tool_path = os.path.join(sdk_root, "tools/android") - cocoslib_path = os.path.join(cocos_root, "cocos/platform/android/java") - command = '%s update lib-project -t %s -p %s' % (sdk_tool_path,android_platform,cocoslib_path) - if os.system(command) != 0: - raise Exception("update cocos lib-project [ " + cocoslib_path + " ] fails!") - command = '%s update project -t %s -p %s -s' % (sdk_tool_path,android_platform,app_android_root) - if os.system(command) != 0: - raise Exception("update project [ " + app_android_root + " ] fails!") - buildfile_path = os.path.join(app_android_root, "build.xml") - command = 'ant clean %s -f %s -Dsdk.dir=%s' % (build_mode,buildfile_path,sdk_root) - os.system(command) + sdk_tool_path = os.path.join(sdk_root, "tools/android") + cocoslib_path = os.path.join(cocos_root, "cocos/platform/android/java") + command = '%s update lib-project -t %s -p %s' % (sdk_tool_path,android_platform,cocoslib_path) + if os.system(command) != 0: + raise Exception("update cocos lib-project [ " + cocoslib_path + " ] fails!") + command = '%s update project -t %s -p %s -s' % (sdk_tool_path,android_platform,app_android_root) + if os.system(command) != 0: + raise Exception("update project [ " + app_android_root + " ] fails!") + buildfile_path = os.path.join(app_android_root, "build.xml") + command = 'ant clean %s -f %s -Dsdk.dir=%s' % (build_mode,buildfile_path,sdk_root) + os.system(command) def copy_files(src, dst): @@ -119,15 +119,15 @@ def build(ndk_build_param,android_platform,build_mode): copy_resources(app_android_root) if android_platform is not None: - sdk_root = check_environment_variables_sdk() - if android_platform.isdigit(): - android_platform = 'android-'+android_platform - else: - print 'please use vaild android platform' - exit(1) - + sdk_root = check_environment_variables_sdk() + if android_platform.isdigit(): + android_platform = 'android-'+android_platform + else: + print 'please use vaild android platform' + exit(1) + if build_mode is None: - build_mode = 'debug' + build_mode = 'debug' elif build_mode != 'release': build_mode = 'debug' diff --git a/tools/jenkins-scripts/autotest.py b/tools/jenkins-scripts/autotest.py index 74857a17cf..31ea709e1d 100755 --- a/tools/jenkins-scripts/autotest.py +++ b/tools/jenkins-scripts/autotest.py @@ -21,153 +21,153 @@ sleep_time = 1.5 # def getADBDeviceIP(): - output = os.popen("adb shell netcfg") - configs = output.read().split('\r\n') - for l in configs: - items = l.split() - if(items[1] == 'UP'): - if(items[2] != '127.0.0.1'): - return items[2] + output = os.popen("adb shell netcfg") + configs = output.read().split('\r\n') + for l in configs: + items = l.split() + if(items[1] == 'UP'): + if(items[2] != '127.0.0.1'): + return items[2] def autotest(type): - soc = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) - if type == TYPE_MAC: - soc.connect((HOST_MAC, PORT)) - if type == TYPE_ANDROID: - HOST_ANDROID = getADBDeviceIP() - soc.connect((HOST_ANDROID, PORT)) - if type == TYPE_IOS: - soc.connect((HOST_IOS, PORT)) - time.sleep(1) - print 'autotest run:' - soc.send('autotest run\r\n') + soc = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) + if type == TYPE_MAC: + soc.connect((HOST_MAC, PORT)) + if type == TYPE_ANDROID: + HOST_ANDROID = getADBDeviceIP() + soc.connect((HOST_ANDROID, PORT)) + if type == TYPE_IOS: + soc.connect((HOST_IOS, PORT)) + time.sleep(1) + print 'autotest run:' + soc.send('autotest run\r\n') - while True: - data = soc.recv(1024) - print data - if data == 'TestEnd': - lastTestInfo = True - break - global lastTestInfo - if len(data) > len('\n') : - lastTestInfo = data - if not data: break - - soc.send('director end\r\n') - print 'test end and close socket.' - soc.close() + while True: + data = soc.recv(1024) + print data + if data == 'TestEnd': + lastTestInfo = True + break + global lastTestInfo + if len(data) > len('\n') : + lastTestInfo = data + if not data: break + + soc.send('director end\r\n') + print 'test end and close socket.' + soc.close() #----------------autotest build and run----------------# def MAC_BUILD(): - def cleanProj(): - infoClean = os.system('xcodebuild -project ./build/cocos2d_tests.xcodeproj -target cpp-tests\ Mac clean') - print 'infoClean: ', infoClean - if infoClean != 0: - return False - time.sleep(sleep_time) - return True - def buildProj(): - infoBuild = os.system('xcodebuild -project ./build/cocos2d_tests.xcodeproj -target cpp-tests\ Mac') - print 'infoBuild: ', infoBuild - if infoBuild != 0: - return False - time.sleep(sleep_time) - return True - def openProj(): - cmd = 'open ./build/build/Debug/cpp-tests\ Mac.app' - print 'cmd: ', cmd - infoOpen = os.system(cmd) - print 'infoOpen: ', infoOpen - if infoOpen != 0: - return False - time.sleep(sleep_time) - return True - def buildAndRun(): - if not cleanProj(): - print '**CLEAN FAILED**' - if not buildProj(): - print '**BUILD FAILED**' - return False - if not openProj(): - return False - time.sleep(sleep_time) - return True - return buildAndRun() + def cleanProj(): + infoClean = os.system('xcodebuild -project ./build/cocos2d_tests.xcodeproj -target cpp-tests\ Mac clean') + print 'infoClean: ', infoClean + if infoClean != 0: + return False + time.sleep(sleep_time) + return True + def buildProj(): + infoBuild = os.system('xcodebuild -project ./build/cocos2d_tests.xcodeproj -target cpp-tests\ Mac') + print 'infoBuild: ', infoBuild + if infoBuild != 0: + return False + time.sleep(sleep_time) + return True + def openProj(): + cmd = 'open ./build/build/Debug/cpp-tests\ Mac.app' + print 'cmd: ', cmd + infoOpen = os.system(cmd) + print 'infoOpen: ', infoOpen + if infoOpen != 0: + return False + time.sleep(sleep_time) + return True + def buildAndRun(): + if not cleanProj(): + print '**CLEAN FAILED**' + if not buildProj(): + print '**BUILD FAILED**' + return False + if not openProj(): + return False + time.sleep(sleep_time) + return True + return buildAndRun() #----------------autotest build and run end----------------# PATH_ANDROID_SRC = 'tests/cpp-tests/proj.android/' FILE_ANDROID_DELETE = ['libs','gen','assets','bin','obj'] #----------------autotest-android build and run----------------# def ANDROID_BUILD(): - def checkDevice(): - cmd = 'adb devices' - infoDev = os.popen(cmd).readlines() - firstDev = infoDev[1] - if len(firstDev) < 5 or firstDev.find('device') < 0: - print 'no android device.' - return False - else: - print 'device info:', firstDev - return True - def cleanProj(): - for strFile in FILE_ANDROID_DELETE: - infoClean = os.system('rm -rf '+PATH_ANDROID_SRC+strFile) - infoClean = os.system('adb uninstall org.cocos2dx.cpp_tests'); - print 'infoClean: ', infoClean - if infoClean != 0: - print 'clean **CLEAN FAILED**' - time.sleep(sleep_time) - def updateProperty(): - infoUpdate = os.system('android update project -p ./cocos/platform/android/java/ -t 12') - print 'cocos update:', infoUpdate - infoUpdate = os.system('android update project -p '+PATH_ANDROID_SRC+' -t 12') - print 'test update:', infoUpdate - def buildProj(): - infoBuild = os.system('./build/android-build.py -p 13 cpp-tests') - print 'infoBuild cpp_tests: ', infoBuild - infoBuild = os.system('ant -buildfile '+PATH_ANDROID_SRC+' debug') - print 'infoBuild: ', infoBuild - if infoBuild != 0: - print 'build **BUILD FAILED**' - time.sleep(sleep_time) - return infoBuild - def installProj(): - cmd = 'adb install '+PATH_ANDROID_SRC+'bin/CppTests-debug.apk' - infoInstall = os.system(cmd) - print 'infoInstall:', infoInstall - if infoInstall != 0: - print 'install **INSTALL FAILED**' - return infoInstall - def openProj(): - cmd = 'adb shell am start -n org.cocos2dx.cpp_tests/org.cocos2dx.cpp_tests.Cocos2dxActivity' - print 'cmd: ', cmd - infoOpen = os.system(cmd) - print 'infoOpen: ', infoOpen - if infoOpen != 0: - return False - time.sleep(sleep_time) - return True - def buildAndRun(): - if not checkDevice(): - return False - cleanProj() - updateProperty() - buildProj() - installProj() - return openProj() - return buildAndRun() + def checkDevice(): + cmd = 'adb devices' + infoDev = os.popen(cmd).readlines() + firstDev = infoDev[1] + if len(firstDev) < 5 or firstDev.find('device') < 0: + print 'no android device.' + return False + else: + print 'device info:', firstDev + return True + def cleanProj(): + for strFile in FILE_ANDROID_DELETE: + infoClean = os.system('rm -rf '+PATH_ANDROID_SRC+strFile) + infoClean = os.system('adb uninstall org.cocos2dx.cpp_tests'); + print 'infoClean: ', infoClean + if infoClean != 0: + print 'clean **CLEAN FAILED**' + time.sleep(sleep_time) + def updateProperty(): + infoUpdate = os.system('android update project -p ./cocos/platform/android/java/ -t 12') + print 'cocos update:', infoUpdate + infoUpdate = os.system('android update project -p '+PATH_ANDROID_SRC+' -t 12') + print 'test update:', infoUpdate + def buildProj(): + infoBuild = os.system('./build/android-build.py -p 13 cpp-tests') + print 'infoBuild cpp_tests: ', infoBuild + infoBuild = os.system('ant -buildfile '+PATH_ANDROID_SRC+' debug') + print 'infoBuild: ', infoBuild + if infoBuild != 0: + print 'build **BUILD FAILED**' + time.sleep(sleep_time) + return infoBuild + def installProj(): + cmd = 'adb install '+PATH_ANDROID_SRC+'bin/CppTests-debug.apk' + infoInstall = os.system(cmd) + print 'infoInstall:', infoInstall + if infoInstall != 0: + print 'install **INSTALL FAILED**' + return infoInstall + def openProj(): + cmd = 'adb shell am start -n org.cocos2dx.cpp_tests/org.cocos2dx.cpp_tests.Cocos2dxActivity' + print 'cmd: ', cmd + infoOpen = os.system(cmd) + print 'infoOpen: ', infoOpen + if infoOpen != 0: + return False + time.sleep(sleep_time) + return True + def buildAndRun(): + if not checkDevice(): + return False + cleanProj() + updateProperty() + buildProj() + installProj() + return openProj() + return buildAndRun() #----------------autotest-android build and run end----------------# def main(): - print 'will build mac project.' - suc_build_mac = MAC_BUILD() - # print 'will build android project.' - # suc_build_android = ANDROID_BUILD() - if suc_build_mac: - autotest(TYPE_MAC) - if suc_build_android: - print 'will run android autotest.' - autotest(TYPE_ANDROID) + print 'will build mac project.' + suc_build_mac = MAC_BUILD() + # print 'will build android project.' + # suc_build_android = ANDROID_BUILD() + if suc_build_mac: + autotest(TYPE_MAC) + if suc_build_android: + print 'will run android autotest.' + autotest(TYPE_ANDROID) # -------------- main -------------- diff --git a/tools/jenkins-scripts/cocos-console-test.py b/tools/jenkins-scripts/cocos-console-test.py index 4623cdc83b..b76ec22444 100755 --- a/tools/jenkins-scripts/cocos-console-test.py +++ b/tools/jenkins-scripts/cocos-console-test.py @@ -20,10 +20,10 @@ from os.path import join, getsize console_param = '[console run]' # get param from commit. 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'] + 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(console_param)-1] print 'console_param:',console_param @@ -31,34 +31,34 @@ console_param_arr = console_param.split(' ') # enum command type class ENUM_PARAM: - new = 0 - compile = 1 - deploy = 2 - run = 3 + new = 0 + compile = 1 + deploy = 2 + run = 3 # partition different level LEVEL_COCOS = { - ENUM_PARAM.new : 1, - ENUM_PARAM.compile : 2, - ENUM_PARAM.deploy : 4, - ENUM_PARAM.run : 8 + ENUM_PARAM.new : 1, + ENUM_PARAM.compile : 2, + ENUM_PARAM.deploy : 4, + ENUM_PARAM.run : 8 } # level's cocos command COCOS_CMD = { - ENUM_PARAM.new:'new', - ENUM_PARAM.compile:'compile', - ENUM_PARAM.deploy:'deploy', - ENUM_PARAM.run:'run' + ENUM_PARAM.new:'new', + ENUM_PARAM.compile:'compile', + ENUM_PARAM.deploy:'deploy', + ENUM_PARAM.run:'run' } # set cocos_param for run different command cocos_param = 0 for level in LEVEL_COCOS: - if console_param_arr.count(COCOS_CMD[level]): - cocos_param = cocos_param + LEVEL_COCOS[level] + if console_param_arr.count(COCOS_CMD[level]): + cocos_param = cocos_param + LEVEL_COCOS[level] if cocos_param < LEVEL_COCOS[ENUM_PARAM.new]: - cocos_param = LEVEL_COCOS[ENUM_PARAM.new] + cocos_param = LEVEL_COCOS[ENUM_PARAM.new] print 'cocos_param:', cocos_param # project types @@ -73,109 +73,109 @@ cocos_console_dir = 'tools/cocos2d-console/bin/' # now cocos2d-console suport different run on Platforms, e.g: only run android on win runSupport = { - 'darwin' : {'mac':1,'ios':1,'android':1}, - 'win' : {'mac':0,'ios':0,'android':1}, - 'linux' : {'mac':0,'ios':0,'android':1} + 'darwin' : {'mac':1,'ios':1,'android':1}, + 'win' : {'mac':0,'ios':0,'android':1}, + 'linux' : {'mac':0,'ios':0,'android':1} } # get current running system curPlat = sys.platform if curPlat.find('linux') >= 0: - curPlat = 'linux' + curPlat = 'linux' elif curPlat.find('darwin') >= 0: - curPlat = 'darwin' + curPlat = 'darwin' else: - curPlat = 'win' + curPlat = 'win' print 'current platform is:', curPlat # delete project.(will use different system command to delete.just mac now.) def clean_project(): - print 'delete older project.' - for proj in project_types: - cmd = 'rm -rf '+proj+PROJ_SUFFIX - os.system(cmd) + print 'delete older project.' + for proj in project_types: + cmd = 'rm -rf '+proj+PROJ_SUFFIX + os.system(cmd) # file path.(for add console listen command.) FILE_PATH = '/Classes/AppDelegate.cpp' FILE_DIR = { - 'cpp':'', - 'lua':'/frameworks/runtime-src' + 'cpp':'', + 'lua':'/frameworks/runtime-src' } PARSE_WORD = 'director->setDisplayStats(true);' CONSOLE_COMMAND = 'director->getConsole()->listenOnTCP(5678);' # add console listenOnTCP to AppDelegate.cpp. def addConsoleListenOnTCP(name): - filePath = name+PROJ_SUFFIX+FILE_DIR[name]+FILE_PATH - print 'filePath:',filePath - strCont = '' - if os.path.isfile(filePath): - file_object = open(filePath, 'r') - strLine = file_object.readline() - while strLine: - strCont = strCont + strLine - if strLine.find(PARSE_WORD) > -1: - print 'add console listenOnTCP command.' - strCont = strCont+'\n\t' + CONSOLE_COMMAND + '\n' - strLine = file_object.readline() - - file_object.close() - file_object = open(filePath, 'w') - file_object.write(strCont) - file_object.close() - time.sleep(2) - else: - print 'file is not exist.' + filePath = name+PROJ_SUFFIX+FILE_DIR[name]+FILE_PATH + print 'filePath:',filePath + strCont = '' + if os.path.isfile(filePath): + file_object = open(filePath, 'r') + strLine = file_object.readline() + while strLine: + strCont = strCont + strLine + if strLine.find(PARSE_WORD) > -1: + print 'add console listenOnTCP command.' + strCont = strCont+'\n\t' + CONSOLE_COMMAND + '\n' + strLine = file_object.readline() + + file_object.close() + file_object = open(filePath, 'w') + file_object.write(strCont) + file_object.close() + time.sleep(2) + else: + print 'file is not exist.' # console result, for record result console_result = 'the result of cocos-console-test is:\n\r' # get current android devices count. def getAndroidDevices(): - cmd = 'adb devices' - info_devices = os.popen(cmd).read() - arrDevices = info_devices.split('\n') - del arrDevices[0] - count = 0 - for device in arrDevices: - # e.g: emulator-5554 device, contains 'device', so, min length is len('device') - if len(device) > len('device') and (device.find('device') >= 0): - count += 1 - return count + cmd = 'adb devices' + info_devices = os.popen(cmd).read() + arrDevices = info_devices.split('\n') + del arrDevices[0] + count = 0 + for device in arrDevices: + # e.g: emulator-5554 device, contains 'device', so, min length is len('device') + if len(device) > len('device') and (device.find('device') >= 0): + count += 1 + return count # close running app or exe by using console command. IP_PHONE = { - 'mac':'localhost', - 'ios':'localhost' + 'mac':'localhost', + 'ios':'localhost' } PORT = 5678 def close_proj(proj, phone): - print 'close running project' - # connect socket - strClose = 'close ' + proj + ' on ' + phone - if IP_PHONE.has_key(phone): - soc = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) - print proj, phone, IP_PHONE[phone] - try: - soc.connect((IP_PHONE[phone], PORT)) - cmd = 'director end\r\n' - print 'cmd close:', cmd - soc.send(cmd) - time.sleep(2) - strClose = strClose + ' success.' - except Exception, e: - print 'socket is not connect.' - strClose = strClose + ' failed.' + ' socket is not connect.' - else: - strClose = strClose + ' failed.' + ' no ' +phone+ ' type.' - time.sleep(2) - return strClose + print 'close running project' + # connect socket + strClose = 'close ' + proj + ' on ' + phone + if IP_PHONE.has_key(phone): + soc = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) + print proj, phone, IP_PHONE[phone] + try: + soc.connect((IP_PHONE[phone], PORT)) + cmd = 'director end\r\n' + print 'cmd close:', cmd + soc.send(cmd) + time.sleep(2) + strClose = strClose + ' success.' + except Exception, e: + print 'socket is not connect.' + strClose = strClose + ' failed.' + ' socket is not connect.' + else: + strClose = strClose + ' failed.' + ' no ' +phone+ ' type.' + time.sleep(2) + return strClose # appendToResult def appendToResult(content): - global console_result - console_result = console_result + content + global console_result + console_result = console_result + content info_of_close_app = {} cur_test_name = '' @@ -186,194 +186,194 @@ class myThread(threading.Thread): run_name = self.getName() print 'run_name:', run_name if run_name == 'close': - while True: - soc = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) - try: - soc.connect(('localhost', PORT)) - cmd_close = 'director end\r\n' - print 'cmd close:', cmd_close - soc.send(cmd_close) - time.sleep(2) - global cur_test_name - print 'cur_test_name:', cur_test_name - info_of_close_app[cur_test_name] = True - break - except Exception, e: - time.sleep(5) + while True: + soc = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) + try: + soc.connect(('localhost', PORT)) + cmd_close = 'director end\r\n' + print 'cmd close:', cmd_close + soc.send(cmd_close) + time.sleep(2) + global cur_test_name + print 'cur_test_name:', cur_test_name + info_of_close_app[cur_test_name] = True + break + except Exception, e: + time.sleep(5) # if any error ANY_ERROR_IN_RUN = 0 # excute cocos command def cocos_project(level): - global ANY_ERROR_IN_RUN - print 'will excute cocos_command: ', COCOS_CMD[level], level - appendToResult('will excute ' + COCOS_CMD[level] + ' command:'+"\n\r\t") - for proj in project_types: - print 'proj: ', proj - if level == ENUM_PARAM.new: - cmd = './'+cocos_console_dir+'cocos new -l '+proj+' '+proj+PROJ_SUFFIX - print proj,'cmd:',cmd - info_create = os.system(cmd) #call cmd on win is diff - if info_create == 0: - time.sleep(12) - addConsoleListenOnTCP(proj) - print 'create project',proj,' is:', not info_create - ANY_ERROR_IN_RUN = ANY_ERROR_IN_RUN + info_create - appendToResult(' '+cmd +': ' + str(not info_create) + ".\n\r\t") - else: - for phone in phonePlats: - print 'platform is: ', phone - cmd = './'+cocos_console_dir+'cocos '+COCOS_CMD[level]+' -s '+proj+PROJ_SUFFIX+' -p '+phone - print 'cmd:',cmd - info_cmd = '' - if level == ENUM_PARAM.compile: - if runSupport[curPlat][phone]: - info_cmd = os.system(cmd) - print 'info '+COCOS_CMD[level]+':', not info_cmd - appendToResult(' '+cmd +': ' + str(not info_cmd) + ".\n\r\t") - else: - if runSupport[curPlat][phone]: - print 'in desploy or run:', phone, getAndroidDevices() - if phone == 'android' and getAndroidDevices() == 0: - strInfo = 'no android device, please checkout the device is running ok.' - print strInfo - else: - if level == ENUM_PARAM.run: - global cur_test_name - cur_test_name = proj+','+phone - thread_close = myThread('close') - thread_close.start() - info_cmd = os.system(cmd) - time.sleep(5) - appendToResult(' '+cmd +': ' + str(not info_cmd) + ".\n\r\t") + global ANY_ERROR_IN_RUN + print 'will excute cocos_command: ', COCOS_CMD[level], level + appendToResult('will excute ' + COCOS_CMD[level] + ' command:'+"\n\r\t") + for proj in project_types: + print 'proj: ', proj + if level == ENUM_PARAM.new: + cmd = './'+cocos_console_dir+'cocos new -l '+proj+' '+proj+PROJ_SUFFIX + print proj,'cmd:',cmd + info_create = os.system(cmd) #call cmd on win is diff + if info_create == 0: + time.sleep(12) + addConsoleListenOnTCP(proj) + print 'create project',proj,' is:', not info_create + ANY_ERROR_IN_RUN = ANY_ERROR_IN_RUN + info_create + appendToResult(' '+cmd +': ' + str(not info_create) + ".\n\r\t") + else: + for phone in phonePlats: + print 'platform is: ', phone + cmd = './'+cocos_console_dir+'cocos '+COCOS_CMD[level]+' -s '+proj+PROJ_SUFFIX+' -p '+phone + print 'cmd:',cmd + info_cmd = '' + if level == ENUM_PARAM.compile: + if runSupport[curPlat][phone]: + info_cmd = os.system(cmd) + print 'info '+COCOS_CMD[level]+':', not info_cmd + appendToResult(' '+cmd +': ' + str(not info_cmd) + ".\n\r\t") + else: + if runSupport[curPlat][phone]: + print 'in desploy or run:', phone, getAndroidDevices() + if phone == 'android' and getAndroidDevices() == 0: + strInfo = 'no android device, please checkout the device is running ok.' + print strInfo + else: + if level == ENUM_PARAM.run: + global cur_test_name + cur_test_name = proj+','+phone + thread_close = myThread('close') + thread_close.start() + info_cmd = os.system(cmd) + time.sleep(5) + appendToResult(' '+cmd +': ' + str(not info_cmd) + ".\n\r\t") # build and run according to params of provided.(lv_ignore: e.g:ignore new) def build_run(lv_ignore): - print 'will build and run, in function build_run' - for level in LEVEL_COCOS: - print 'level:', level, cocos_param, LEVEL_COCOS[level] - if cocos_param >= LEVEL_COCOS[level] and level > lv_ignore: - if level == ENUM_PARAM.new: - clean_project() - cocos_project(level) + print 'will build and run, in function build_run' + for level in LEVEL_COCOS: + print 'level:', level, cocos_param, LEVEL_COCOS[level] + if cocos_param >= LEVEL_COCOS[level] and level > lv_ignore: + if level == ENUM_PARAM.new: + clean_project() + cocos_project(level) # android simulator name. ANDROID_SIMULATOR_NAME = 'console-test' # start android simulator if no android devices connected. def start_android_simulator(): - print 'in function start_android_simulator.' - if getAndroidDevices() > 0: - print 'already connected android device.' - return - if cocos_param >= LEVEL_COCOS[ENUM_PARAM.deploy]: - cmd_start = [ 'emulator -avd '+ANDROID_SIMULATOR_NAME ] - # print 'cmd_start:', cmd_start - # info_start = subprocess.Popen(cmd_start, stdin=subprocess.PIPE, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - # print 'start an android simulator:', not info_start + print 'in function start_android_simulator.' + if getAndroidDevices() > 0: + print 'already connected android device.' + return + if cocos_param >= LEVEL_COCOS[ENUM_PARAM.deploy]: + cmd_start = [ 'emulator -avd '+ANDROID_SIMULATOR_NAME ] + # print 'cmd_start:', cmd_start + # info_start = subprocess.Popen(cmd_start, stdin=subprocess.PIPE, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + # print 'start an android simulator:', not info_start # send email EMAIL_KEYS={ - 0:'EMAIL_HOST', - 1:'EMAIL_USER', - 2:'EMAIL_PWD', - 3:'EMAIL_POSTFIX', - 4:'EMAIL_LIST', - 5:'NEED_SEND_EMAIL' + 0:'EMAIL_HOST', + 1:'EMAIL_USER', + 2:'EMAIL_PWD', + 3:'EMAIL_POSTFIX', + 4:'EMAIL_LIST', + 5:'NEED_SEND_EMAIL' } OBJ_EMAIL_INFO = {} print 'will get env info.' for key in EMAIL_KEYS: - if os.environ.has_key(EMAIL_KEYS[key]): - OBJ_EMAIL_INFO[EMAIL_KEYS[key]] = os.environ[EMAIL_KEYS[key]] - if key == 4: - # string to list by ' ', for separate users. - OBJ_EMAIL_INFO[EMAIL_KEYS[4]] = OBJ_EMAIL_INFO[EMAIL_KEYS[4]].split(' ') + if os.environ.has_key(EMAIL_KEYS[key]): + OBJ_EMAIL_INFO[EMAIL_KEYS[key]] = os.environ[EMAIL_KEYS[key]] + if key == 4: + # string to list by ' ', for separate users. + OBJ_EMAIL_INFO[EMAIL_KEYS[4]] = OBJ_EMAIL_INFO[EMAIL_KEYS[4]].split(' ') print 'will send email.', OBJ_EMAIL_INFO def send_mail(to_list,sub,title,content): - mail_user = OBJ_EMAIL_INFO[ EMAIL_KEYS[1] ] - mail_postfix = OBJ_EMAIL_INFO[ EMAIL_KEYS[3] ] - mail_host = OBJ_EMAIL_INFO[ EMAIL_KEYS[0] ] - mail_pass = OBJ_EMAIL_INFO[ EMAIL_KEYS[2] ] - me = mail_user+"<"+mail_user+"@"+mail_postfix+">" - msg = MIMEText(content,_subtype='plain',_charset='gb2312') - msg['Subject'] = sub - msg['From'] = me - msg['To'] = " ".join(to_list) - print 'to users:', msg['To'] - msg['Content'] = 'test' - try: - s = smtplib.SMTP() - s.connect(mail_host) - s.login(mail_user,mail_pass) - s.sendmail(me, to_list, str(msg)) - print 'info:', me, to_list, str(msg) - s.close() - appendToResult( 'send email true:' + str(msg) ) - return True - except Exception, e: - appendToResult( 'send email false:' + str(e) ) + mail_user = OBJ_EMAIL_INFO[ EMAIL_KEYS[1] ] + mail_postfix = OBJ_EMAIL_INFO[ EMAIL_KEYS[3] ] + mail_host = OBJ_EMAIL_INFO[ EMAIL_KEYS[0] ] + mail_pass = OBJ_EMAIL_INFO[ EMAIL_KEYS[2] ] + me = mail_user+"<"+mail_user+"@"+mail_postfix+">" + msg = MIMEText(content,_subtype='plain',_charset='gb2312') + msg['Subject'] = sub + msg['From'] = me + msg['To'] = " ".join(to_list) + print 'to users:', msg['To'] + msg['Content'] = 'test' + try: + s = smtplib.SMTP() + s.connect(mail_host) + s.login(mail_user,mail_pass) + s.sendmail(me, to_list, str(msg)) + print 'info:', me, to_list, str(msg) + s.close() + appendToResult( 'send email true:' + str(msg) ) + return True + except Exception, e: + appendToResult( 'send email false:' + str(e) ) print str(e) return False def sendEmail(msg): - send_mail(OBJ_EMAIL_INFO[EMAIL_KEYS[4]], "cocos-console-test result", 'for error.', msg) + send_mail(OBJ_EMAIL_INFO[EMAIL_KEYS[4]], "cocos-console-test result", 'for error.', msg) # get package size def getdirsize(dir): - size = 0L - for root, dirs, files in os.walk(dir): - size += sum([getsize(join(root, name)) for name in files]) - return size + size = 0L + for root, dirs, files in os.walk(dir): + size += sum([getsize(join(root, name)) for name in files]) + return size APP_FILE_DIR = { - 'cpp':'bin/debug/', - 'lua':'runtime/' + 'cpp':'bin/debug/', + 'lua':'runtime/' } APP_FILE_SUFFIX = { - 'mac':'.app', - 'ios':'.app', - 'android':'-debug-unaligned.apk' + 'mac':'.app', + 'ios':'.app', + 'android':'-debug-unaligned.apk' } if os.environ.has_key('APP_FILE_SUFFIX'): - str_app_suffix = os.environ['APP_FILE_SUFFIX'] - APP_FILE_SUFFIX = eval(str_app_suffix) + str_app_suffix = os.environ['APP_FILE_SUFFIX'] + APP_FILE_SUFFIX = eval(str_app_suffix) def getPackageSize(): - for proj in project_types: - for phone in phonePlats: - # if runSupport[curPlat][phone]: - package_path = './'+proj+PROJ_SUFFIX+'/'+APP_FILE_DIR[proj]+phone+'/'+proj+PROJ_SUFFIX+APP_FILE_SUFFIX[phone] - print 'package_path', package_path - package_size = 0 - if os.path.isfile(package_path): - package_size = os.path.getsize(package_path); - else: - package_size = getdirsize(package_path); - strSize = 'size of '+proj+PROJ_SUFFIX+' '+phone+' is:'+str(package_size/(1024))+'KB'+'\n\t' - print 'strSize:', strSize - appendToResult(strSize) + for proj in project_types: + for phone in phonePlats: + # if runSupport[curPlat][phone]: + package_path = './'+proj+PROJ_SUFFIX+'/'+APP_FILE_DIR[proj]+phone+'/'+proj+PROJ_SUFFIX+APP_FILE_SUFFIX[phone] + print 'package_path', package_path + package_size = 0 + if os.path.isfile(package_path): + package_size = os.path.getsize(package_path); + else: + package_size = getdirsize(package_path); + strSize = 'size of '+proj+PROJ_SUFFIX+' '+phone+' is:'+str(package_size/(1024))+'KB'+'\n\t' + print 'strSize:', strSize + appendToResult(strSize) def main(): - print 'in main:' - # start_android_simulator() - print 'will build_run:' - build_run(-1) - print 'ANY_ERROR_IN_RUN:', ANY_ERROR_IN_RUN - print 'end build run. and get package size.' - getPackageSize() - print 'will send email:' - print 'console_result:', console_result - if OBJ_EMAIL_INFO[ EMAIL_KEYS[5] ] or ANY_ERROR_IN_RUN: - sendEmail(console_result) + print 'in main:' + # start_android_simulator() + print 'will build_run:' + build_run(-1) + print 'ANY_ERROR_IN_RUN:', ANY_ERROR_IN_RUN + print 'end build run. and get package size.' + getPackageSize() + print 'will send email:' + print 'console_result:', console_result + if OBJ_EMAIL_INFO[ EMAIL_KEYS[5] ] or ANY_ERROR_IN_RUN: + sendEmail(console_result) # -------------- main -------------- if __name__ == '__main__': sys_ret = 0 try: - sys_ret = main() + sys_ret = main() except: - traceback.print_exc() - sys_ret = 1 + traceback.print_exc() + sys_ret = 1 finally: - sys.exit(sys_ret) + sys.exit(sys_ret) diff --git a/tools/jenkins-scripts/configs/autotest.py b/tools/jenkins-scripts/configs/autotest.py index 5e6a6098a8..ea57782db7 100644 --- a/tools/jenkins-scripts/configs/autotest.py +++ b/tools/jenkins-scripts/configs/autotest.py @@ -6,5 +6,5 @@ ret = os.system('python -u tools/jenkins-scripts/autotest.py') os.system('git reset --hard') print ret if(ret > 0): - ret = 1 + ret = 1 exit(ret) diff --git a/tools/jenkins-scripts/configs/cocos-2dx-develop-android.py b/tools/jenkins-scripts/configs/cocos-2dx-develop-android.py index e632c330c5..60bdd4a173 100644 --- a/tools/jenkins-scripts/configs/cocos-2dx-develop-android.py +++ b/tools/jenkins-scripts/configs/cocos-2dx-develop-android.py @@ -5,10 +5,10 @@ print ' Branch:develop' print ' Target:Android' print ' build script:python build/android-build.py all' if(os.path.exists('build/android-build.py') == False): - node_name = os.environ['NODE_NAME'] - source_dir = '../cocos-2dx-develop-base-repo/node/' + node_name + "/." - os.system("cp -r" + source_dir + " .") - os.system('git pull origin develop') + node_name = os.environ['NODE_NAME'] + source_dir = '../cocos-2dx-develop-base-repo/node/' + node_name + "/." + os.system("cp -r" + source_dir + " .") + os.system('git pull origin develop') os.system('git submodule update --init --force') ret = os.system('python build/android-build.py -n -j8 all') @@ -16,6 +16,6 @@ os.system('git clean -xdf -f') print 'build exit' print ret if ret == 0: - exit(0) + exit(0) else: - exit(1) + exit(1) diff --git a/tools/jenkins-scripts/configs/cocos-2dx-develop-base-repo.py b/tools/jenkins-scripts/configs/cocos-2dx-develop-base-repo.py index f70b31d568..c7cd0f2fd3 100644 --- a/tools/jenkins-scripts/configs/cocos-2dx-develop-base-repo.py +++ b/tools/jenkins-scripts/configs/cocos-2dx-develop-base-repo.py @@ -2,20 +2,20 @@ import os import sys def check_ret(ret): - if(ret != 0): - os.system('git checkout -B develop remotes/origin/develop') - os.system('git clean -xdf -f') - sys.exit(1) + if(ret != 0): + os.system('git checkout -B develop remotes/origin/develop') + os.system('git clean -xdf -f') + sys.exit(1) branchs = ['develop', 'master'] for item in branchs: - os.system('git clean -xdf -f') - os.system('git checkout -B ' + item + ' remotes/origin/' + item) - os.system('git clean -xdf -f') - ret = os.system('git pull origin') - check_ret(ret) - ret = os.system('git submodule update --init --force') - check_ret(ret) + os.system('git clean -xdf -f') + os.system('git checkout -B ' + item + ' remotes/origin/' + item) + os.system('git clean -xdf -f') + ret = os.system('git pull origin') + check_ret(ret) + ret = os.system('git submodule update --init --force') + check_ret(ret) #back to develop os.system('git checkout -B develop remotes/origin/develop') diff --git a/tools/jenkins-scripts/configs/cocos-2dx-develop-ios.py b/tools/jenkins-scripts/configs/cocos-2dx-develop-ios.py index 7a0c672f47..0dedd56b3c 100644 --- a/tools/jenkins-scripts/configs/cocos-2dx-develop-ios.py +++ b/tools/jenkins-scripts/configs/cocos-2dx-develop-ios.py @@ -4,10 +4,10 @@ print ' Host:MAC' print ' Branch:develop' print ' Target:iOS' if(os.path.exists('tools/jenkins-scripts/ios-build.sh') == False): - node_name = os.environ['NODE_NAME'] - source_dir = '../cocos-2dx-develop-base-repo/node/' + node_name + "/." - os.system("cp -r " + source_dir + " .") - os.system('git pull origin develop') + node_name = os.environ['NODE_NAME'] + source_dir = '../cocos-2dx-develop-base-repo/node/' + node_name + "/." + os.system("cp -r " + source_dir + " .") + os.system('git pull origin develop') os.system('git submodule update --init --force') ret = os.system('tools/jenkins-scripts/ios-build.sh') @@ -15,6 +15,6 @@ os.system('git clean -xdf -f') print 'build exit' print ret if ret == 0: - exit(0) + exit(0) else: - exit(1) + exit(1) diff --git a/tools/jenkins-scripts/configs/cocos-2dx-develop-win32.py b/tools/jenkins-scripts/configs/cocos-2dx-develop-win32.py index 801874494e..1e55080898 100644 --- a/tools/jenkins-scripts/configs/cocos-2dx-develop-win32.py +++ b/tools/jenkins-scripts/configs/cocos-2dx-develop-win32.py @@ -7,11 +7,11 @@ print ' Branch:develop' print ' Target:win32' print ' "%VS110COMNTOOLS%..\IDE\devenv.com" "build\cocos2d-win32.vc2012.sln" /Build "Debug|Win32"' if(os.path.exists('build/cocos2d-win32.vc2012.sln') == False): - node_name = os.environ['NODE_NAME'] - source_dir = '../cocos-2dx-develop-base-repo/node/' + node_name - source_dir = source_dir.replace("/", os.sep) - os.system("xcopy " + source_dir + " . /E /Y /H") - os.system('git pull origin develop') + node_name = os.environ['NODE_NAME'] + source_dir = '../cocos-2dx-develop-base-repo/node/' + node_name + source_dir = source_dir.replace("/", os.sep) + os.system("xcopy " + source_dir + " . /E /Y /H") + os.system('git pull origin develop') os.system('git submodule update --init --force') ret = subprocess.call('"%VS110COMNTOOLS%..\IDE\devenv.com" "build\cocos2d-win32.vc2012.sln" /Build "Debug|Win32"', shell=True) @@ -19,6 +19,6 @@ os.system('git clean -xdf -f') print 'build exit' print ret if ret == 0: - exit(0) + exit(0) else: - exit(1) + exit(1) diff --git a/tools/jenkins-scripts/configs/cocos-2dx-doxygen.py b/tools/jenkins-scripts/configs/cocos-2dx-doxygen.py index 4367230caf..2dadb80233 100644 --- a/tools/jenkins-scripts/configs/cocos-2dx-doxygen.py +++ b/tools/jenkins-scripts/configs/cocos-2dx-doxygen.py @@ -5,11 +5,11 @@ print ' Branch:develop' print ' Target:Doxygen' print ' doxygen doxygen.config' if(os.path.exists('docs/doxygen.config') == False): - node_name = os.environ['NODE_NAME'] - source_dir = '../cocos-2dx-develop-base-repo/node/' + node_name - source_dir = source_dir.replace("/", os.sep) - os.system("xcopy " + source_dir + " . /E /Y /H") - os.system('git pull origin develop') + node_name = os.environ['NODE_NAME'] + source_dir = '../cocos-2dx-develop-base-repo/node/' + node_name + source_dir = source_dir.replace("/", os.sep) + os.system("xcopy " + source_dir + " . /E /Y /H") + os.system('git pull origin develop') os.system('git submodule update --init --force') os.chdir('docs/') @@ -19,6 +19,6 @@ os.system('git clean -xdf -f') print 'build exit' print ret if ret == 0: - exit(0) + exit(0) else: - exit(1) + exit(1) diff --git a/tools/jenkins-scripts/configs/cocos-2dx-pull-request-build-comment-trigger.py b/tools/jenkins-scripts/configs/cocos-2dx-pull-request-build-comment-trigger.py index e7817809c5..3cc1053ce3 100644 --- a/tools/jenkins-scripts/configs/cocos-2dx-pull-request-build-comment-trigger.py +++ b/tools/jenkins-scripts/configs/cocos-2dx-pull-request-build-comment-trigger.py @@ -3,6 +3,6 @@ import os #os.system('git pull origin develop') ret = os.system('python -u tools/jenkins-scripts/job-comment-trigger.py') if ret == 0: - exit(0) + exit(0) else: - exit(1) + exit(1) diff --git a/tools/jenkins-scripts/configs/cocos-2dx-pull-request-build-trigger.py b/tools/jenkins-scripts/configs/cocos-2dx-pull-request-build-trigger.py index 60c79ddc94..fcdca42b38 100644 --- a/tools/jenkins-scripts/configs/cocos-2dx-pull-request-build-trigger.py +++ b/tools/jenkins-scripts/configs/cocos-2dx-pull-request-build-trigger.py @@ -3,6 +3,6 @@ import os #os.system('git pull origin develop') ret = os.system('python -u tools/jenkins-scripts/job-trigger.py') if ret == 0: - exit(0) + exit(0) else: - exit(1) + exit(1) diff --git a/tools/jenkins-scripts/configs/cocos-2dx-pull-request-build.py b/tools/jenkins-scripts/configs/cocos-2dx-pull-request-build.py index a09fdf2b79..6783e89cb9 100644 --- a/tools/jenkins-scripts/configs/cocos-2dx-pull-request-build.py +++ b/tools/jenkins-scripts/configs/cocos-2dx-pull-request-build.py @@ -1,17 +1,17 @@ import os import platform if(os.path.exists('tools/jenkins-scripts/pull-request-builder.py') == False): - node_name = os.environ['NODE_NAME'] - source_dir = '../../../cocos-2dx-develop-base-repo/node/' + node_name - if(platform.system() == 'Windows'): - source_dir = source_dir.replace("/", os.sep) - os.system("xcopy " + source_dir + ' . /E /Y /H') - else: - os.system("cp -r " + source_dir + "/. .") + node_name = os.environ['NODE_NAME'] + source_dir = '../../../cocos-2dx-develop-base-repo/node/' + node_name + if(platform.system() == 'Windows'): + source_dir = source_dir.replace("/", os.sep) + os.system("xcopy " + source_dir + ' . /E /Y /H') + else: + os.system("cp -r " + source_dir + "/. .") def clean_workspace(): - os.system('git reset --hard') - os.system('git clean -xdf -f') + os.system('git reset --hard') + os.system('git clean -xdf -f') clean_workspace() os.system('git checkout develop') @@ -19,14 +19,14 @@ clean_workspace() os.system('git pull origin develop') for i in range(0, 3): - ret = os.system('python -u tools/jenkins-scripts/pull-request-builder.py') - if(ret > 255): - ret >>= 8 - if(ret == 0) or (ret == 1): - break + ret = os.system('python -u tools/jenkins-scripts/pull-request-builder.py') + if(ret > 255): + ret >>= 8 + if(ret == 0) or (ret == 1): + break clean_workspace() print ret if(ret > 0): - ret = 1 + ret = 1 exit(ret) diff --git a/tools/jenkins-scripts/configs/cocos2d-console-test.py b/tools/jenkins-scripts/configs/cocos2d-console-test.py index 26a2492a2f..9e58f9f1ec 100644 --- a/tools/jenkins-scripts/configs/cocos2d-console-test.py +++ b/tools/jenkins-scripts/configs/cocos2d-console-test.py @@ -8,5 +8,5 @@ ret = os.system('python -u tools/jenkins-scripts/cocos-console-test.py') os.system('git reset --hard') print ret if(ret > 0): - ret = 1 + ret = 1 exit(ret) diff --git a/tools/jenkins-scripts/configs/cocostudiox-base-repo.py b/tools/jenkins-scripts/configs/cocostudiox-base-repo.py index 91aeb02ee0..8c264bc7df 100644 --- a/tools/jenkins-scripts/configs/cocostudiox-base-repo.py +++ b/tools/jenkins-scripts/configs/cocostudiox-base-repo.py @@ -2,7 +2,7 @@ import os import sys ret = os.system('git pull origin master') if(ret != 0): - sys.exit(1) + sys.exit(1) ret = os.system('git submodule update --init --force') if(ret != 0): - sys.exit(1) + sys.exit(1) diff --git a/tools/jenkins-scripts/configs/cocostudiox-daily-build.py b/tools/jenkins-scripts/configs/cocostudiox-daily-build.py index 00cf754f82..b7f0e04a5c 100644 --- a/tools/jenkins-scripts/configs/cocostudiox-daily-build.py +++ b/tools/jenkins-scripts/configs/cocostudiox-daily-build.py @@ -1,13 +1,13 @@ import os import platform if(os.path.exists('CocoStudio/CSX/CSX/CSX.pro') == False): - node_name = os.environ['NODE_NAME'] - source_dir = '../../../cocostudiox-base-repo/node/' + node_name - if(platform.system() == 'Windows'): - source_dir = source_dir.replace("/", os.sep) - os.system("xcopy " + source_dir + ' . /E /Y /H') - else: - os.system("cp -r " + source_dir + "/. .") + node_name = os.environ['NODE_NAME'] + source_dir = '../../../cocostudiox-base-repo/node/' + node_name + if(platform.system() == 'Windows'): + source_dir = source_dir.replace("/", os.sep) + os.system("xcopy " + source_dir + ' . /E /Y /H') + else: + os.system("cp -r " + source_dir + "/. .") os.system('git pull origin') os.system('git submodule update --init --force') @@ -16,15 +16,15 @@ node_name = os.environ['NODE_NAME'] os.chdir('CocoStudio/CSX/CSX') ret = os.system('qmake -r') if(ret == 0): - if(node_name == 'android_mac'): - ret = os.system('make -j8') - elif(node_name == 'win32_win7'): - ret = os.system('mingw32-make -j8') + if(node_name == 'android_mac'): + ret = os.system('make -j8') + elif(node_name == 'win32_win7'): + ret = os.system('mingw32-make -j8') os.chdir('../../..') os.system('git clean -xdf') os.system('git reset --hard') print ret if(ret > 0): - ret = 1 + ret = 1 exit(ret) diff --git a/tools/jenkins-scripts/emptytest.py b/tools/jenkins-scripts/emptytest.py index d5cc7e3f9a..86d671981a 100644 --- a/tools/jenkins-scripts/emptytest.py +++ b/tools/jenkins-scripts/emptytest.py @@ -19,290 +19,290 @@ import paramiko payload = {} #get payload from os env if os.environ.has_key('payload'): - payload_str = os.environ['payload'] - #parse to json obj - payload = json.loads(payload_str) + payload_str = os.environ['payload'] + #parse to json obj + payload = json.loads(payload_str) print 'payload:',payload pr_num = 6326 #get pull number if payload.has_key('number'): - pr_num = payload['number'] + pr_num = payload['number'] print 'pr_num:' + str(pr_num) run_app_time = 5 if os.environ.has_key('RUN_APP_TIME'): - run_app_time = os.environ['RUN_APP_TIME'] + run_app_time = os.environ['RUN_APP_TIME'] print 'run_app_time:', run_app_time test_name = ['cpp_empty_test'] if os.environ.has_key('TESTS_NAME'): - temp_var = os.environ['TESTS_NAME'] - test_name = temp_var.split(', ') + temp_var = os.environ['TESTS_NAME'] + test_name = temp_var.split(', ') package_name = ['org.cocos2dx.cpp_empty_test'] if os.environ.has_key('PACKAGE_NAME'): - temp_var = os.environ['PACKAGE_NAME'] - package_name = temp_var.split(', ') + temp_var = os.environ['PACKAGE_NAME'] + package_name = temp_var.split(', ') activity_name = ['org.cocos2dx.cpp_empty_test.AppActivity'] if os.environ.has_key('ACTIVITY_NAME'): - temp_var = os.environ['ACTIVITY_NAME'] - activity_name = temp_var.split(', ') + temp_var = os.environ['ACTIVITY_NAME'] + activity_name = temp_var.split(', ') gIdx = 0 if os.environ.has_key('TEST_INDEX'): - gIdx = os.environ('TEST_INDEX') + gIdx = os.environ('TEST_INDEX') current_platform = platform.system() print 'current platform is:', current_platform arrDevices = [] def getDevices(): - cmd = 'adb devices' - info_devices = os.popen(cmd).read() - arr_info = info_devices.split('\n') - del arr_info[0] - count = 0 - for device in arr_info: - if len(device) > 0: - count += 1 - print 'device ', count,device - deviceInfo = device.split(' ') - global arrDevices - obj = {} - obj['name'] = deviceInfo[0] - arrDevices.append(obj) - return count + cmd = 'adb devices' + info_devices = os.popen(cmd).read() + arr_info = info_devices.split('\n') + del arr_info[0] + count = 0 + for device in arr_info: + if len(device) > 0: + count += 1 + print 'device ', count,device + deviceInfo = device.split(' ') + global arrDevices + obj = {} + obj['name'] = deviceInfo[0] + arrDevices.append(obj) + return count def getADBDeviceIP(device_name): - output = os.popen("adb -s "+device_name+" shell netcfg") - configs = output.read().split('\r\n') - output.close() - for l in configs: - items = l.split() - if len(items)>1 and items[1] == 'UP': - if items[2].find('127.0.0.1') < 0 and items[2].find('0.0.0.0') < 0: - return items[2] - return False + output = os.popen("adb -s "+device_name+" shell netcfg") + configs = output.read().split('\r\n') + output.close() + for l in configs: + items = l.split() + if len(items)>1 and items[1] == 'UP': + if items[2].find('127.0.0.1') < 0 and items[2].find('0.0.0.0') < 0: + return items[2] + return False def mapIP(): - for device in arrDevices: - ip_d = getADBDeviceIP(device['name']) - device['ip'] = ip_d + for device in arrDevices: + ip_d = getADBDeviceIP(device['name']) + device['ip'] = ip_d allThreadIsRunning = {} def setThreadStatus(): - for device in arrDevices: - allThreadIsRunning[device['name']] = 1 + for device in arrDevices: + allThreadIsRunning[device['name']] = 1 devices_info = {} info_list = '{"product":["model","brand","name","cpu.abi","cpu.abi2","manufacturer","locale.language","locale.region"],"build":["id","version.sdk","version.release"]}' if os.environ.has_key('DEVICE_INFO_LIST'): - info_list = os.environ['DEVICE_INFO_LIST'] + info_list = os.environ['DEVICE_INFO_LIST'] info_list = eval(info_list) def getDeviceInfoByName(name): - cmd = '' - dev_name = name - if len(name) > 0: - cmd = 'adb -s '+name+' shell cat /system/build.prop' - else: - cmd = 'adb shell cat /system/build.prop' - dev_name = 'device one' - pip_cat = os.popen(cmd) - read_info = pip_cat.read() - read_info_list = read_info.split('\r\n') - device_info_one = {} - def checkProperty(item_str, device_name): - for argv in info_list: - for item in info_list[argv]: - prop = argv+'.'+item - if item_str.find(prop) > -1: - arr_item = item_str.split('=') - device_info_one[prop] = arr_item[1] - break - for item in read_info_list: - checkProperty(item, dev_name) - devices_info[dev_name] = device_info_one + cmd = '' + dev_name = name + if len(name) > 0: + cmd = 'adb -s '+name+' shell cat /system/build.prop' + else: + cmd = 'adb shell cat /system/build.prop' + dev_name = 'device one' + pip_cat = os.popen(cmd) + read_info = pip_cat.read() + read_info_list = read_info.split('\r\n') + device_info_one = {} + def checkProperty(item_str, device_name): + for argv in info_list: + for item in info_list[argv]: + prop = argv+'.'+item + if item_str.find(prop) > -1: + arr_item = item_str.split('=') + device_info_one[prop] = arr_item[1] + break + for item in read_info_list: + checkProperty(item, dev_name) + devices_info[dev_name] = device_info_one #getDeviceInfoByName('') #print 'device_info:',device_info def getDeviceInfomation(): - for device in arrDevices: - getDeviceInfoByName(device['name']) + for device in arrDevices: + getDeviceInfoByName(device['name']) info_empty_test = {} info_empty_test_pro = ['install','open','socket','uninstall'] def init_info_empty_test(): - for item in info_empty_test_pro: - info_empty_test[item] = {} + for item in info_empty_test_pro: + info_empty_test[item] = {} init_info_empty_test() apk_name = 'apks/'+test_name[gIdx]+'/'+test_name[gIdx]+'_'+str(pr_num)+'.apk' def install_apk_on_device(device): - name = device['name'] - cmd = 'adb -s '+name+' install '+apk_name - print 'install on '+name - info_install = os.popen(cmd).read() - print 'infomation of install apk:', info_install - info_install_arr = info_install.split('\r\n') - info_install_result = False - for item in info_install_arr: - if item.find('Success') > -1: - info_install_result = True - info_empty_test['install'][name] = info_install_result - return True + name = device['name'] + cmd = 'adb -s '+name+' install '+apk_name + print 'install on '+name + info_install = os.popen(cmd).read() + print 'infomation of install apk:', info_install + info_install_arr = info_install.split('\r\n') + info_install_result = False + for item in info_install_arr: + if item.find('Success') > -1: + info_install_result = True + info_empty_test['install'][name] = info_install_result + return True def open_apk_on_device(device): - print 'will open activity:' - name = device['name'] - cmd = 'adb -s '+name+' shell am start -n '+package_name[gIdx]+'/'+activity_name[gIdx] - # print 'start activity:', cmd - info_start = os.popen(cmd).read() - info_start = info_start.split('\r\n') - # print 'info_start:', info_start - info_start_result = True - for info in info_start: - if info.find('Error:') > -1: - print 'infomation of open activity:',info - info_start_result = False - info_empty_test['open'][name] = info_start_result - return True + print 'will open activity:' + name = device['name'] + cmd = 'adb -s '+name+' shell am start -n '+package_name[gIdx]+'/'+activity_name[gIdx] + # print 'start activity:', cmd + info_start = os.popen(cmd).read() + info_start = info_start.split('\r\n') + # print 'info_start:', info_start + info_start_result = True + for info in info_start: + if info.find('Error:') > -1: + print 'infomation of open activity:',info + info_start_result = False + info_empty_test['open'][name] = info_start_result + return True PORT = 5678 def socket_status_on_device(device): - name = device['name'] - ip = device['ip'] - soc = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) - status_socket = False - info_of_socket_result = '' - try: - print 'telnet ', ip, PORT - soc.connect((ip, PORT)) - cmd = 'resolution\r\n' - print 'connected successfully.' - print 'send console command: resolution' - soc.send(cmd) - while True: - data = soc.recv(1024) - if len(data): - print data - if data.find('size:') > -1: - info_of_socket_result = 'OK' - print 'close', test_name[gIdx] - soc.send('director end') - status_socket = True - break - if not data: - info_of_socket_result = test_name[gIdx]+' is crashed!' - break - except Exception, e: - info_of_socket_result = test_name[gIdx]+' is crashed!' - time.sleep(2) - soc.close() - time.sleep(2) - info_empty_test['socket'][name] = info_of_socket_result - return status_socket + name = device['name'] + ip = device['ip'] + soc = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) + status_socket = False + info_of_socket_result = '' + try: + print 'telnet ', ip, PORT + soc.connect((ip, PORT)) + cmd = 'resolution\r\n' + print 'connected successfully.' + print 'send console command: resolution' + soc.send(cmd) + while True: + data = soc.recv(1024) + if len(data): + print data + if data.find('size:') > -1: + info_of_socket_result = 'OK' + print 'close', test_name[gIdx] + soc.send('director end') + status_socket = True + break + if not data: + info_of_socket_result = test_name[gIdx]+' is crashed!' + break + except Exception, e: + info_of_socket_result = test_name[gIdx]+' is crashed!' + time.sleep(2) + soc.close() + time.sleep(2) + info_empty_test['socket'][name] = info_of_socket_result + return status_socket def uninstall_apk_on_device(device): - # adb shell pm uninstall -n org.cocos2dx.hellolua - print 'uninstall ', test_name[gIdx] - name = device['name'] - cmd = 'adb -s '+name+' shell pm uninstall -n '+package_name[gIdx] - info_uninstall = os.popen(cmd).read() - info_uninstall_result = '' - if info_uninstall.find('Success') > -1: - info_uninstall_result = 'OK' - else: - info_uninstall_result = 'uninstall Failed!' - info_empty_test['uninstall'][name] = info_uninstall_result - return True + # adb shell pm uninstall -n org.cocos2dx.hellolua + print 'uninstall ', test_name[gIdx] + name = device['name'] + cmd = 'adb -s '+name+' shell pm uninstall -n '+package_name[gIdx] + info_uninstall = os.popen(cmd).read() + info_uninstall_result = '' + if info_uninstall.find('Success') > -1: + info_uninstall_result = 'OK' + else: + info_uninstall_result = 'uninstall Failed!' + info_empty_test['uninstall'][name] = info_uninstall_result + return True def excute_test_on_device(device): - uninstall_apk_on_device(device) - print device - info_install = install_apk_on_device(device) - print 'install:', info_install - info_open = open_apk_on_device(device) - print 'open:', info_open - time.sleep(3) - info_socket = socket_status_on_device(device) - print 'socket:', info_socket - info_uninstall = uninstall_apk_on_device(device) - print 'uninstall:', info_uninstall - allThreadIsRunning[device['name']] = 0 + uninstall_apk_on_device(device) + print device + info_install = install_apk_on_device(device) + print 'install:', info_install + info_open = open_apk_on_device(device) + print 'open:', info_open + time.sleep(3) + info_socket = socket_status_on_device(device) + print 'socket:', info_socket + info_uninstall = uninstall_apk_on_device(device) + print 'uninstall:', info_uninstall + allThreadIsRunning[device['name']] = 0 address_of_result_html = '' def send_result_to_master(): - if not os.environ.has_key('REMOTE_IP'): - return false - remote_ip = os.environ['REMOTE_IP'] - remote_port = os.environ['REMOTE_PORT'] - remote_user = os.environ['REMOTE_USER'] - remote_pwd = os.environ['REMOTE_PWD'] - remote_dir = os.environ['REMOTE_DIR'] - remote_dir = remote_dir + str(pr_num)+'/' - print remote_dir - ssh = paramiko.SSHClient() - print 'ssh:',ssh - ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - ssh.connect(remote_ip, int(remote_port), remote_user, remote_pwd) - # create dir - stdin, stdout, stderr = ssh.exec_command("mkdir "+remote_dir) - ssh.close() - trans = paramiko.Transport((remote_ip,int(remote_port))) - trans.connect(username = remote_user, password = remote_pwd) - sftp = paramiko.SFTPClient.from_transport(trans) - remotepath = remote_dir+test_name[gIdx]+'_'+str(pr_num)+'.html' - localpath = 'html/cpp_empty_test/cpp_empty_test_'+str(pr_num)+'.html' - sftp.put(localpath, remotepath) - sftp.close() - result_dir = remote_dir.replace('/data',':9000') - global address_of_result_html - address_of_result_html = 'http://'+remote_ip+result_dir+test_name[gIdx]+'_'+str(pr_num)+'.html' - + if not os.environ.has_key('REMOTE_IP'): + return false + remote_ip = os.environ['REMOTE_IP'] + remote_port = os.environ['REMOTE_PORT'] + remote_user = os.environ['REMOTE_USER'] + remote_pwd = os.environ['REMOTE_PWD'] + remote_dir = os.environ['REMOTE_DIR'] + remote_dir = remote_dir + str(pr_num)+'/' + print remote_dir + ssh = paramiko.SSHClient() + print 'ssh:',ssh + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + ssh.connect(remote_ip, int(remote_port), remote_user, remote_pwd) + # create dir + stdin, stdout, stderr = ssh.exec_command("mkdir "+remote_dir) + ssh.close() + trans = paramiko.Transport((remote_ip,int(remote_port))) + trans.connect(username = remote_user, password = remote_pwd) + sftp = paramiko.SFTPClient.from_transport(trans) + remotepath = remote_dir+test_name[gIdx]+'_'+str(pr_num)+'.html' + localpath = 'html/cpp_empty_test/cpp_empty_test_'+str(pr_num)+'.html' + sftp.put(localpath, remotepath) + sftp.close() + result_dir = remote_dir.replace('/data',':9000') + global address_of_result_html + address_of_result_html = 'http://'+remote_ip+result_dir+test_name[gIdx]+'_'+str(pr_num)+'.html' + def check_thread_is_running(): - while 1: - in_running = 0 - for key in allThreadIsRunning: - in_running = in_running + allThreadIsRunning[key] - # print 'in_running:', in_running - time.sleep(3) - if not in_running: - break - print 'all cpp emptytest is finished.' - log_emptytest_result() - print 'will send result:' - send_result_to_master() - print 'end of check thread is running.' - print 'address of result is:',address_of_result_html + while 1: + in_running = 0 + for key in allThreadIsRunning: + in_running = in_running + allThreadIsRunning[key] + # print 'in_running:', in_running + time.sleep(3) + if not in_running: + break + print 'all cpp emptytest is finished.' + log_emptytest_result() + print 'will send result:' + send_result_to_master() + print 'end of check thread is running.' + print 'address of result is:',address_of_result_html def generate_html_with_result(result): - target_path = 'html/cpp_empty_test/cpp_empty_test_'+str(pr_num)+'.html' - data = codecs.open('hello.html', encoding='UTF-8').read() - data = re.sub("content", result, data) - codecs.open(target_path, 'wb', encoding='UTF-8').write(data) + target_path = 'html/cpp_empty_test/cpp_empty_test_'+str(pr_num)+'.html' + data = codecs.open('hello.html', encoding='UTF-8').read() + data = re.sub("content", result, data) + codecs.open(target_path, 'wb', encoding='UTF-8').write(data) empty_test_result = True str_result = '' def log_emptytest_result(): - def appendToResult(one_str): - global str_result - str_result = str_result + one_str + '\r\n' - appendToResult('
')
-	appendToResult('empty test start:')
-	for device in arrDevices:
-		name = device['name']
-		appendToResult('device infomation of : '+name)
-		for key in devices_info[name]:
-			appendToResult('\t'+key+':'+devices_info[name][key])
-		appendToResult('install: ' + str(info_empty_test['install'][name]))
-		appendToResult('open: ' + str(info_empty_test['open'][name]))
-		appendToResult('telnet ' + str(device['ip'])+' : ' + str(info_empty_test['socket'][name]))
-		appendToResult('close: ' + str(info_empty_test['socket'][name]))
-		appendToResult('uninstall: ' + str(info_empty_test['uninstall'][name]))
-		if not info_empty_test['install'][name] or not info_empty_test['open'][name] or not info_empty_test['socket'][name] or not info_empty_test['uninstall'][name]:
-			empty_test_result = False
-			appendToResult('run failed!')
-		else: appendToResult('run successfully!')
-		appendToResult('')
-	appendToResult('empty test end.
') - generate_html_with_result(str_result) - print 'log empty test end' + def appendToResult(one_str): + global str_result + str_result = str_result + one_str + '\r\n' + appendToResult('
')
+    appendToResult('empty test start:')
+    for device in arrDevices:
+        name = device['name']
+        appendToResult('device infomation of : '+name)
+        for key in devices_info[name]:
+            appendToResult('\t'+key+':'+devices_info[name][key])
+        appendToResult('install: ' + str(info_empty_test['install'][name]))
+        appendToResult('open: ' + str(info_empty_test['open'][name]))
+        appendToResult('telnet ' + str(device['ip'])+' : ' + str(info_empty_test['socket'][name]))
+        appendToResult('close: ' + str(info_empty_test['socket'][name]))
+        appendToResult('uninstall: ' + str(info_empty_test['uninstall'][name]))
+        if not info_empty_test['install'][name] or not info_empty_test['open'][name] or not info_empty_test['socket'][name] or not info_empty_test['uninstall'][name]:
+            empty_test_result = False
+            appendToResult('run failed!')
+        else: appendToResult('run successfully!')
+        appendToResult('')
+    appendToResult('empty test end.
') + generate_html_with_result(str_result) + print 'log empty test end' class myThread(threading.Thread): def __init__(self,threadname): @@ -316,39 +316,39 @@ class myThread(threading.Thread): excute_test_on_device(device) def run_emptytest(): - for device in arrDevices: - th = myThread(device) - th.start() + for device in arrDevices: + th = myThread(device) + th.start() def main(): - print 'in main:' - getDevices() - if len(arrDevices): - mapIP() - setThreadStatus() - print 'arrDevices:',arrDevices - time.sleep(1) - else: - print 'there is no device for emptytest, please check devices!' - return 1 - if len(arrDevices): - getDeviceInfomation() - run_emptytest() - check_thread_is_running() - print 'info_empty_test:', info_empty_test - print 'empty test end', empty_test_result - if empty_test_result: - return 0 - else: - return 1 + print 'in main:' + getDevices() + if len(arrDevices): + mapIP() + setThreadStatus() + print 'arrDevices:',arrDevices + time.sleep(1) + else: + print 'there is no device for emptytest, please check devices!' + return 1 + if len(arrDevices): + getDeviceInfomation() + run_emptytest() + check_thread_is_running() + print 'info_empty_test:', info_empty_test + print 'empty test end', empty_test_result + if empty_test_result: + return 0 + else: + return 1 # -------------- main -------------- if __name__ == '__main__': sys_ret = 0 try: - sys_ret = main() + sys_ret = main() except: - traceback.print_exc() - sys_ret = 1 + traceback.print_exc() + sys_ret = 1 finally: - sys.exit(sys_ret) + sys.exit(sys_ret) diff --git a/tools/jenkins-scripts/github-pr-watchdog.py b/tools/jenkins-scripts/github-pr-watchdog.py index d5c417730e..0f38b46117 100644 --- a/tools/jenkins-scripts/github-pr-watchdog.py +++ b/tools/jenkins-scripts/github-pr-watchdog.py @@ -12,61 +12,61 @@ job_trigger_url=os.environ['JOB_PULL_REQUEST_BUILD_TRIGGER_URL'] access_token = os.environ['GITHUB_ACCESS_TOKEN'] Headers = {"Authorization":"token " + access_token} def main(): - r = requests.get(url,headers=Headers) - payload = r.json() - #print payload - for pr in payload: - pr_num = pr['number'] - r = requests.get(pr['url']+"/commits",headers=Headers) - commits = r.json() - #print commits - last_commit = commits[len(commits)-1] - message = last_commit['commit']['message'] - - #print message - pattern = re.compile("\[ci(\s+)skip\]", re.I) - result_commit_title = pattern.search(message) + r = requests.get(url,headers=Headers) + payload = r.json() + #print payload + for pr in payload: + pr_num = pr['number'] + r = requests.get(pr['url']+"/commits",headers=Headers) + commits = r.json() + #print commits + last_commit = commits[len(commits)-1] + message = last_commit['commit']['message'] + + #print message + pattern = re.compile("\[ci(\s+)skip\]", re.I) + result_commit_title = pattern.search(message) - title = pr['title'] - result_pr_title = pattern.search(title) - if result_commit_title is not None or result_pr_title is not None: - print 'skip build for pull request #' + str(pr_num) - break - #return(0) - s = pr['statuses_url'] - update_time = pr['updated_at'] - #print pr_num - #print s - #print update_time - t = datetime.datetime.strptime(update_time, "%Y-%m-%dT%H:%M:%SZ") - now = datetime.datetime.utcnow() - three_minutes = datetime.timedelta(seconds=3*60) - if (t + three_minutes < now): - #print pr_num - statuses = requests.get(s, headers=Headers) - #print statuses.json() - if(len(statuses.json()) < 1): - print pr_num - payload_forward = {} - payload_forward['number']=pr_num - payload_forward['action']=pr['state'] - payload_forward['html_url']=pr['html_url'] - payload_forward['statuses_url']=pr['statuses_url'] - payload_forward['branch']=pr['base']['ref'] - print payload_forward - post_data = {'payload':""} - post_data['payload']= json.dumps(payload_forward) + title = pr['title'] + result_pr_title = pattern.search(title) + if result_commit_title is not None or result_pr_title is not None: + print 'skip build for pull request #' + str(pr_num) + break + #return(0) + s = pr['statuses_url'] + update_time = pr['updated_at'] + #print pr_num + #print s + #print update_time + t = datetime.datetime.strptime(update_time, "%Y-%m-%dT%H:%M:%SZ") + now = datetime.datetime.utcnow() + three_minutes = datetime.timedelta(seconds=3*60) + if (t + three_minutes < now): + #print pr_num + statuses = requests.get(s, headers=Headers) + #print statuses.json() + if(len(statuses.json()) < 1): + print pr_num + payload_forward = {} + payload_forward['number']=pr_num + payload_forward['action']=pr['state'] + payload_forward['html_url']=pr['html_url'] + payload_forward['statuses_url']=pr['statuses_url'] + payload_forward['branch']=pr['base']['ref'] + print payload_forward + post_data = {'payload':""} + post_data['payload']= json.dumps(payload_forward) - requests.post(job_trigger_url, data=post_data) + requests.post(job_trigger_url, data=post_data) # -------------- main -------------- if __name__ == '__main__': sys_ret = 0 try: - main() + main() except: - traceback.print_exc() - sys_ret = 1 + traceback.print_exc() + sys_ret = 1 finally: - sys.exit(sys_ret) + sys.exit(sys_ret) diff --git a/tools/jenkins-scripts/post-build.py b/tools/jenkins-scripts/post-build.py index 2efc346ded..68d9055111 100644 --- a/tools/jenkins-scripts/post-build.py +++ b/tools/jenkins-scripts/post-build.py @@ -33,10 +33,10 @@ def send_mail(sub,title,content): return False def sendEmail(pr, html_url, target_url): - sub = "Pull request #" + str(pr) + " build is failed!" - title = "build failed!" - content = 'to view build result, check:\r\n'+target_url + '\r\nYou can view the failed pr at:\r\n'+html_url - send_mail(sub, title, content) + sub = "Pull request #" + str(pr) + " build is failed!" + title = "build failed!" + content = 'to view build result, check:\r\n'+target_url + '\r\nYou can view the failed pr at:\r\n'+html_url + send_mail(sub, title, content) payload_str = os.environ['payload'] payload_str = payload_str.decode('utf-8','ignore') diff --git a/tools/jenkins-scripts/reboot.py b/tools/jenkins-scripts/reboot.py index 8d21c6d175..22f6a1b05c 100755 --- a/tools/jenkins-scripts/reboot.py +++ b/tools/jenkins-scripts/reboot.py @@ -25,40 +25,40 @@ print 'remote_port',int(remote_port[0]) all_machines = {} def set_default_value_to_all_machines(): - for idx, item in enumerate(remote_machines): - all_machines[item]={} - all_machines[item]['ip']=remote_ip[idx] - all_machines[item]['dir']=remote_dir[idx] - all_machines[item]['port']=remote_port[idx] - all_machines[item]['user']=remote_user[idx] - all_machines[item]['pwd']=os.environ[item+'_PWD'] + for idx, item in enumerate(remote_machines): + all_machines[item]={} + all_machines[item]['ip']=remote_ip[idx] + all_machines[item]['dir']=remote_dir[idx] + all_machines[item]['port']=remote_port[idx] + all_machines[item]['user']=remote_user[idx] + all_machines[item]['pwd']=os.environ[item+'_PWD'] def reboot_machine(machine, item): - print 'machine:',machine, 'item:', item - remote_ip = machine['ip'] - remote_port = machine['port'] - remote_user = machine['user'] - remote_pwd = machine['pwd'] - remote_dir = os.path.join(machine['dir'],'workspace','reboot', 'reboot.py') - print remote_dir - ssh = paramiko.SSHClient() - print 'ssh:',ssh - ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - ssh.connect(remote_ip, int(remote_port), remote_user, remote_pwd) - # excute reboot.py on machine - cmd = 'python '+remote_dir - if item == 'win32_win7': - cmd = 'cmd.exe /c "python '+remote_dir+'"' - stdin, stdout, stderr = ssh.exec_command(cmd) - print stdout.readlines() - ssh.close() - print 'OK' + print 'machine:',machine, 'item:', item + remote_ip = machine['ip'] + remote_port = machine['port'] + remote_user = machine['user'] + remote_pwd = machine['pwd'] + remote_dir = os.path.join(machine['dir'],'workspace','reboot', 'reboot.py') + print remote_dir + ssh = paramiko.SSHClient() + print 'ssh:',ssh + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + ssh.connect(remote_ip, int(remote_port), remote_user, remote_pwd) + # excute reboot.py on machine + cmd = 'python '+remote_dir + if item == 'win32_win7': + cmd = 'cmd.exe /c "python '+remote_dir+'"' + stdin, stdout, stderr = ssh.exec_command(cmd) + print stdout.readlines() + ssh.close() + print 'OK' def main(): - print 'in main' - set_default_value_to_all_machines() - for item in all_machines: - reboot_machine( all_machines[item], item ) + print 'in main' + set_default_value_to_all_machines() + for item in all_machines: + reboot_machine( all_machines[item], item ) # -------------- main -------------- if __name__ == '__main__':