Exemplo n.º 1
0
 def get(self):
     arg_dict = self.request.arguments
     logger.info('GET AQUBE', args=arg_dict)
     device_id = get_real_device_id(arg_dict['deviceId'][0].decode())
     action_name = arg_dict['actionName'][0].decode()
     action_args = json.loads(arg_dict['actionArgs'][0].decode())
     aqube_result = forward.aqube(device_id, action_name, action_args)
     self.end_with_json(RESULT_OK, message=aqube_result)
Exemplo n.º 2
0
def ping(delay):
    time.sleep(delay)
    response = requests.get(url='http://localhost:{}'.format(
        cf.TORNADO_PORT), )
    if 'ALIVE' in response.text:
        logger.info('SIMHAND UP :)')
        return
    logger.error('SIMHAND ERROR :(')
    raise RuntimeError('simhand start failed')
Exemplo n.º 3
0
 def get(self):
     # 获取动作名称 动作参数 设备编号
     arg_dict = self.request.arguments
     logger.info('GET UIAUTOACTION', args=arg_dict)
     action_name = arg_dict['actionName'][0].decode()
     action_args = json.loads(arg_dict['actionArgs'][0].decode())
     device_id = get_real_device_id(arg_dict['deviceId'][0].decode())
     # ui操作
     ui_result = forward.ui(device_id, action_name, action_args)
     self.end_with_json(RESULT_OK, message=ui_result)
Exemplo n.º 4
0
 def get(self):
     # 得到 设备ID 与 截图保存名称
     arg_dict = self.request.arguments
     logger.info('GET SCREENSHOT', args=arg_dict)
     pic_name = arg_dict['name'][0].decode()
     device_id = get_real_device_id(arg_dict['deviceId'][0].decode())
     # 正式截图
     shot_result = forward.screen_shot(device_id, pic_name)
     # 返回截图结果
     self.end_with_json(RESULT_OK, message=shot_result)
Exemplo n.º 5
0
 def __init__(self, device_id):
     # TODO 实际上每次都init太慢 但是不init会有断开的风险 正式环境需要在uiautomator2中增加一个restart方法
     try:
         self.device = u2.connect(device_id)
         self.device.current_app()
     except (ConnectionError, ConnectionResetError, ProtocolError):
         _cmd_list = ['python', '-m', 'uiautomator2', 'init', device_id]
         logger.info('U2 is down, RESTART', cmd=_cmd_list)
         subprocess.run(_cmd_list, shell=True)
         time.sleep(2)
         self.device = u2.connect(device_id)
Exemplo n.º 6
0
 def end_with_json(self, code, data=None, message=None):
     """ 规范服务器返回 """
     request_url = self.request.uri
     result_dict = {
         'code': code,
         'data': data or {},
         'message': message or {},
     }
     logger.info('REQUEST END',
                 code=code,
                 data=data,
                 message=message,
                 request_url=request_url)
     self.finish(result_dict)
Exemplo n.º 7
0
def screen_shot(device_id, pic_name):
    """
    操作截图

    :param device_id: 设备ID,与adb devices得到的ID一致
    :param pic_name: 截图保存的真实路径及文件名(保存在手机中)
    :return:
    """
    shot_cmd_list = [
        'adb', '-s', device_id, 'shell', 'screencap', '-p', pic_name
    ]
    logger.info('SCREEN SHOT CMD', cmd=' '.join(shot_cmd_list))
    screen_shot_completed_process = subprocess.run(shot_cmd_list,
                                                   stdout=subprocess.PIPE)
    screen_shot_result = screen_shot_completed_process.stdout.decode()
    logger.info('SCREEN SHOT RESULT', result=screen_shot_result or 'None')
    return screen_shot_result or 'None'
Exemplo n.º 8
0
 def __getattr__(cls, item):
     if hasattr(cls.aqube_module, item):
         return getattr(cls.aqube_module, item)
     logger.info('METHOD NOT FOUND', method=item)
     return None
Exemplo n.º 9
0
from tornado.web import Application
from tornado.ioloop import IOLoop
import requests
import time
import threading

from simhand import config as cf
from simhand.logger import logger
from simhand.router import TORNADO_ROUTER


def ping(delay):
    time.sleep(delay)
    response = requests.get(url='http://localhost:{}'.format(
        cf.TORNADO_PORT), )
    if 'ALIVE' in response.text:
        logger.info('SIMHAND UP :)')
        return
    logger.error('SIMHAND ERROR :(')
    raise RuntimeError('simhand start failed')


if __name__ == "__main__":
    # stable check
    logger.info('STARTING ...')
    threading.Thread(target=ping, args=(2, )).start()

    application = Application(TORNADO_ROUTER, **cf.TORNADO_SETTING)
    application.listen(cf.TORNADO_PORT)
    IOLoop.instance().start()
Exemplo n.º 10
0
""" global config """
import os
from simhand.logger import logger

# 项目根目录
ROOT_PATH = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
# SIMHAND 项目目录
PROJECT_PATH = os.path.join(ROOT_PATH, 'simhand')
# AQUBE_CORE 项目目录
AQUBE_PATH = os.path.join(ROOT_PATH, 'AQube_Core')
# AQUBE_CORE URL
AQUBE_URL = 'https://github.com/williamfzc/AQube_Core.git'
# pysubmodule json
PYSUBMODULE_JSON = os.path.join(ROOT_PATH, 'pysub.json')

# TORNADO 配置
TORNADO_SETTING = {
    'debug': True,
    'static_path': os.path.join(PROJECT_PATH, "static"),
    'template_path': os.path.join(PROJECT_PATH, "template"),
}
TORNADO_PORT = 9507

logger.info('ROOT PATH', root_path=ROOT_PATH)
logger.info('PROJECT PATH', project_path=PROJECT_PATH)
logger.info('PORT', port=TORNADO_PORT)
logger.info('AQUBE PATH', aqube_core=AQUBE_PATH)