Exemple #1
0
 def _register_any_task(cls, _, todo, event_type):
     if not todo:
         return
     if event_type not in cls._any_task_dict:
         cls._any_task_dict[event_type] = set()
     cls._any_task_dict[event_type].add(todo)
     logger.info('RESISTER ANY', func_name=todo.__name__)
Exemple #2
0
    def register_task(cls, operate_type, event_type, todo, device_list=None):
        logger.info('START REGISTER', type=operate_type)

        if operate_type in cls._operation_dict:
            operate_type = cls._operation_dict[operate_type]
        func_item = getattr(cls, operate_type, cls._default_operation)
        return func_item(device_list, todo, event_type)
Exemple #3
0
 def _register_specific_task(cls, device_list, todo, event_type):
     for each_device in device_list:
         if each_device not in cls._specific_task_dict:
             cls._specific_task_dict[each_device] = dict()
         if event_type not in cls._specific_task_dict[each_device]:
             cls._specific_task_dict[each_device][event_type] = set()
         cls._specific_task_dict[each_device][event_type].add(todo)
         logger.info('RESISTER SPECIFIC', func_name=todo.__name__, device=each_device)
Exemple #4
0
def get_prop(device_id):
    """ get prop """
    cmd_list = ['adb', '-s', device_id, 'shell', 'getprop']
    return_code, output, error = exec_cmd(cmd_list)
    if return_code:
        logger.info('GETPROP ERROR', code=return_code, msg=error)
        return
    prop_dict = {
        each.split(':')[0].strip('[] '): each.split(':')[1].strip('[] ')
        for each in output.split('\r\n') if each
    }
    return prop_dict
Exemple #5
0
    def exec_task(cls, device_id, event_type):
        # any func
        func_list = cls._any_task_dict[event_type].copy()

        # specific func
        if device_id in cls._specific_task_dict:
            _specific_func_list = cls._specific_task_dict[device_id][event_type]
            func_list |= _specific_func_list

        logger.info('ALL FUNC NEED EXEC', func_list=[i.__name__ for i in func_list])
        for each_func in func_list:
            logger.info('EXEC FUNC', func=each_func.__name__, device=device_id)
            each_func(device_id)
Exemple #6
0
    def set_devices(cls, current_devices):
        add_device_set = current_devices - cls._devices
        lost_device_set = cls._devices - current_devices

        # remove device
        for each_device in lost_device_set:
            logger.info('LOST DEVICE', device=each_device)
            TaskManager.exec_task(each_device, 'disconnect')

        # add device
        for each_device in add_device_set:
            logger.info('ADD DEVICE', device=each_device)
            TaskManager.exec_task(each_device, 'connect')

        cls._devices = current_devices