blob: 407f4039e32a759865480cbefe3bc3433b85eff8 [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):
Chris Dalton117d9722018-04-27 17:10:39 -060023 # root first, in case skps reside in a protected directory
24 __ADB.root()
csmartdaltond7a9db62016-09-22 05:10:02 -070025 escapedskps = [re.sub(r'([^a-zA-Z0-9_/\.\*\?\[\!\]])', r'\\\1', x)
csmartdalton0262b5c2016-09-19 12:04:56 -070026 for x in skps]
csmartdaltone4fd0782016-11-09 08:41:23 -080027 return __ADB.check('''\
csmartdalton0262b5c2016-09-19 12:04:56 -070028 for PATHNAME in %s; do
29 if [ -d "$PATHNAME" ]; then
csmartdalton5745d792016-09-22 12:37:21 -070030 find "$PATHNAME" -maxdepth 1 -name *.skp
csmartdalton0262b5c2016-09-19 12:04:56 -070031 else
32 echo "$PATHNAME"
33 fi
csmartdaltone4fd0782016-11-09 08:41:23 -080034 done''' % ' '.join(escapedskps)).splitlines()