From 2971ffb19246aef0a1182579c60f84730920b487 Mon Sep 17 00:00:00 2001 From: yumiguan <41277086+yumiguan@users.noreply.github.com> Date: Fri, 12 Oct 2018 10:18:56 +0800 Subject: [PATCH] Modify way to get default application (#13) * Modify the way to get default application * update version name --- dev.sh | 26 +++++++++++++ .../config/comparison_table_model.json | 10 ++--- lyrebird_ios/ios_helper.py | 37 +------------------ lyrebird_ios/templates/index.html | 29 +++++---------- lyrebird_ios/ui.py | 30 +++++---------- setup.py | 2 +- 6 files changed, 52 insertions(+), 82 deletions(-) create mode 100644 dev.sh diff --git a/dev.sh b/dev.sh new file mode 100644 index 0000000..c77cf87 --- /dev/null +++ b/dev.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +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 + +source ./venv/bin/activate +pip3 install -r ./requirements.txt + +echo "***************************" +echo " iOS setup finish " +echo "***************************" diff --git a/lyrebird_ios/config/comparison_table_model.json b/lyrebird_ios/config/comparison_table_model.json index 46e55b8..4f1c2bc 100644 --- a/lyrebird_ios/config/comparison_table_model.json +++ b/lyrebird_ios/config/comparison_table_model.json @@ -4,11 +4,11 @@ "iPhone3,3": "iPhone 4", "iPhone4,1": "iPhone 4S", "iPhone5,1": "iPhone 5", - "iPhone5,2": "iPhone 5 (GSM+CDMA)", - "iPhone5,3": "iPhone 5c (GSM)", - "iPhone5,4": "iPhone 5c (GSM+CDMA)", - "iPhone6,1": "iPhone 5s (GSM)", - "iPhone6,2": "iPhone 5s (GSM+CDMA)", + "iPhone5,2": "iPhone 5 GSM+CDMA", + "iPhone5,3": "iPhone 5c GSM", + "iPhone5,4": "iPhone 5c GSM+CDMA", + "iPhone6,1": "iPhone 5s GSM", + "iPhone6,2": "iPhone 5s GSM+CDMA", "iPhone7,1": "iPhone 6 Plus", "iPhone7,2": "iPhone 6", "iPhone8,1": "iPhone 6s", diff --git a/lyrebird_ios/ios_helper.py b/lyrebird_ios/ios_helper.py index 2ff2b46..d1e978c 100644 --- a/lyrebird_ios/ios_helper.py +++ b/lyrebird_ios/ios_helper.py @@ -158,7 +158,7 @@ def __init__(self, device_id): self._log_cache = [] self._log_crash_cache = [] self._log_file = None - self._screen_shot_file = os.path.abspath(os.path.join(tmp_dir, 'android_screenshot_%s.png' % self.device_id)) + self._screen_shot_file = None self._anr_file = None self._crash_file_list = [] self._device_info = None @@ -191,7 +191,6 @@ def read_line(cls, line): _device = cls(line) if len(device_info) < 2: _log.error(f'Read device info line error. {lines}') - raise libimobiledeviceError('Failed to got device info, Please make sure \'deviceinfo\' command is working on your system.') for info in device_info: info_kv = info.split(':') if info_kv[0] == 'ProductType': @@ -231,8 +230,6 @@ def log_handler(logcat_process): log_file.close() return - # self.crash_checker(line) - # self.anr_checker(line) self._log_cache.append(line.decode(encoding='UTF-8', errors='ignore')) if len(self._log_cache) >= 5000: @@ -242,24 +239,6 @@ def log_handler(logcat_process): self._log_cache = [] threading.Thread(target=log_handler, args=(p,)).start() - def crash_checker(self, line): - crash_log_path = os.path.join(crash_dir, 'android_crash_%s.log' % self.device_id) - - if str(line).find('FATAL EXCEPTION') > 0: - self.start_catch_log = True - self._log_crash_cache.append(str(line)) - lyrebird.publish('crash', 'android', path=crash_log_path, id=self.device_id) - elif str(line).find('AndroidRuntime') > 0 and self.start_catch_log: - self._log_crash_cache.append(str(line)) - else: - self.start_catch_log = False - with codecs.open(crash_log_path, 'w') as f: - f.write('\n'.join(self._log_crash_cache)) - - def anr_checker(self, line): - if str(line).find('ANR') > 0 and str(line).find('ActivityManager') > 0: - self.get_anr_log() - @property def device_info(self): if not self._device_info: @@ -309,20 +288,6 @@ def to_dict(self): prop_lines = self.device_info if not prop_lines: return device_info - - for line in prop_lines: - # 基带版本 - if 'ro.build.expect.baseband' in line: - baseband = line[line.rfind('[')+1:line.rfind(']')].strip() - device_info['baseBand'] = baseband - # 版本号 - if 'ro.build.id' in line: - build_id = line[line.rfind('[') + 1:line.rfind(']')].strip() - device_info['buildId'] = build_id - # Android 版本 - if 'ro.build.version.release' in line: - build_version = line[line.rfind('[') + 1:line.rfind(']')].strip() - device_info['releaseVersion'] = build_version return device_info diff --git a/lyrebird_ios/templates/index.html b/lyrebird_ios/templates/index.html index fb012cd..c8bcbd2 100644 --- a/lyrebird_ios/templates/index.html +++ b/lyrebird_ios/templates/index.html @@ -190,7 +190,7 @@ status: false, isStop: false, starting: false, - defaultApp: "com.meituan.imeituan-beta", + defaultApp: "", spinnerStatus: false, appInfo: {}, devices: {}, @@ -208,7 +208,6 @@ var getDevices = this.getDevices; sio.on('device', function (data) { - console.log('Update device list'); getDevices(); }); }, @@ -221,22 +220,20 @@ fetch(apiUrl + '/check-env') .then(res => res.json()) .then(json => { - console.log('Got response: ' + json); this.showError = json.show_error; this.userMsg = json.user_message; this.loading = false }) .catch(err => console.warn(err)); }, - get_default_app() { - fetch(apiUrl + '/conf') - .then(res => res.json()) - .then(json => { - console.log('Got response: ' + json); - this.defaultApp = json.default_app; - this.loading = false - }) - .catch(err => console.warn(err)); + get_default_app: function() { + this.$http.get(apiUrl + '/conf') + .then(function (response) { + console.log('default app:', response.data); + if(response.data){ + this.defaultApp = response.data; + } + }); }, maybeLoad() { return Object.keys(this.options).length <= 0 ? this.load() : null @@ -246,7 +243,6 @@ fetch(apiUrl + '/apps/' + this.currentDevice.device_id) .then(res => res.json()) .then(json => { - console.log('Got response: ' + json); this.options = json; this.loading = false }) @@ -262,7 +258,6 @@ fetch(apiUrl + '/apps/' + this.currentDevice.device_id + '/' + bundle_id) .then(res => res.json()) .then(json => { - console.log('Got response: ' + json); this.appInfo = json; this.loading = false }) @@ -270,16 +265,13 @@ }, getDevices: function () { this.$http.get(apiUrl + '/devices').then(function (response) { - console.info("api/device got response", response.data); this.devices = response.data; }); }, getDeviceDetail: function () { - console.log('get device detail'); this.$http.get(apiUrl + '/device/' + this.currentDevice.device_id) .then(function (response) { this.currentDeviceDetail = response.data; - console.log(response.data) }); if (this.packageName){ this.getAppInfo(); @@ -299,14 +291,11 @@ }); }, showDeviceInfo: function (device_id) { - console.info('vue show device info ', device_id); if (this.currentDevice !== this.devices[device_id]) { this.logs = []; this.currentDevice = this.devices[device_id]; -// sio.emit('log-start', this.currentDevice.device_id) } this.getDeviceDetail(); -// this.takeScreenShot(); }, } }) diff --git a/lyrebird_ios/ui.py b/lyrebird_ios/ui.py index 03a46b8..b69b59b 100644 --- a/lyrebird_ios/ui.py +++ b/lyrebird_ios/ui.py @@ -42,14 +42,16 @@ def info(self): device_prop = device.to_dict() device_info['device'] = {'UDID': device_prop['device_id'], 'Model': device_prop['model'], 'Version': device_prop['os_version']} - plugin_conf = lyrebird.context.application.conf.get('plugin.ios') - if not plugin_conf: - default_bundle_id = '' - default_bundle_id = plugin_conf.get('default_bundle_id') - + plugin_conf = lyrebird.context.application.conf.get('plugin.ios', {}) + default_bundle_id = plugin_conf.get('bundle_id', '') device_info['app'] = device.get_app_info(default_bundle_id) return jsonify(device_info) - + + def conf(self): + plugin_conf = lyrebird.context.application.conf.get('plugin.ios', {}) + default_bundle_id = plugin_conf.get('bundle_id', '') + return jsonify(default_bundle_id) + def device_list(self): return jsonify(device_service.devices_to_dict()) @@ -134,18 +136,6 @@ def dump_data(self): return jsonify(res) - def dump(self, device_id): - """ - 保存截图 设备信息 日志 app信息 - :param device_id: - :return: 所有信息文件绝对路径 json list - """ - device = device_service.devices.get(device_id) - if device: - device.take_screen_shot() - - return jsonify([device.log_file, device.screen_shot_file, self.get_app_info_file_path(device), self.get_prop_file_path(device, device_id)]) - def get_prop_file_path(self, device, device_id): device_prop_file_path = os.path.abspath(os.path.join(tmp_dir, '%s.info.txt' % device_id)) device_prop = device.device_info @@ -186,8 +176,6 @@ def on_create(self): self.add_url_rule('/api/info', view_func=self.info) # for Bugit self.add_url_rule('/api/desc', view_func=self.desc) - # Dump所有信息 - # self.add_url_rule('/api/dump/', view_func=self.dump) # 获取设备列表 self.add_url_rule('/api/devices', view_func=self.device_list) # 设备详情 @@ -208,6 +196,8 @@ def on_create(self): self.add_url_rule('/api/dump', view_func=self.dump_data) # 检查环境 self.add_url_rule('/api/check-env', view_func=self.check_env) + # 获取默认配置 + self.add_url_rule('/api/conf', view_func=self.conf) # 启动设备监听服务 lyrebird.start_background_task(device_service.run) # 订阅 cmd 消息,并开始截图 diff --git a/setup.py b/setup.py index 3da54c0..294a276 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='lyrebird-ios', - version='0.1.11', + version='0.1.12', packages=['lyrebird_ios'], url='https://github.com/meituan/lyrebird-ios', author='HBQA',