From 5189da4e1c4350ad406558db8aef95aead60dfbb Mon Sep 17 00:00:00 2001 From: "Y. Ree" Date: Tue, 28 Aug 2018 16:43:23 +0800 Subject: [PATCH] Add event for devices, apps and screenshot (#5) * Fixed the problem that the file name of screen snapshot cannot be parsed when it has special characters. * Fix update version. * Add event for devices&app&take screenshot * Update version * Fix publish state -> True * Fix delete dup var -> PLUGIN ROOT * Add release to pypi stage. * Add build status & & Pypi version & Python required and MIT --- .travis.yml | 16 ++++++++++++++++ README.md | 5 +++++ lyrebird_ios/device_service.py | 35 ++++++++++++++++++++++++++++++++++ lyrebird_ios/ios_helper.py | 3 +-- lyrebird_ios/ui.py | 18 +++++++++++++++++ setup.py | 2 +- 6 files changed, 76 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 93a3a11..992e264 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,3 +11,19 @@ jobs: - pip install . # command to run tests script: pytest + + - stage: release to pypi + if: type = push + language: python + catch: pip + python: + - "3.6" + script: + - echo "Skipping tests" + deploy: + provider: pypi + user: YurRee + password: + secure: "a2Hxhdd0RWS6VrFt9dXTb5cD/FdNTlfpE4qUsCIP8WmJG5T98KAFiwRLYbrdoqmqRFCQEBM7WOiI/A2wZasuwSKV3LViDauhT7zMpZdrULd0HLlAIR1HQmPiU7oUV78P0WsNrdXW2sonjoKYq8kbbV6k86dqR9Y3lrcXuwDc783KIGezblHvI9kd+6vl83XWY8xyknBtnoy5qgRFe3JtcCZ58ljeLxfv2wqzbKxUo1mwB+haqBhd4aD9tG/Nvx1TjMxC2WpGwgtOd+SJN6M3cOR9cYO3lIsn0dF+TAzt2XUY87J+pPhilj++H9fyjRPlVYXsGvkqKc8zS3JRB8jay5IRwzoEO75a3dLMailFFpM44AjphmuTysShaekh6ogmPaNXCSaY7lpVGw3xbsQ7ZSd1olGQpTO1ov1X0/qAHYjnSjIv/1NWvNM/Fwz9J6E3nlUF3uBKiWGPeGzQqRvvCW1JG7eoocOXixriqsmTKiOfjnT39LmZtXWpb3/3ptycv1mniZm2D52Eotfznf3EnFZSkr2i7sXIwurdQjnErc3RkRPQnUPjulGKKfWSf+KZ/603do2G7QKhGwntVwS6y/9ddwo+7306OVHVhnaKP+Qk089W5RqUOZwLidx0q4qgFRZfyFGshxalJIjHGX1Vude1+zSMFaDtwZah6jpBEZY=" + on: + tags: true diff --git a/README.md b/README.md index 1187cef..147f11c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # Lyrebird iOS Plugin +[![Build Status](https://travis-ci.org/meituan/lyrebird-ios.svg?branch=master)](https://travis-ci.org/openatx/facebook-wda) +[![PyPI](https://img.shields.io/pypi/v/lyrebird-ios.svg)](https://pypi.python.org/pypi/lyrebird-ios) +![PyPI](https://img.shields.io/pypi/pyversions/lyrebird.svg) +![GitHub](https://img.shields.io/github/license/meituan/lyrebird-ios.svg) +--- Lyrebird 是一个基于拦截以及模拟 HTTP/HTTPs 网络请求的面向移动应用的插件化测试平台。iOS Plugin 是其插件之一,您可以在插件中快速查看已连接设备的详细设备信息,截取屏幕快照,以及查看已连接设备的应用信息。 ## 特性 diff --git a/lyrebird_ios/device_service.py b/lyrebird_ios/device_service.py index 9258a2a..c5b2739 100644 --- a/lyrebird_ios/device_service.py +++ b/lyrebird_ios/device_service.py @@ -1,5 +1,7 @@ +import lyrebird from lyrebird import context from . import ios_helper +from .helper import config from lyrebird.log import get_logger _log = get_logger() @@ -44,6 +46,7 @@ def handle(self): return self.devices = devices + self.publish_devices_info_event(self.devices) context.application.socket_io.emit('device', namespace='/iOS-plugin') def start_log_recorder(self, device_id): @@ -52,3 +55,35 @@ def start_log_recorder(self, device_id): self.devices[_device_id].start_log() else: self.devices[_device_id].stop_log() + + def publish_devices_info_event(self, online_devices): + devices = [] + for item in online_devices: + info = online_devices[item] + app = online_devices[item].get_app_info(self.get_default_app_name()) + devices.append( + { + 'id': info.device_id, + 'info': { + 'name': info.device_name, + 'model': info.model, + 'os': info.os_version, + 'sn': info.sn + }, + 'app': { + 'name': app['AppName'], + 'version': app['VersionNumber'], + 'build': app['BuildNumber'], + 'bundleID': app['BundleID'] + } + } + ) + lyrebird.publish('ios.device', devices, state=True) + + @staticmethod + def get_default_app_name(): + conf = config.load() + if hasattr(conf, 'default_app'): + return conf.default_app + else: + return '' diff --git a/lyrebird_ios/ios_helper.py b/lyrebird_ios/ios_helper.py index 4518f65..becae3e 100644 --- a/lyrebird_ios/ios_helper.py +++ b/lyrebird_ios/ios_helper.py @@ -21,8 +21,7 @@ tmp_dir = os.path.abspath(os.path.join(storage, 'tmp')) crash_dir = os.path.abspath(os.path.join(storage, 'crash')) -PLUGIN_ROOT_PATH = Path('~', '.lyrebird/plugins/lyrebird_ios').expanduser() -PLIST_PATH = os.path.join(PLUGIN_ROOT_PATH, 'plist') +PLIST_PATH = os.path.join(storage, 'plist') error_msg = None if not os.path.exists(tmp_dir): diff --git a/lyrebird_ios/ui.py b/lyrebird_ios/ui.py index e2c9d85..6ab48d0 100644 --- a/lyrebird_ios/ui.py +++ b/lyrebird_ios/ui.py @@ -96,6 +96,22 @@ def take_screen_shot(self, device_id): return context.make_fail_response('Could not start screenshot service! ' 'Please make sure the idevicescreenshot command works correctly') + def get_screen_shot(self): + screen_shots = [] + for item in device_service.devices: + device = device_service.devices[item] + self.take_screen_shot(item) + screen_shots.append( + { + 'id': item, + 'screenshot': { + 'name': device.model.replace(' ', '_'), + 'path': self.get_screenshot_image(item) + } + } + ) + lyrebird.publish('ios.screenshot', screen_shots, state=True) + def get_screenshot_image(self, device_id): return send_from_directory(tmp_dir, '%s.png' % device_service.devices.get(device_id).model.replace(' ', '_')) @@ -256,6 +272,8 @@ def on_create(self): self.add_url_rule('/api/check-env', view_func=self.check_env) # 启动设备监听服务 lyrebird.start_background_task(device_service.run) + # 订阅 cmd 消息,并开始截图 + lyrebird.subscribe('ios.cmd', self.get_screen_shot()) @staticmethod def get_icon(): diff --git a/setup.py b/setup.py index b8886ef..3446733 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='lyrebird-ios', - version='0.1.7', + version='0.1.8', packages=['lyrebird_ios'], url='https://github.com/meituan/lyrebird-ios', author='HBQA',