Skip to content

Commit

Permalink
add function: Start App (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
yumiguan authored Oct 29, 2018
1 parent 1c3e6e7 commit e6e3c17
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 12,626 deletions.
23 changes: 10 additions & 13 deletions dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@ echo "***************************"
echo " iOS setup start "
echo "***************************"

# 如果已经有venv目录,删除此目录
if [ -e "./venv/" ]; then
rm -rf ./venv/
fi

mkdir venv
python3 -m venv ./venv

# 有些设备上虚拟环境中没有pip,需要通过easy_install安装
if [ ! -e "./venv/bin/pip" ] ;then
echo "pip no exist, install pip with easy_install"
./venv/bin/easy_install pip
fi
# create python virtual environment
python3 -m venv --clear venv

# activate virtual environment
source ./venv/bin/activate

# install from requirements.txt
pip3 install -r ./requirements.txt

# create data dir for debug
if [ ! -e "./data/" ]; then
mkdir ./data
fi

echo "***************************"
echo " iOS setup finish "
echo "***************************"
6 changes: 3 additions & 3 deletions lyrebird_ios/device_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def handle(self):
return

self.devices = devices
self.publish_devices_info_event(self.devices)
self.publish_devices_info_event(self.devices, self.get_default_app_name())
context.application.socket_io.emit('device', namespace='/iOS-plugin')

def start_log_recorder(self, device_id):
Expand All @@ -55,11 +55,11 @@ def start_log_recorder(self, device_id):
else:
self.devices[_device_id].stop_log()

def publish_devices_info_event(self, online_devices):
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(self.get_default_app_name())
app_info = online_devices[item].get_app_info(app_name)
message_info = {
'id': device_info.device_id,
'info': {
Expand Down
53 changes: 25 additions & 28 deletions lyrebird_ios/ios_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import lyrebird
from lyrebird import context
from lyrebird.log import get_logger
from . import wda_helper

_log = get_logger()

Expand All @@ -22,6 +23,8 @@
PLIST_PATH = os.path.join(storage, 'plist')
error_msg = None

ios_driver = wda_helper.Helper()

if not os.path.exists(tmp_dir):
os.makedirs(tmp_dir)

Expand Down Expand Up @@ -213,39 +216,33 @@ def convert_model(self, model):
model_dict = json.loads(codecs.open(model_json, 'r', 'utf-8').read())
return model_dict.get(model)

def start_log(self):
self.stop_log()

log_file_name = 'ios_log_%s.log' % self.device_id
self._log_file = os.path.abspath(os.path.join(tmp_dir, log_file_name))

p = subprocess.Popen(f'{idevicesyslog} -u {self.device_id}', shell=True, stdout=subprocess.PIPE)

def log_handler(logcat_process):
log_file = codecs.open(self._log_file, 'w', 'utf-8')

while True:
line = logcat_process.stdout.readline()

if not line:
context.application.socket_io.emit('log', self._log_cache, namespace='/iOS-plugin')
log_file.close()
return

self._log_cache.append(line.decode(encoding='UTF-8', errors='ignore'))

if len(self._log_cache) >= 5000:
context.application.socket_io.emit('log', self._log_cache, namespace='/iOS-plugin')
log_file.writelines(self._log_cache)
log_file.flush()
self._log_cache = []
threading.Thread(target=log_handler, args=(p,)).start()

@property
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 = {
'mock': f'http://{ip}:{port}/mock',
'closeComet': True,
'urlscheme': True
}
try:
ios_driver.start_app()
except Exception as e:
pass
return str(e)
return ''

def stop_app(self):
try:
ios_driver.stop_app()
except AttributeError as e:
pass
return str(e)
return

def get_properties(self):
p = subprocess.run(f'{ideviceinfo} -u {self.device_id}', shell=True, stdout=subprocess.PIPE)
Expand Down
Loading

0 comments on commit e6e3c17

Please sign in to comment.