示例#1
0
def monitor_device():
    while True:
        # logging.info("monitor_device")
        time.sleep(5)
        current_device_dict = {}
        new_device_dict = {}
        current_device_dict = get_device_info()
        logging.debug('current device dict: %s' % current_device_dict)
        logging.debug('Config.device_dict is %s' % Config.device_dict)
        if current_device_dict != Config.device_dict:
            for device_model, device_id in current_device_dict.iteritems():
                if device_model not in Config.device_dict:
                    new_device_dict.update({device_model: device_id})

            if new_device_dict != {}:
                logging.debug('new device dict is: %s' % new_device_dict)
            else:
                logging.info('device lost')
            Config.device_dict = current_device_dict
            create_threads_monkey(new_device_dict)
def monitor_device():
    start_adb()
    while True:
        # logging.info("monitor_device")
        time.sleep(5)
        current_device_dict = {}
        new_device_dict = {}
        current_device_dict = get_device_info()
        logging.debug('current device dict: %s' % current_device_dict)
        logging.debug('Config.device_dict is %s' % Config.device_dict)
        if current_device_dict != Config.device_dict:
            for device_model, device_id in current_device_dict.iteritems():
                if device_model not in Config.device_dict:
                    new_device_dict.update({device_model: device_id})

            if new_device_dict != {}:
                logging.debug('new device dict is: %s' % new_device_dict)
            else:
                logging.info('device lost')
            Config.device_dict = current_device_dict
            create_threads_monkey(new_device_dict)
示例#3
0
            output = subprocess.check_output(cmd_pid)
            print('222222',output)
            output = output.decode()
        except Exception:
            traceback.print_exc()
        if output == '':
            logging.info("No monkey running in %s" % device_model)
            break
        else:
            output = re.search('shell     [0-9]+', output).group()
            pid = re.search('[0-9]+', output).group()
            logging.info("kill the monkey process: %s in %s" % (pid, device_model))
            output = subprocess.check_output("%s -s %s shell kill %s" % (adb, device_id, pid))
            output = output.decode()
    time.sleep(2)
#停止跑monkey
def stop_monkey(device_id, device_model):
    if platform.system() == 'Darwin':
        logging.debug('This system is Mac')
        stop_monkey_for_mac(device_id, device_model)
    elif platform.system() == 'Windows':
        logging.debug('This system is Windows')
        stop_monkey_for_win(device_id, device_model)
    else:
        logging.info('Do not surpport your system')

if __name__ == '__main__':
    device_dict = get_device_info()
    for device_model, device_id in device_dict.items():
        stop_monkey(device_id, device_model)
        output = None
        cmd_pid = "%s -s %s shell ps | grep monkey" % (adb, device_id)
        try:
            output = subprocess.check_output(cmd_pid)
        except Exception:
            traceback.print_exc()
        if output == '':
            logging.info("No monkey running in %s" % device_model)
            break
        else:
            output = re.search('shell     [0-9]+', output).group()
            pid = re.search('[0-9]+', output).group()
            logging.info("kill the monkey process: %s in %s" % (pid, device_model))
            output = subprocess.check_output("%s -s %s shell kill %s" % (adb, device_id, pid))
    time.sleep(2)

def stop_monkey(device_id, device_model):
    if platform.system() == 'Darwin':
        logging.debug('This system is Mac')
        stop_monkey_for_mac(device_id, device_model)
    elif platform.system() == 'Windows':
        logging.debug('This system is Windows')
        stop_monkey_for_win(device_id, device_model)
    else:
        logging.info('Do not surpport your system')

if __name__ == '__main__':
    device_dict = get_device_info()
    for device_model, device_id in device_dict.iteritems():
        stop_monkey(device_id, device_model)