Skip to content

Commit

Permalink
Update README.md; use _sync.rmtree for rm operation; other fixs
Browse files Browse the repository at this point in the history
  • Loading branch information
vdavdev committed Mar 26, 2022
1 parent dc62430 commit 5a65bf4
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 27 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ QQ交流群: _134535547_ (进群答案: ios)
- 模拟Xcode运行XCTest,常用的如启动WebDriverAgent测试(此方法不依赖xcodebuild)
- 获取指定应用性能(CPU,MEM,FPS)
- 文件操作
- Crash日志操作
- 其他

支持运行在Mac,Linux,Windows上
Expand Down Expand Up @@ -292,6 +293,26 @@ $ tidevice fsync -h
# com.duokan.reader 多看阅读
```

### Crash日志操作
```bash

# 查看Crash日志列表
$ tidevice crash ls

# 复制Crash日志文件,默认输出到crashes文件夹
$ tidevice crash cp

# 复制Crash日志文件,自定义输出目录
$ tidevice crash cp -O myOutputDir

# 移动Crash日志文件,默认输出到crashes文件夹。可自定义位置
$ tidevice crash mv

# 清空设备端的Crash日志
$ tidevice crash rm

```

### 其他常用
```bash
# 重启
Expand Down
21 changes: 21 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Command line tool to communicate with iOS device, support the following function
- retrieve performance data
- simulate run xctest, eg: WebDriverAgent
- file operation
- crash log operation
- other

Support platform: Mac, Linux, Windows
Expand Down Expand Up @@ -265,6 +266,26 @@ $ tidevice fsync -h
```


### Crash log operation
```bash

# List crash log files on device
$ tidevice crash ls

# Copy crash log files from device, default output dir: crashes
$ tidevice crash cp

# Copy crash log files from device, with custom output dir
$ tidevice crash cp -O myOutputDir

# Move crash log files from device, default output dir: crashes
$ tidevice crash mv

# Remove crash log files on device
$ tidevice crash rm

```

### Other
```bash
# reboot device
Expand Down
2 changes: 1 addition & 1 deletion tidevice/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ def cmd_test(args: argparse.Namespace):
flags=[
dict(args=['command'],
choices=[
'ls', 'cp', 'mv', 'del'
'ls', 'cp', 'mv', 'rm'
]),
dict(
args=['-o', '--out'],
Expand Down
28 changes: 7 additions & 21 deletions tidevice/_crash.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
from ._sync import Sync
import logging
from ._proto import LOG
from ._safe_socket import PlistSocket


logger = logging.getLogger(LOG.main)

# Ref: https://github.com/libimobiledevice/libimobiledevice/blob/master/tools/idevicecrashreport.c

class CrashManager(object):
def __init__(self, move_conn, copy_conn, output_dir):
def __init__(self, move_conn: PlistSocket, copy_conn: PlistSocket, output_dir: str):
self._afc = None
self._move_coon = move_conn
self._move_conn = move_conn
self._copy_conn = copy_conn
self._output_dir = output_dir

Expand All @@ -22,7 +23,7 @@ def __init__(self, move_conn, copy_conn, output_dir):

def _flush(self):
ack = b'ping\x00'
assert ack == self._move_coon.recvall(len(ack))
assert ack == self._move_conn.recvall(len(ack))

def preview(self):
logger.info("List of crash logs:")
Expand All @@ -41,21 +42,6 @@ def move(self):
self._afc.rmtree("/")
logger.info("Crash file moved to '{}' from device".format(self._output_dir))

def delete(self):
self._remove_file("/")
logger.info("Crash file purged from device")

def _remove_file(self, dir_path):
files = self._afc.listdir(dir_path)
for file in files:
if dir_path == "/":
file = "/{}".format(file)
else:
file = "{}/{}".format(dir_path, file)
file_st = self._afc.stat(file)

if file_st.is_dir():
self._remove_file(file)
else:
self._afc.remove(file)
self._afc.rmdir(dir_path)
def remove(self):
self._afc.rmtree("/")
logger.info("Crash file purged from device")
4 changes: 2 additions & 2 deletions tidevice/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ def execute_crash_commands(self, output_dir, command):
cm.copy()
elif command == 'mv':
cm.move()
elif command == 'del':
cm.delete()
elif command == 'rm':
cm.remove()

def start_service(self, name: str) -> PlistSocket:
try:
Expand Down
7 changes: 4 additions & 3 deletions tidevice/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,10 @@ def rmtree(self, dpath: str) -> list:
if info.is_dir:
rmfiles = []
for fname in self.listdir(dpath):
fpath = dpath.rstrip("/") + "/" + fname
files = self.rmtree(fpath)
rmfiles.extend(files)
if (fname != ""):
fpath = dpath.rstrip("/") + "/" + fname
files = self.rmtree(fpath)
rmfiles.extend(files)
rmfiles.append(dpath + "/")
self.rmdir(dpath)
return rmfiles
Expand Down

0 comments on commit 5a65bf4

Please sign in to comment.