Skip to content

Commit 0c84d22

Browse files
committed
Added async pull directory (no tests)
1 parent bea554f commit 0c84d22

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

ppadb/device.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def _pull(self, src, dest):
8181
return sync.pull(src, dest)
8282

8383
def pull(self, src, dest):
84-
# Currently will override dest-- desired?
8584
src = PurePosixPath(src)
8685
dest = Path(dest)
8786

@@ -102,6 +101,10 @@ def pull(self, src, dest):
102101
element_dest = dest / element
103102
self.pull(element_src, element_dest)
104103
else:
104+
file_string = "IS_FILE"
105+
res = self.shell(f"[ -f {src} ] && echo {file_string}")
106+
if file_string not in res:
107+
raise FileNotFoundError(f"Cannot find {src} on device")
105108
self._pull(str(src), str(dest))
106109

107110
def install(

ppadb/device_async.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,40 @@ async def push(self, src, dest, mode=0o644, progress=None):
5858
for item in files:
5959
await self._push(root / item, destdir / item, mode, progress)
6060

61-
async def pull(self, src, dest):
61+
async def _pull(self, src, dest):
6262
sync_conn = await self.sync()
6363
sync = SyncAsync(sync_conn)
6464

6565
async with sync_conn:
6666
return await sync.pull(src, dest)
6767

68+
async def pull(self, src, dest):
69+
src = PurePosixPath(src)
70+
dest = Path(dest)
71+
72+
dir_string = "IS_DIR"
73+
res = await self.shell(f"[ -d {src} ] && echo {dir_string}")
74+
if dir_string in res:
75+
# Get all files in the dir
76+
# Pull each
77+
dest.mkdir(exist_ok=True)
78+
cmd = f"ls -1a {src}"
79+
res = await self.shell(cmd)
80+
contents_list = res.split("\n")
81+
contents_list = [
82+
x for x in contents_list if x != "." and x != ".." and x != ""
83+
]
84+
for element in contents_list:
85+
element_src = src / element
86+
element_dest = dest / element
87+
await self.pull(element_src, element_dest)
88+
else:
89+
file_string = "IS_FILE"
90+
res = await self.shell(f"[ -f {src} ] && echo {file_string}")
91+
if file_string not in res:
92+
raise FileNotFoundError(f"Cannot find {src} on device")
93+
await self._pull(str(src), str(dest))
94+
6895
async def install(
6996
self,
7097
path,

test/test_device.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,13 @@ def test_pull_recursive_dir(populated_device, working_dir, test_filepaths):
247247
assert to_check.is_file()
248248
assert to_check.read_text() == f"{path}\n"
249249

250+
def test_pull_nonexisting(device, working_dir):
251+
src = "data/local/tmp/dklsfalkjhvcnsdfalvfds"
252+
with pytest.raises(Exception) as excinfo:
253+
device.pull(src, working_dir / "non_existent")
254+
255+
assert str(excinfo.value) == f"Cannot find {src} on device"
256+
250257

251258
def test_forward(device):
252259
device.killforward_all()

0 commit comments

Comments
 (0)