csmartdalton | 0262b5c | 2016-09-19 12:04:56 -0700 | [diff] [blame] | 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 | |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 6 | from _adb import Adb |
csmartdalton | 0262b5c | 2016-09-19 12:04:56 -0700 | [diff] [blame] | 7 | import re |
| 8 | import subprocess |
| 9 | |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 10 | __ADB = None |
csmartdalton | 0262b5c | 2016-09-19 12:04:56 -0700 | [diff] [blame] | 11 | |
Kevin Lubick | cccaef1 | 2017-10-13 08:15:09 -0400 | [diff] [blame] | 12 | def init(device_serial, adb_binary): |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 13 | global __ADB |
Kevin Lubick | cccaef1 | 2017-10-13 08:15:09 -0400 | [diff] [blame] | 14 | __ADB = Adb(device_serial, adb_binary) |
csmartdalton | 0262b5c | 2016-09-19 12:04:56 -0700 | [diff] [blame] | 15 | |
| 16 | def join(*pathnames): |
| 17 | return '/'.join(pathnames) |
| 18 | |
| 19 | def basename(pathname): |
| 20 | return pathname.rsplit('/', maxsplit=1)[-1] |
| 21 | |
| 22 | def find_skps(skps): |
Chris Dalton | 117d972 | 2018-04-27 17:10:39 -0600 | [diff] [blame^] | 23 | # root first, in case skps reside in a protected directory |
| 24 | __ADB.root() |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 25 | escapedskps = [re.sub(r'([^a-zA-Z0-9_/\.\*\?\[\!\]])', r'\\\1', x) |
csmartdalton | 0262b5c | 2016-09-19 12:04:56 -0700 | [diff] [blame] | 26 | for x in skps] |
csmartdalton | e4fd078 | 2016-11-09 08:41:23 -0800 | [diff] [blame] | 27 | return __ADB.check('''\ |
csmartdalton | 0262b5c | 2016-09-19 12:04:56 -0700 | [diff] [blame] | 28 | for PATHNAME in %s; do |
| 29 | if [ -d "$PATHNAME" ]; then |
csmartdalton | 5745d79 | 2016-09-22 12:37:21 -0700 | [diff] [blame] | 30 | find "$PATHNAME" -maxdepth 1 -name *.skp |
csmartdalton | 0262b5c | 2016-09-19 12:04:56 -0700 | [diff] [blame] | 31 | else |
| 32 | echo "$PATHNAME" |
| 33 | fi |
csmartdalton | e4fd078 | 2016-11-09 08:41:23 -0800 | [diff] [blame] | 34 | done''' % ' '.join(escapedskps)).splitlines() |