Skip to content

Commit

Permalink
Add event for devices, apps and screenshot (#5)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
yury-awesome authored Aug 28, 2018
1 parent 770944c commit 5189da4
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 是其插件之一,您可以在插件中快速查看已连接设备的详细设备信息,截取屏幕快照,以及查看已连接设备的应用信息。

## 特性
Expand Down
35 changes: 35 additions & 0 deletions lyrebird_ios/device_service.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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):
Expand All @@ -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 ''
3 changes: 1 addition & 2 deletions lyrebird_ios/ios_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 18 additions & 0 deletions lyrebird_ios/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ', '_'))

Expand Down Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 5189da4

Please sign in to comment.