Merge pull request #24146 from drodriguez/android-faster-adb-push

[android] Make ADB push use sync if available.
This commit is contained in:
Daniel Rodríguez Troitiño
2019-04-30 17:42:02 -07:00
committed by GitHub
2 changed files with 25 additions and 9 deletions

View File

@@ -44,10 +44,24 @@ def rmdir(path):
shell(['rm', '-rf', '{}/*'.format(path)])
def push(local_path, device_path):
"""Move the file at the given local path to the path on the device."""
return subprocess.check_output(['adb', 'push', local_path, device_path],
stderr=subprocess.STDOUT).strip()
def push(local_paths, device_path):
"""Move the files at the given local paths to the path on the device."""
if isinstance(local_paths, str):
local_paths = [local_paths]
try:
# In recent versions of ADB, push supports --sync, which checksums the
# files to be transmitted and skip the ones that haven't changed, which
# improves the effective transfer speed.
return subprocess.check_output(
['adb', 'push', '--sync'] + local_paths + [device_path],
stderr=subprocess.STDOUT).strip()
except subprocess.CalledProcessError as e:
if "unrecognized option '--sync'" in e.output:
return subprocess.check_output(
['adb', 'push'] + local_paths + [device_path],
stderr=subprocess.STDOUT).strip()
else:
raise e
def reboot():

View File

@@ -53,9 +53,9 @@ def argument_parser():
return parser
def _push(source, destination):
print('Pushing "{}" to device path "{}".'.format(source, destination))
print(adb.commands.push(source, destination))
def _push(sources, destination):
print('Pushing "{}" to device path "{}".'.format(sources, destination))
print(adb.commands.push(sources, destination))
def main():
@@ -70,8 +70,10 @@ def main():
for path in args.paths:
if os.path.isdir(path):
for basename in glob.glob(os.path.join(path, '*.so')):
_push(os.path.join(path, basename), args.destination)
full_paths = [
os.path.join(path, basename)
for basename in glob.glob(os.path.join(path, '*.so'))]
_push(full_paths, args.destination)
else:
_push(path, args.destination)