blob: dc23fc5895b7989809d05fc57a342c5953bfabde [file] [log] [blame]
csmartdalton0262b5c2016-09-19 12:04:56 -07001# 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
csmartdaltond7a9db62016-09-22 05:10:02 -07006from _adb import Adb
csmartdalton0262b5c2016-09-19 12:04:56 -07007import re
8import subprocess
9
csmartdaltond7a9db62016-09-22 05:10:02 -070010__ADB = None
csmartdalton0262b5c2016-09-19 12:04:56 -070011
Kevin Lubickcccaef12017-10-13 08:15:09 -040012def init(device_serial, adb_binary):
csmartdaltond7a9db62016-09-22 05:10:02 -070013 global __ADB
Kevin Lubickcccaef12017-10-13 08:15:09 -040014 __ADB = Adb(device_serial, adb_binary)
csmartdalton0262b5c2016-09-19 12:04:56 -070015
16def join(*pathnames):
17 return '/'.join(pathnames)
18
19def basename(pathname):
20 return pathname.rsplit('/', maxsplit=1)[-1]
21
22def find_skps(skps):
csmartdaltond7a9db62016-09-22 05:10:02 -070023 escapedskps = [re.sub(r'([^a-zA-Z0-9_/\.\*\?\[\!\]])', r'\\\1', x)
csmartdalton0262b5c2016-09-19 12:04:56 -070024 for x in skps]
csmartdaltone4fd0782016-11-09 08:41:23 -080025 return __ADB.check('''\
csmartdalton0262b5c2016-09-19 12:04:56 -070026 for PATHNAME in %s; do
27 if [ -d "$PATHNAME" ]; then
csmartdalton5745d792016-09-22 12:37:21 -070028 find "$PATHNAME" -maxdepth 1 -name *.skp
csmartdalton0262b5c2016-09-19 12:04:56 -070029 else
30 echo "$PATHNAME"
31 fi
csmartdaltone4fd0782016-11-09 08:41:23 -080032 done''' % ' '.join(escapedskps)).splitlines()