Skip to content

Commit bd90bf6

Browse files
committed
Optional parameter serialno to AdbClient
- Version 5.0.0 - culebra: optionally set sys.path from environment in generated script
1 parent 87b7878 commit bd90bf6

4 files changed

Lines changed: 23 additions & 13 deletions

File tree

AndroidViewClient/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import setup, find_packages
44

55
setup(name='androidviewclient',
6-
version='4.11.0',
6+
version='5.0.0',
77
description='''AndroidViewClient is a 100% pure python tool that
88
simplifies test script creation providing higher level operations and the ability of
99
obtaining the tree of Views present at any given moment on the device or emulator screen.

AndroidViewClient/src/com/dtmilano/android/adb/adbclient.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@author: Diego Torres Milano
1818
'''
1919

20-
__version__ = '4.8.0'
20+
__version__ = '5.0.0'
2121

2222
import sys
2323
import warnings
@@ -75,9 +75,7 @@ def __str__(self):
7575

7676
class AdbClient:
7777

78-
def __init__(self, serialno, hostname=HOSTNAME, port=PORT, settransport=True, reconnect=True):
79-
if not serialno:
80-
raise ValueError("serialno must not be empty or None")
78+
def __init__(self, serialno=None, hostname=HOSTNAME, port=PORT, settransport=True, reconnect=True):
8179
self.serialno = serialno
8280
self.hostname = hostname
8381
self.port = port
@@ -87,7 +85,7 @@ def __init__(self, serialno, hostname=HOSTNAME, port=PORT, settransport=True, re
8785

8886
self.checkVersion()
8987
self.isTransportSet = False
90-
if settransport:
88+
if settransport and serialno != None:
9189
self.__setTransport()
9290

9391
@staticmethod
@@ -99,6 +97,12 @@ def setAlarm(timeout):
9997
print >> sys.stderr, "setAlarm(%d)" % timeout
10098
signal.alarm(timeout)
10199

100+
def setSerialno(self, serialno):
101+
if self.isTransportSet:
102+
raise ValueError("Transport is already set, serialno cannot be set once this is done.")
103+
self.serialno = serialno
104+
self.__setTransport()
105+
102106
def setReconnect(self, val):
103107
self.reconnect = val
104108

@@ -201,6 +205,8 @@ def checkVersion(self, reconnect=True):
201205
def __setTransport(self):
202206
if DEBUG:
203207
print >> sys.stderr, "__setTransport()"
208+
if not self.serialno:
209+
raise ValueError("serialno not set, empty or None")
204210
self.checkConnected()
205211
serialnoRE = re.compile(self.serialno)
206212
found = False

AndroidViewClient/src/com/dtmilano/android/viewclient.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@author: Diego Torres Milano
1919
'''
2020

21-
__version__ = '4.10.2'
21+
__version__ = '5.0.0'
2222

2323
import sys
2424
import warnings
@@ -43,7 +43,7 @@
4343
import xml.parsers.expat
4444
from com.dtmilano.android.adb import adbclient
4545

46-
DEBUG = True
46+
DEBUG = False
4747
DEBUG_DEVICE = DEBUG and False
4848
DEBUG_RECEIVED = DEBUG and False
4949
DEBUG_TREE = DEBUG and False

AndroidViewClient/tools/culebra

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ___________________/ /__/ /__/ /__/ /________________________________
1818
1919
'''
2020

21-
__version__ = '4.10.1'
21+
__version__ = '5.0.0'
2222

2323
import re
2424
import sys
@@ -57,17 +57,18 @@ START_ACTIVITY = 'start-activity'
5757
OUTPUT = 'output'
5858
INTERACTIVE = 'interactive'
5959
WINDOW = 'window'
60+
APPEND_TO_SYS_PATH = 'append-to-sys-path'
6061

6162
USAGE = 'usage: %s [OPTION]... [serialno]'
62-
SHORT_OPTS = 'HVIFSkw:i:t:d:rCUj:D:K:R:a:o:A'
63+
SHORT_OPTS = 'HVIFSkw:i:t:d:rCUj:D:K:R:a:o:Ap'
6364
LONG_OPTS = [HELP, VERBOSE, IGNORE_SECURE_DEVICE, FORCE_VIEW_SERVER_USE, DO_NOT_START_VIEW_SERVER,
6465
DO_NOT_IGNORE_UIAUTOMATOR_KILLED,
6566
WINDOW + '=',
6667
FIND_VIEWS_BY_ID + '=', FIND_VIEWS_WITH_TEXT + '=', FIND_VIEWS_WITH_CONTENT_DESCRIPTION + '=',
6768
USE_REGEXPS, VERBOSE_COMMENTS, UNIT_TEST,
6869
USE_JAR + '=', USE_DICTIONARY + '=', DICTIONARY_KEYS_FROM + '=', AUTO_REGEXPS + '=',
6970
START_ACTIVITY + '=',
70-
OUTPUT + '=', INTERACTIVE]
71+
OUTPUT + '=', INTERACTIVE, APPEND_TO_SYS_PATH]
7172
LONG_OPTS_ARG = {WINDOW: 'WINDOW',
7273
FIND_VIEWS_BY_ID: 'BOOL', FIND_VIEWS_WITH_TEXT: 'BOOL', FIND_VIEWS_WITH_CONTENT_DESCRIPTION: 'BOOL',
7374
USE_JAR: 'BOOL', USE_DICTIONARY: 'BOOL', DICTIONARY_KEYS_FROM: 'VALUE', AUTO_REGEXPS: 'LIST',
@@ -89,6 +90,7 @@ OPTS_HELP = {
8990
'a': 'starts Activity before dump',
9091
'o': 'output filename',
9192
'A': 'interactive',
93+
'p': 'append environment variables values to sys.path'
9294
}
9395

9496
AUTO_REGEXPS_RES = {'clock': re.compile('[012]\d:[0-5]\d')}
@@ -320,7 +322,7 @@ options = {FIND_VIEWS_BY_ID: True, FIND_VIEWS_WITH_TEXT: False, FIND_VIEWS_WITH_
320322
USE_REGEXPS: False, VERBOSE_COMMENTS: False,
321323
UNIT_TEST: False, USE_JAR: False, USE_DICTIONARY: False, DICTIONARY_KEYS_FROM: 'id',
322324
AUTO_REGEXPS: None, START_ACTIVITY: None, OUTPUT: None, INTERACTIVE: False,
323-
WINDOW: -1}
325+
WINDOW: -1, APPEND_TO_SYS_PATH: False}
324326
transform = traverseAndPrint
325327
for o, a in optlist:
326328
o = o.strip('-')
@@ -369,6 +371,8 @@ for o, a in optlist:
369371
options[OUTPUT] = a
370372
elif o in ['A', INTERACTIVE]:
371373
options[INTERACTIVE] = True
374+
elif o in ['p', APPEND_TO_SYS_PATH]:
375+
options[APPEND_TO_SYS_PATH] = True
372376

373377
if not (options[FIND_VIEWS_BY_ID] or options[FIND_VIEWS_WITH_TEXT] or options[FIND_VIEWS_WITH_CONTENT_DESCRIPTION]):
374378
if not options[VERBOSE_COMMENTS]:
@@ -414,7 +418,7 @@ if options[UNIT_TEST]:
414418
import unittest
415419
'''
416420

417-
if not options[USE_JAR]:
421+
if options[APPEND_TO_SYS_PATH]:
418422
print '''
419423
try:
420424
sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))

0 commit comments

Comments
 (0)