Skip to content

Commit

Permalink
add env check (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
yumiguan authored Apr 29, 2020
1 parent 5e48725 commit 2dee131
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 15 deletions.
6 changes: 6 additions & 0 deletions frontend/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const errorHandler = (error) => {

axios.interceptors.response.use(successHandler, errorHandler)

export const checkEnv = () => {
return axios({
url: API_PREFIX + '/check_env'
})
}

export const getDevices = () => {
return axios({
url: API_PREFIX + '/devices'
Expand Down
14 changes: 12 additions & 2 deletions frontend/src/components/iOS.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import DeviceList from '@/components/DeviceList.vue'
import DeviceInfo from '@/components/DeviceInfo.vue'
import ScreenShot from '@/components/ScreenShot.vue'
import PackageInfo from '@/components/PackageInfo.vue'
import { checkEnv } from '@/api'
export default {
components: {
Expand All @@ -38,8 +39,7 @@ export default {
}
},
created () {
this.$store.dispatch('loadDevices')
this.$io.on('device_ios', this.getDevices)
this.checkEnvironment()
this.$bus.$on('msg.success', this.successMessage)
this.$bus.$on('msg.info', this.infoMessage)
this.$bus.$on('msg.error', this.errorMessage)
Expand All @@ -50,6 +50,16 @@ export default {
}
},
methods: {
checkEnvironment () {
checkEnv()
.then(
this.$store.dispatch('loadDevices'),
this.$io.on('ios-device', this.getDevices)
)
.catch(error => {
this.$bus.$emit('msg.error', error.data.message)
})
},
getDevices () {
this.$store.dispatch('loadDevices')
},
Expand Down
7 changes: 5 additions & 2 deletions lyrebird_ios/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ def get_screenshot_image(device_id):
return None

def check_env():
from .ios_helper import error_msg
return jsonify(error_msg)
msg = device_service.check_env()
if device_service.status == device_service.RUNNING:
return make_ok_response()
else:
return make_fail_response(msg)


def _get_ip():
Expand Down
14 changes: 12 additions & 2 deletions lyrebird_ios/device_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,24 @@ def __init__(self):
self.devices = {}
self.reset_screenshot_dir()

def check_env(self):
error_message = ios_helper.check_environment()
if not error_message:
self.status = self.RUNNING
_log.debug('iOS device listener start')
else:
self.status = self.STOP
_log.error(error_message)
return error_message

def devices_to_dict(self):
json_obj = {}
for device_id in self.devices:
json_obj[device_id] = self.devices[device_id].to_dict()
return json_obj

def run(self):
self.status = self.RUNNING
self.check_env()
while self.status == self.RUNNING:
try:
self.handle()
Expand All @@ -46,7 +56,7 @@ def handle(self):

self.devices = devices
self.publish_devices_info_event(self.devices, self.get_default_app_name())
lyrebird.emit('device_ios')
lyrebird.emit('ios-device')

def start_log_recorder(self, device_id):
for _device_id in self.devices:
Expand Down
11 changes: 4 additions & 7 deletions lyrebird_ios/ios_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
screenshot_dir = os.path.abspath(os.path.join(storage, 'screenshot'))

PLIST_PATH = os.path.join(storage, 'plist')
error_msg = None

ios_driver = wda_helper.Helper()

Expand All @@ -31,18 +30,18 @@ def check_environment():
检查用户环境,第三方依赖是否正确安装。
:return:
"""
global idevice_id, idevicescreenshot, ideviceinfo, error_msg
global idevice_id, idevicescreenshot, ideviceinfo

if not os.path.exists('/usr/local/bin/ideviceinfo'):
_log.error('ideviceinfo command not found, check your libimobiledevice')
return 'ideviceinfo command not found, check your libimobiledevice'
else:
p = subprocess.Popen('/usr/local/bin/ideviceinfo', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
err = p.stderr.read().decode()
if len(err):
_log.error(f'Something wrong with the ideviceinfo program: {err}')
return f'Something wrong with the ideviceinfo program: {err}'

if not os.path.exists('/usr/local/bin/idevicescreenshot'):
_log.debug('ideviceinfo command not found, check your libimobiledevice')
return 'ideviceinfo command not found, check your libimobiledevice'

idevice_id = '/usr/local/bin/idevice_id'
ideviceinfo = '/usr/local/bin/ideviceinfo'
Expand Down Expand Up @@ -264,8 +263,6 @@ def devices():
:type dict
:return: online_devices object of online devices
"""
check_environment()

res = subprocess.run(f'{idevice_id} -l', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = res.stdout.decode()
err_str = res.stderr.decode()
Expand Down
2 changes: 1 addition & 1 deletion lyrebird_ios/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# get application list
('/api/apps/<string:device_id>', apis.app_list, ['GET']),
# environment check
('/api/check-env', apis.check_env, ['GET']),
('/api/check_env', apis.check_env, ['GET']),
# get config
('/api/conf', apis.conf, ['GET'])
],
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.3.0',
version='0.3.1',
packages=['lyrebird_ios'],
url='https://github.com/meituan/lyrebird-ios',
author='HBQA',
Expand Down

0 comments on commit 2dee131

Please sign in to comment.