Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions ppadb/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
from pipes import quote as cmd_quote


def _get_src_info(src):
"""Get information about the contents of a folder; used in :meth:`Device.push`."""
exists = os.path.exists(src)
isfile = os.path.isfile(src)
isdir = os.path.isdir(src)
basename = os.path.basename(src)
walk = None if not isdir else list(os.walk(src))

return exists, isfile, isdir, basename, walk


class Device(Transport, Serial, Input, Utils, WM, Traffic, CPUStat, BatteryStats):
INSTALL_RESULT_PATTERN = "(Success|Failure|Error)\s?(.*)"
UNINSTALL_RESULT_PATTERN = "(Success|Failure.*|.*Unknown package:.*)"
Expand All @@ -55,24 +66,22 @@ def _push(self, src, dest, mode, progress):
sync.push(src, dest, mode, progress)

def push(self, src, dest, mode=0o644, progress=None):
if not os.path.exists(src):
exists, isfile, isdir, basename, walk = _get_src_info(src)
if not exists:
raise FileNotFoundError("Cannot find {}".format(src))
elif os.path.isfile(src):
self._push(src, dest, mode, progress)
elif os.path.isdir(src):

basename = os.path.basename(src)
if isfile:
self._push(src, dest, mode, progress)

for root, dirs, files in os.walk(src):
subdir = root.replace(src, "")
if subdir.startswith("/"):
subdir = subdir[1:]
root_dir_path = os.path.join(basename, subdir)
elif isdir:
for root, dirs, files in walk:
subdir = os.path.relpath(root, src)
root_dir_path = os.path.normpath(os.path.join(basename, subdir))

self.shell("mkdir -p {}/{}".format(dest, root_dir_path))
self.shell('mkdir -p "{}"'.format(os.path.normpath(os.path.join(dest, root_dir_path))))

for item in files:
self._push(os.path.join(root, item), os.path.join(dest, root_dir_path, item), mode, progress)
self._push(os.path.normpath(os.path.join(root, item)), os.path.normpath(os.path.join(dest, root_dir_path, item)), mode, progress)

def pull(self, src, dest):
sync_conn = self.sync()
Expand Down
18 changes: 5 additions & 13 deletions ppadb/device_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,10 @@
import os

from ppadb.command.transport_async import TransportAsync
from ppadb.device import _get_src_info
from ppadb.sync_async import SyncAsync


def _get_src_info(src):
exists = os.path.exists(src)
isfile = os.path.isfile(src)
isdir = os.path.isdir(src)
basename = os.path.basename(src)
walk = None if not isdir else list(os.walk(src))

return exists, isfile, isdir, basename, walk


class DeviceAsync(TransportAsync):
INSTALL_RESULT_PATTERN = "(Success|Failure|Error)\s?(.*)"
UNINSTALL_RESULT_PATTERN = "(Success|Failure.*|.*Unknown package:.*)"
Expand Down Expand Up @@ -54,12 +45,13 @@ async def push(self, src, dest, mode=0o644, progress=None):

elif isdir:
for root, dirs, files in walk:
root_dir_path = os.path.join(basename, root.replace(src, ""))
subdir = os.path.relpath(root, src)
root_dir_path = os.path.normpath(os.path.join(basename, subdir))

await self.shell("mkdir -p {}/{}".format(dest, root_dir_path))
await self.shell('mkdir -p "{}"'.format(os.path.normpath(os.path.join(dest, root_dir_path))))

for item in files:
await self._push(os.path.join(root, item), os.path.join(dest, root_dir_path, item), mode, progress)
await self._push(os.path.normpath(os.path.join(root, item)), os.path.normpath(os.path.join(dest, root_dir_path, item)), mode, progress)

async def pull(self, src, dest):
sync_conn = await self.sync()
Expand Down