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
6from _adb import Adb
7import re
8import subprocess
9
10__ADB = None
11
12def init(device_serial, adb_binary):
13  global __ADB
14  __ADB = Adb(device_serial, adb_binary)
15
16def join(*pathnames):
17  return '/'.join(pathnames)
18
19def basename(pathname):
20  return pathname.rsplit('/', maxsplit=1)[-1]
21
22def find_skps(skps):
23  # root first, in case skps reside in a protected directory
24  __ADB.root()
25  escapedskps = [re.sub(r'([^a-zA-Z0-9_/\.\*\?\[\!\]])', r'\\\1', x)
26                 for x in skps]
27  return __ADB.check('''\
28    for PATHNAME in %s; do
29      if [ -d "$PATHNAME" ]; then
30        find "$PATHNAME" -maxdepth 1 -name '*.skp' -o -name '*.mskp'
31      else
32        echo "$PATHNAME"
33      fi
34    done''' % ' '.join(escapedskps)).splitlines()
35