Skip to content

Commit

Permalink
fix bug - support iPhoneX (#23)
Browse files Browse the repository at this point in the history
* fix bug

* fix codacy issue
  • Loading branch information
zhaoye authored and yumiguan committed May 27, 2019
1 parent 501ae77 commit bf758d6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
9 changes: 7 additions & 2 deletions debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@


if __name__ == '__main__':
pip.main(['install', '.', '--upgrade'])
lyrebird.debug()
version_num = pip.__version__[:pip.__version__.find('.')]
if int(version_num) >= 10:
from pip import __main__
__main__._main(['install', '.', '--upgrade'])
else:
pip.main(['install', '.', '--upgrade'])
lyrebird.main()
26 changes: 13 additions & 13 deletions lyrebird_ios/device_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def __init__(self):
self.handle_interval = 1
self.devices = {}
self.reset_screenshot_dir()
print('DeviceService OnCreate')

def devices_to_dict(self):
json_obj = {}
Expand All @@ -31,15 +30,13 @@ def devices_to_dict(self):

def run(self):
self.status = self.RUNNING
print('iOS device listener start')
while self.status == self.RUNNING:
try:
self.handle()
context.application.socket_io.sleep(self.handle_interval)
except Exception as e:
_log.error(e)
self.status = self.STOP
print('iOS device listener stop')

def handle(self):
devices = ios_helper.devices()
Expand All @@ -62,7 +59,6 @@ def publish_devices_info_event(self, online_devices, app_name):
devices = []
for item in online_devices:
device_info = online_devices[item]
app_info = online_devices[item].get_app_info(app_name)
message_info = {
'id': device_info.device_id,
'info': {
Expand All @@ -72,23 +68,27 @@ def publish_devices_info_event(self, online_devices, app_name):
'sn': device_info.sn
},
}
if app_info.get('AppName'):
message_info['app'] = {
'name': app_info['AppName'],
'version': app_info['VersionNumber'],
'build': app_info['BuildNumber'],
'bundleID': app_info['BundleID']
}
devices.append(message_info)
try:
app_info = device_info.get_app_info(app_name)
if app_info.get('AppName'):
message_info['app'] = {
'name': app_info['AppName'],
'version': app_info['VersionNumber'],
'build': app_info['BuildNumber'],
'bundleID': app_info['BundleID']
}
except Exception:
_log.error('Can\'t read app info')

lyrebird.publish('ios.device', devices, state=True)

@staticmethod
def get_default_app_name():
plugin_conf = lyrebird.context.application.conf.get('plugin.ios', {})
default_bundle_id = plugin_conf.get('bundle_id', '')
return default_bundle_id

def reset_screenshot_dir(self):
if os.path.exists(ios_helper.screenshot_dir):
shutil.rmtree(ios_helper.screenshot_dir)
print('iOS device log file reset')
21 changes: 16 additions & 5 deletions lyrebird_ios/ios_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import os, plistlib, subprocess, threading, codecs, json, time
import os
import plistlib
import subprocess
import codecs
import json
import time
import lyrebird
from lyrebird import context
from lyrebird.log import get_logger
Expand Down Expand Up @@ -152,6 +157,7 @@ class Device:
"""
设备基类,主要属性包含 device_id, model, os_version等,主要方法包括截屏,获取信息等
"""

def __init__(self, device_id):
self.device_id = device_id
self.model = None
Expand Down Expand Up @@ -222,7 +228,7 @@ def device_info(self):
if not self._device_info:
self._device_info = self.get_properties()
return self._device_info

def start_app(self, bundle_id, ip, port):
ios_driver.bundle_id = bundle_id
ios_driver.environment = {
Expand All @@ -243,7 +249,7 @@ def stop_app(self):
except AttributeError as e:
pass
return str(e)
return
return

def get_properties(self):
p = subprocess.run(f'{ideviceinfo} -u {self.device_id}', shell=True, stdout=subprocess.PIPE)
Expand All @@ -260,7 +266,11 @@ def get_device_plist(self, device_id):
plist_path = '%s/%s.plist' % (PLIST_PATH, self.device_id)
if not os.path.exists(PLIST_PATH):
os.mkdir(PLIST_PATH)
p = subprocess.Popen(f'{ideviceinstaller} -u {self.device_id} -l -o xml > {plist_path}', shell=True)
if '-' in device_id:
_cmd = f'{ideviceinstaller} -l -o xml > {plist_path}'
else:
_cmd = f'{ideviceinstaller} -u {self.device_id} -l -o xml > {plist_path}'
p = subprocess.Popen(_cmd, shell=True)
p.wait()

def get_apps_list(self, device_id):
Expand All @@ -280,7 +290,8 @@ def take_screen_shot(self):
file_name = self.model.replace(' ', '_')
timestrap = int(time.time())
screen_shot_file = os.path.abspath(os.path.join(screenshot_dir, f'{file_name}_{timestrap}.png'))
p = subprocess.run(f'{idevicescreenshot} -u {self.device_id} {screen_shot_file}', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = subprocess.run(f'{idevicescreenshot} -u {self.device_id} {screen_shot_file}',
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
err_str = p.stdout.decode()
if p.returncode == 0:
return dict({
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='lyrebird-ios',
version='0.2.4',
version='0.2.5',
packages=['lyrebird_ios'],
url='https://github.com/meituan/lyrebird-ios',
author='HBQA',
Expand All @@ -28,7 +28,7 @@
'lyrebird_web': [
'iOS = lyrebird_ios.ui:MyUI'
]
},
},
install_requires=[
'lyrebird',
'facebook-wda'
Expand Down

0 comments on commit bf758d6

Please sign in to comment.