Skip to content

Commit

Permalink
v0.3.6 find idevice binary from path (#45)v
Browse files Browse the repository at this point in the history
* find idevice binary from  path

* rm unused code
  • Loading branch information
zhaoye authored Nov 27, 2020
1 parent 546233a commit 4ea2ef4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
30 changes: 10 additions & 20 deletions lyrebird_ios/ios_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import plistlib
import tempfile
import subprocess
from pathlib import Path
from packaging import version
import lyrebird
from lyrebird.log import get_logger
from . import wda_helper
Expand All @@ -24,7 +22,6 @@
screenshot_dir = os.path.abspath(os.path.join(storage, 'screenshot'))

PLIST_PATH = os.path.join(storage, 'plist')
SYSTEM_BIN = Path('/usr/local/bin')

ios_driver = wda_helper.Helper()

Expand All @@ -37,36 +34,32 @@ def check_environment():
global ideviceinstaller, idevice_id, idevicescreenshot, ideviceinfo

# Check idevice_id, action when unavailable : block
idevice_id_keywords = 'idevice_id'
idevice_id = SYSTEM_BIN/idevice_id_keywords
err_msg = check_environment_item(idevice_id_keywords, idevice_id)
idevice_id = 'idevice_id'
err_msg = check_environment_item(idevice_id)
if err_msg:
idevice_id = None
raise IdeviceidError(err_msg)

# Check ideviceinfo, action when unavailable : block
ideviceinfo_keywords = 'ideviceinfo'
ideviceinfo = SYSTEM_BIN/ideviceinfo_keywords
err_msg = check_environment_item(ideviceinfo_keywords, ideviceinfo)
ideviceinfo = 'ideviceinfo'
err_msg = check_environment_item(ideviceinfo)
if err_msg:
ideviceinfo = None
raise IdeviceinfoError(err_msg)

env_err_msg = []

# Check ideviceinstaller, action when unavailable : warning
ideviceinstaller_keywords = 'ideviceinstaller'
ideviceinstaller = SYSTEM_BIN/ideviceinstaller_keywords
err_msg = check_environment_item(ideviceinstaller_keywords, ideviceinstaller)
ideviceinstaller = 'ideviceinstaller'
err_msg = check_environment_item(ideviceinstaller)
if err_msg:
env_err_msg.append(err_msg)
ideviceinstaller = None

# Check idevicescreenshot, action when unavailable : warning
idevicescreenshot_keywords = 'idevicescreenshot'
idevicescreenshot = SYSTEM_BIN/idevicescreenshot_keywords
idevicescreenshot = 'idevicescreenshot'
temp_file = tempfile.NamedTemporaryFile().name
err_msg = check_environment_item(idevicescreenshot_keywords, idevicescreenshot, sub_command=temp_file)
err_msg = check_environment_item(idevicescreenshot, sub_command=temp_file)
if err_msg:
env_err_msg.append(err_msg)
idevicescreenshot = None
Expand All @@ -75,11 +68,8 @@ def check_environment():
_log.error('iOS Plugin environment warning:\n' + '.\n'.join(env_err_msg))


def check_environment_item(command, path, sub_command=''):
if not Path(path).exists():
return f'Command `{command}` not found, check your libimobiledevice'

p = subprocess.run(f'{str(path)} {sub_command}', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def check_environment_item(command, sub_command=''):
p = subprocess.run(f'{command} {sub_command}', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
err_str = p.stderr.decode()
return f'Execute command `{command}` error: {err_str}' if err_str else ''

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.5',
version='0.3.6',
packages=['lyrebird_ios'],
url='https://github.com/meituan/lyrebird-ios',
author='HBQA',
Expand Down

0 comments on commit 4ea2ef4

Please sign in to comment.