_adb_path.py 844 B

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright 2016 Google Inc.
  2. #
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. from _adb import Adb
  6. import re
  7. import subprocess
  8. __ADB = None
  9. def init(device_serial, adb_binary):
  10. global __ADB
  11. __ADB = Adb(device_serial, adb_binary)
  12. def join(*pathnames):
  13. return '/'.join(pathnames)
  14. def basename(pathname):
  15. return pathname.rsplit('/', maxsplit=1)[-1]
  16. def find_skps(skps):
  17. # root first, in case skps reside in a protected directory
  18. __ADB.root()
  19. escapedskps = [re.sub(r'([^a-zA-Z0-9_/\.\*\?\[\!\]])', r'\\\1', x)
  20. for x in skps]
  21. return __ADB.check('''\
  22. for PATHNAME in %s; do
  23. if [ -d "$PATHNAME" ]; then
  24. find "$PATHNAME" -maxdepth 1 -name *.skp
  25. else
  26. echo "$PATHNAME"
  27. fi
  28. done''' % ' '.join(escapedskps)).splitlines()