aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/skpbench/_adb_path.py
blob: 72382bc1dc178af84c45f5186d25a7a21fcacd07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Copyright 2016 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from _adb import Adb
import re
import subprocess

__ADB = None

def init(device_serial):
  global __ADB
  __ADB = Adb(device_serial)

def join(*pathnames):
  return '/'.join(pathnames)

def basename(pathname):
  return pathname.rsplit('/', maxsplit=1)[-1]

def find_skps(skps):
  escapedskps = [re.sub(r'([^a-zA-Z0-9_/\.\*\?\[\!\]])', r'\\\1', x)
                 for x in skps]
  return __ADB.check_lines('''\
    for PATHNAME in %s; do
      if [ -d "$PATHNAME" ]; then
        find "$PATHNAME" -maxdepth 1 -name *.skp
      else
        echo "$PATHNAME"
      fi
    done''' % ' '.join(escapedskps))