def retrun_process_num(): ''' This file used to return the process number for this process of suite support. the line content should be as: time_flag machine_name number ''' try: machine_name = platform.uname()[1] machine_name = machine_name.lower() except: machine_name = ' ' if platform.system().find('Win')!= -1: lock_hand = xFiles.lock_file('temp_lock_file.log') shared_file = 'shared_num.log' starts_line = machine_name number = 0 if os.path.isfile(shared_file): file_hand = file(shared_file) all_lines = file_hand.readlines() file_hand.close() for l in all_lines: l = (l.strip()).lower() if l.find(starts_line) != -1: try: number += int(l.split()[2]) except: pass else: pass if platform.system().find('Win')!= -1: xFiles.unlock_file(lock_hand) return number
def run_case(cmd,lock,max_process,result_log='',run_over_file='aa',TIME_flag=str(time.time())): update_process_num(TIME_flag,True) time_begin = time.time() initial_cmd = cmd lock.acquire() max_process.value = max_process.value + 1 lock.release() pro_lines_temp = [cmd+'\n'] process_stat_temp = 0 if sys.platform[:3] != "win": cmd = "{ " + cmd + "; }" else: cmd = 'start /MIN '+cmd pass pipe2 = os.popen(cmd + " 2>&1", "r") for item in pipe2: pro_lines_temp.append(item.rstrip()+'\n') try: sts = pipe2.close() if sts >=1: process_stat_temp = sts if sts is None: process_stat_temp = 0 except IOError: pro_lines_temp.append('In run_cmd can not run: '+cmd+'\n') process_stat_temp = 1 time.sleep(5) lock.acquire() if result_log: file_hand = file(result_log,'a') file_hand.writelines(pro_lines_temp) file_hand.close() max_process.value = max_process.value - 1 lock.release() time_end = time.time() time_scope = time_end - time_begin time_scope = "--%-8s"%str(time_scope) #time_scope = "%-8s"% if platform.system().find('Win')!= -1: lock_hand = xFiles.lock_file('temp_lock_file.log') #run_over_file = 'run_over_'+new_lines_bat new_lines = [] if os.path.isfile(run_over_file): run_over_lines = file(run_over_file).readlines() for case_l in run_over_lines: if case_l.find(initial_cmd) != -1: case_l = time_scope + ' '+case_l new_lines.append(case_l) file_hand_t = file(run_over_file,'w') file_hand_t.writelines(new_lines) file_hand_t.close() if platform.system().find('Win')!= -1: xFiles.unlock_file(lock_hand) update_process_num(TIME_flag,add=False)
def run_case(cmd,lock,max_process,result_log='',run_over_file='aa',TIME_flag=str(time.time()),case_dict={}): update_process_num(TIME_flag,True) time_begin = time.time() initial_cmd = cmd lock.acquire() max_process.value = max_process.value + 1 lock.release() pro_lines_temp = [cmd+'\n'] process_stat_temp = 0 if sys.platform[:3] != "win": cmd = "{ " + cmd + "; }" else: cmd = 'start /MIN '+cmd pass pipe2 = os.popen(cmd + " 2>&1", "r") for item in pipe2: pro_lines_temp.append(item.rstrip()+'\n') try: sts = pipe2.close() if sts >=1: process_stat_temp = sts if sts is None: process_stat_temp = 0 except IOError: pro_lines_temp.append('In run_cmd can not run: '+cmd+'\n') process_stat_temp = 1 time.sleep(1) try: lock.acquire() if result_log: file_hand = file(result_log,'a') file_hand.writelines(pro_lines_temp) file_hand.close() if max_process.value >= 0.9: max_process.value = max_process.value - 1 if max_process.value <= 0.1: max_process.value = 0 lock.release() time_end = time.time() time_scope = time_end - time_begin time_scope = "--%-8s"%str(time_scope) if platform.system().find('Win')!= -1: lock_hand = xFiles.lock_file('temp_lock_file.log') new_lines = [] file_hand_t = file(run_over_file,'a') file_hand_t.write(time_scope + ' '+initial_cmd+'\n') file_hand_t.close() if platform.system().find('Win')!= -1: xFiles.unlock_file(lock_hand) # remove the till-map lock.acquire() temp_case_dict = {} temp_case_dict = copy.deepcopy(case_dict) for d,cmd_list in temp_case_dict.items(): if not cmd_list: continue for sub_cmd in cmd_list: if sub_cmd == initial_cmd and sub_cmd.find('--till-map')!= -1: #print cmd_list cmd_list.remove(sub_cmd) case_dict[d] = cmd_list break lock.release() update_process_num(TIME_flag,add=False) except Exception,e: print traceback.format_exc()
def update_process_num(TIME_flag,add=True): ''' This file used to update the process number between different suite support. the line content should be as: time_flag machine_name number ''' time.sleep(3) try: machine_name = platform.uname()[1] machine_name = machine_name.lower() except: machine_name = ' ' if platform.system().find('Win')!= -1: lock_hand = xFiles.lock_file('temp_lock_file.log') shared_file = 'shared_num.log' starts_line = TIME_flag+' '+machine_name new_lines = [] if os.path.isfile(shared_file): file_hand = file(shared_file) all_lines = file_hand.readlines() file_hand.close() #print '***********************' #print all_lines #print '***********************' #print starts_line find_flag = 0 for l in all_lines: l = l.strip() l = l.lower() if not l: continue if l.startswith(starts_line): find_flag = 1 try: number = int(l.split()[2]) if add: number = number + 1 else: number = number - 1 if number < 0: number = 0 l = starts_line+' '+str(number) #print '----------',l except: pass new_lines.append(l+'\n') if find_flag == 0: if add: l = starts_line+' 1' new_lines.append(l) file_hand = file(shared_file,'w') #print '---------------------' #print new_lines #print '---------------------' file_hand.writelines(new_lines) file_hand.close() else: if add: file_hand = file(shared_file,'w') l = starts_line+' 1' file_hand.writelines(l+'\n') file_hand.close() if platform.system().find('Win')!= -1: xFiles.unlock_file(lock_hand)
if case_l.find(cmd+'\n') != -1: case_run_over = 1 break if case_run_over == 1: #run_cmd.remove(cmd) pass else: run_over_file_hand = file(run_over_file,'a') try: machine_name = platform.uname()[1] + ' ' except: machine_name = ' ' run_over_file_hand.write(machine_name+cmd+'\n') run_over_file_hand.close() if platform.system().find('Win')!= -1: xFiles.unlock_file(lock_hand) if case_run_over == 1: continue print_logs.append('='*50) print_logs.append("| "+"BQS Platform".center(50)) print_logs.append('-'*50) t_flag = str(time.ctime()) print_logs.append("| "+"%-20s"%('Show_time')+'|'+ t_flag.center(30)) print_logs.append('-'*50) print_logs.append( "| "+"%-20s"%('Running ')+'|'+get_cmd_value(cmd,'design').replace(top_dir,'').strip('\\').strip('/').center(30)) left_num = len(run_cmd)-id1 -1 print_logs.append('-'*50) print_logs.append("| "+"%-20s"%('Status(Finish/Total)')+'|'+( str(id1+1)+'/'+str(len(run_cmd))+' over in the suite').center(30)) pro_lines_temp = [] file_hand = file(log_file,'a') if sys.platform[:3] != "win":