Skip to content

Commit

Permalink
Add tidevice tool for screenshot. (#64)
Browse files Browse the repository at this point in the history
* Add tidevice tool for screenshot.

* Modify the way to use tidevice

* Catch exception by tidevice-screenshot.
  • Loading branch information
Rena-Yuan authored Mar 28, 2022
1 parent 65e9eaa commit 4771bea
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
```bash
ideviceinfo
idevicescreenshot
idevicesinstaller -l
ideviceinstaller -l
```

### 安装
Expand Down
2 changes: 1 addition & 1 deletion lyrebird_ios/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def take_screen_shot(device_id):
device = device_service.devices.get(device_id)
img_info = device.take_screen_shot()
if img_info['returncode'] != 0:
return make_fail_response(img_info['result'].stdout.decode())
return make_fail_response(img_info['stdout'])
timestamp = img_info.get('timestamp')
return make_ok_response(imgUrl=f'/plugins/ios/api/src/screenshot/{device_id}?time={timestamp}')

Expand Down
25 changes: 21 additions & 4 deletions lyrebird_ios/ios_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import plistlib
import tempfile
import subprocess
import traceback
import lyrebird
from lyrebird.log import get_logger
from . import wda_helper
Expand Down Expand Up @@ -271,13 +272,29 @@ def take_screen_shot(self):
screen_shot_file = os.path.abspath(os.path.join(screenshot_dir, f'{file_name}_{timestamp}.png'))
p = subprocess.run(f'{idevicescreenshot} -u {self.device_id} {screen_shot_file}',
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = {
'returncode': p.returncode,
'result': p,
if p.returncode == 0:
return {
'returncode': p.returncode,
'stdout': p.stdout.decode(),
'screen_shot_file': screen_shot_file,
'timestamp': timestamp
}
import tidevice
try:
img = tidevice.Device(self.device_id).screenshot()
except AssertionError as e:
return_code = 1
stdout = f'Fail to get screenshot by tidevice.\n {str(e)}\n {traceback.format_exc()}'
else:
img.save(screen_shot_file)
return_code = 0
stdout = 'Success'
return {
'returncode': return_code,
'stdout': stdout,
'screen_shot_file': screen_shot_file,
'timestamp': timestamp
}
return result

def to_dict(self):
device_info = {k: self.__dict__[k] for k in self.__dict__ if not k.startswith('_')}
Expand Down
5 changes: 3 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.3.8',
version='0.3.9',
packages=['lyrebird_ios'],
url='https://github.com/meituan/lyrebird-ios',
author='HBQA',
Expand All @@ -29,7 +29,8 @@
},
install_requires=[
'lyrebird',
'facebook-wda==0.8.1'
'facebook-wda==0.8.1',
'tidevice==0.6.12'
],
extras_require={
'dev': [
Expand Down

0 comments on commit 4771bea

Please sign in to comment.