Skip to content

Commit

Permalink
dump: Improved help
Browse files Browse the repository at this point in the history
- Version 2.3.16
- culebra: corrected help
  • Loading branch information
dtmilano committed May 4, 2013
1 parent 0906105 commit 5a39b8c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
2 changes: 1 addition & 1 deletion AndroidViewClient/src/com/dtmilano/android/viewclient.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@author: diego @author: diego
''' '''


__version__ = '2.3.15' __version__ = '2.3.16'


import sys import sys
import subprocess import subprocess
Expand Down
8 changes: 4 additions & 4 deletions AndroidViewClient/tools/culebra
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ___________________/ /__/ /__/ /__/ /________________________________
@author: Jennifer E. Swofford (ascii art snake) @author: Jennifer E. Swofford (ascii art snake)
''' '''


__version__ = '0.9.6' __version__ = '0.9.7'


import re import re
import sys import sys
Expand Down Expand Up @@ -65,7 +65,6 @@ OUTPUT = 'output'
USAGE = 'usage: %s [OPTION]... [serialno]' USAGE = 'usage: %s [OPTION]... [serialno]'
# -u,-s,-p,-v eaten by monkeyrunner # -u,-s,-p,-v eaten by monkeyrunner
SHORT_OPTS = 'HVIFSi:t:d:rCUj:D:R:o:' SHORT_OPTS = 'HVIFSi:t:d:rCUj:D:R:o:'

LONG_OPTS = [HELP, VERBOSE, IGNORE_SECURE_DEVICE, FORCE_VIEW_SERVER_USE, DO_NOT_START_VIEW_SERVER, LONG_OPTS = [HELP, VERBOSE, IGNORE_SECURE_DEVICE, FORCE_VIEW_SERVER_USE, DO_NOT_START_VIEW_SERVER,
FIND_VIEWS_BY_ID + '=', FIND_VIEWS_WITH_TEXT + '=', FIND_VIEWS_WITH_CONTENT_DESCRIPTION + '=', FIND_VIEWS_BY_ID + '=', FIND_VIEWS_WITH_TEXT + '=', FIND_VIEWS_WITH_CONTENT_DESCRIPTION + '=',
USE_REGEXPS, VERBOSE_COMMENTS, UNIT_TEST, USE_REGEXPS, VERBOSE_COMMENTS, UNIT_TEST,
Expand All @@ -78,14 +77,15 @@ OPTS_HELP = {
'H': 'prints this help', 'H': 'prints this help',
'i': 'whether to use findViewById() in script', 'i': 'whether to use findViewById() in script',
't': 'whether to use findViewWithText() in script', 't': 'whether to use findViewWithText() in script',
'd': 'whether to sue findViewWithContentDescription', 'd': 'whether to use findViewWithContentDescription',
'r': 'use regexps in matches', 'r': 'use regexps in matches',
'U': 'generates unit test script', 'U': 'generates unit test script',
'j': 'use jar and appropriate shebang to run script', 'j': 'use jar and appropriate shebang to run script',
'D': 'use a dictionary to store the Views found', 'D': 'use a dictionary to store the Views found',
'R': 'auto regexps (i.e. clock)', 'R': 'auto regexps (i.e. clock)',
'o': 'output filename', 'o': 'output filename',
} }

ID_RE = re.compile('id/([^/]*)(/(\d+))?') ID_RE = re.compile('id/([^/]*)(/(\d+))?')
AUTO_REGEXPS_RES = {'clock': re.compile('[012]\d:[0-5]\d')} AUTO_REGEXPS_RES = {'clock': re.compile('[012]\d:[0-5]\d')}
SHEBANG = { SHEBANG = {
Expand Down Expand Up @@ -261,11 +261,11 @@ def str2bool(v):
progname = os.path.basename(sys.argv[0]) progname = os.path.basename(sys.argv[0])
try: try:
optlist, args = getopt.getopt(sys.argv[1:], SHORT_OPTS, LONG_OPTS) optlist, args = getopt.getopt(sys.argv[1:], SHORT_OPTS, LONG_OPTS)
sys.argv[1:] = args
except getopt.GetoptError, e: except getopt.GetoptError, e:
print >>sys.stderr, 'ERROR:', str(e) print >>sys.stderr, 'ERROR:', str(e)
usage() usage()


sys.argv[1:] = args
kwargs1 = {VERBOSE: False, 'ignoresecuredevice': False} kwargs1 = {VERBOSE: False, 'ignoresecuredevice': False}
kwargs2 = {'forceviewserveruse': False, 'startviewserver': True} kwargs2 = {'forceviewserveruse': False, 'startviewserver': True}
options = {FIND_VIEWS_BY_ID: True, FIND_VIEWS_WITH_TEXT: False, FIND_VIEWS_WITH_CONTENT_DESCRIPTION: False, options = {FIND_VIEWS_BY_ID: True, FIND_VIEWS_WITH_TEXT: False, FIND_VIEWS_WITH_CONTENT_DESCRIPTION: False,
Expand Down
55 changes: 52 additions & 3 deletions AndroidViewClient/tools/dump
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Created on Feb 3, 2012
@author: diego @author: diego
''' '''


__version__ = '0.9.7'


import sys import sys
import os import os
Expand Down Expand Up @@ -44,16 +45,64 @@ MAP = {'i':ViewClient.TRAVERSE_CITUI, UNIQUE_ID:ViewClient.TRAVERSE_CITUI,
'd':ViewClient.TRAVERSE_CITCD, CONTENT_DESCRIPTION:ViewClient.TRAVERSE_CITCD, 'd':ViewClient.TRAVERSE_CITCD, CONTENT_DESCRIPTION:ViewClient.TRAVERSE_CITCD,
'c':ViewClient.TRAVERSE_CITC, CENTER:ViewClient.TRAVERSE_CITC, 'c':ViewClient.TRAVERSE_CITC, CENTER:ViewClient.TRAVERSE_CITC,
} }

USAGE = 'usage: %s [OPTION]... [serialno]'
# -u,-s,-p,-v eaten by monkeyrunner
SHORT_OPTS = 'HVIFSw:ixdc' SHORT_OPTS = 'HVIFSw:ixdc'
LONG_OPTS = [HELP, VERBOSE, IGNORE_SECURE_DEVICE, FORCE_VIEW_SERVER_USE, LONG_OPTS = [HELP, VERBOSE, IGNORE_SECURE_DEVICE, FORCE_VIEW_SERVER_USE,
DO_NOT_START_VIEW_SERVER, WINDOW + '=', DO_NOT_START_VIEW_SERVER, WINDOW + '=',
UNIQUE_ID, POSITION, CONTENT_DESCRIPTION, CENTER] UNIQUE_ID, POSITION, CONTENT_DESCRIPTION, CENTER]
LONG_OPTS_ARG = {WINDOW: 'WINDOW'}
OPTS_HELP = {
'H': 'prints this help',
'V': 'verbose comments',
'I': 'ignore secure device',
'F': 'force view server use (even if UiAutomator present)',
'S': 'dont start ViewServer',
'w': 'dump WINDOW content (default: -1)',
'i': 'dump View unique IDs',
'x': 'dump View positions',
'd': 'dump View content descriptions',
'c': 'dump View centers'
}

def shortAndLongOptions():
'''
@return: the list of corresponding (short-option, long-option) tuples
'''

short_opts = SHORT_OPTS.replace(':', '')
if len(short_opts) != len(LONG_OPTS):
raise Exception('There is a mismatch between short and long options')
t = tuple(short_opts) + tuple(LONG_OPTS)
l2 = len(t)/2
sl = []
for i in range(l2):
sl.append((t[i], t[i+l2]))
return sl


def usage(exitVal=1): def usage(exitVal=1):
print >> sys.stderr, 'usage: dump [-H|--%s] [-V|--%s] [-I|--%s] [-F|--%s] [-S|--%s] [-w|--%s=WINDOW] [-i|--%s] [-x|--%s] [-d|--%s] [-c|--%s] [serialno]' % \ print >> sys.stderr, USAGE % progname
tuple(LONG_OPTS) print >> sys.stderr, "Try '%s --help' for more information." % progname
sys.exit(exitVal) sys.exit(exitVal)


def help():
print >> sys.stderr, USAGE % progname
print >> sys.stderr
print >> sys.stderr, "Options:"
for so, lo in shortAndLongOptions():
o = ' -%c, --%s' % (so, lo)
if lo[-1] == '=':
o += LONG_OPTS_ARG[lo[:-1]]
try:
o = '%-34s %-45s' % (o, OPTS_HELP[so])
except:
pass
print >> sys.stderr, o
sys.exit(0)

# __main__
progname = os.path.basename(sys.argv[0])
try: try:
opts, args = getopt.getopt(sys.argv[1:], SHORT_OPTS, LONG_OPTS) opts, args = getopt.getopt(sys.argv[1:], SHORT_OPTS, LONG_OPTS)
sys.argv[1:] = args sys.argv[1:] = args
Expand All @@ -68,7 +117,7 @@ transform = ViewClient.TRAVERSE_CIT
for o, a in opts: for o, a in opts:
o = o.strip('-') o = o.strip('-')
if o in ['H', HELP]: if o in ['H', HELP]:
usage(0) help()
elif o in ['V', VERBOSE]: elif o in ['V', VERBOSE]:
kwargs1[VERBOSE] = True kwargs1[VERBOSE] = True
elif o in ['I', IGNORE_SECURE_DEVICE]: elif o in ['I', IGNORE_SECURE_DEVICE]:
Expand Down

0 comments on commit 5a39b8c

Please sign in to comment.