Example #1
0
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)
Example #3
0
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()
Example #4
0
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)
Example #5
0
 #kill_pop_window.kill_error_box()
 if platform.system().find('Win')!= -1:
     p_killer = Process(target=run_kill_error,args=())
     p_killer.start()
 p_process_killer = Process(target=run_kill_longprocess,args=(20,int(opt.timeout_kill)))
 p_process_killer.start()
 if process_num == -1:
     if cases == -1:
         pass
     else:
         for id1,cmd in enumerate(run_cmd):
             print_logs = []
             if 1: # used for process multi-process-lulti-machine
                 case_run_over = 0
                 if platform.system().find('Win')!= -1:
                     lock_hand = xFiles.lock_file('temp/'+'temp_lock_file.log')
                 run_over_file = 'temp/'+'run_over_'+new_lines_bat
                 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(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: