def add(func_name, real_func): if not is_existed(func_name): _func_map[func_name] = real_func logger.info(conf.TAG_BINDER, msg='function {} added'.format(func_name)) return True logger.warn(conf.TAG_BINDER, msg='function already existed', name=func_name) return False
def remove(func_name): if func_name in _func_map: del _func_map[func_name] logger.info(conf.TAG_BINDER, msg='function {} removed'.format(func_name)) return True logger.warn(conf.TAG_BINDER, msg='function {} not existed'.format(func_name)) return False
def _bind_standard(cls): # build-in functions bind here logger.info(conf.TAG_BINDER, msg=' standard package loading ... '.center(40, '-')) extra_functions = importlib.import_module('pyatool.extras') for each_func in extra_functions.__all__: function_obj = getattr(extra_functions, each_func) PYAToolkit.bind_func(real_func=function_obj) logger.info(conf.TAG_BINDER, msg=' standard package loaded '.center(40, '-'))
def _exec(command): adb_process = subprocess.Popen(command, stdout=subprocess.PIPE) exec_result, exec_err = adb_process.communicate( timeout=conf.DEFAULT_TIMEOUT) if adb_process.returncode != 0: feedback = 'unknown error happened when execute {}, view terminal for detail'.format( command) if exec_err: feedback = exec_err.decode() raise RuntimeError(feedback) logger.info(conf.TAG_EXEC_CMD, cmd=command, result=exec_result) return exec_result.decode()
def __init__(self, device_id, mode=None): self.adb_exec = [conf.ADB_EXECUTOR, '-s', device_id] self.device_id = device_id self.device_ip = None # remote connect if mode and mode == 'remote': self.device_ip = self._enable_remote_connect() self.adb_exec = [conf.ADB_EXECUTOR, '-s', self.device_ip] # show current configure logger.info(conf.TAG_DEVICE, id=self.device_id, ip=self.device_ip, adb_cmd=self.adb_exec)