blob: fef2c2acb604c04b9d8f10099e23b6b45138f5fd [file] [log] [blame]
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
''' A utility module to print the gesture areas and functionalities '''
import getopt
import os
import sys
import trackpad_util
from trackpad_util import read_trackpad_test_conf
def _get_prompt(func, subname):
prompt = func.prompt
# Get subprompt
if isinstance(subname, tuple):
subprompt = reduce(lambda s1, s2: s1 + s2,
tuple(func.subprompt[s] for s in subname))
elif subname is None or func.subprompt is None:
subprompt = None
subprompt = func.subprompt[subname]
# Get full prompt
full_prompt = prompt if subprompt is None else prompt.format(*subprompt)
# Get full_func_name
if subname is not None:
if isinstance(subname, tuple):
name_list = list(subname)
name_list = [, subname]
full_func_name = '.'.join(name_list)
full_func_name =
space_func = ' ' * 4
space_prompt = ' ' * 8
print '%s<%s>' % (space_func, full_func_name)
print '%s%s\n' % (space_prompt, full_prompt)
def _span(seq1, seq2):
to_list = lambda s: list(s) if isinstance(s, tuple) else [s]
return tuple(tuple(to_list(s1) + to_list(s2)) for s1 in seq1
for s2 in seq2)
def print_gestures():
''' Print gesture areas and functionalities '''
functionality_list = read_trackpad_test_conf('functionality_list', '.')
area = None
count = 0
for func in functionality_list:
if func.area != area:
area = func.area
print '\n\nArea: ', area[0]
print '=================================='
print '\nfunctionality: ',
print '----------------------------------'
space_description = ' ' * 0
print '%sdescription: %s\n' % (space_description, func.description)
# Iterate through every functionality to record gesture files.
func_name =
subname = func.subname
if subname is None:
prompt = _get_prompt(func, subname)
count += 1
span_subname = (reduce(_span, subname)
if isinstance(subname[0], tuple) else subname)
for sub in span_subname:
prompt = _get_prompt(func, sub)
count += 1
print '\nTotal %d gesture variations.' % count
def _usage():
''' Print the usage of this program. '''
# Print the usage
print 'Usage: $ %s [options]\n' % sys.argv[0]
print 'options:'
print ' -c, --config=<config_file>'
print ' <config_file>: the config file'
print ' When omitted, use the default config file %s.' % \
print ' -h, --help: show this help\n'
def _parse_options():
''' Parse the command line options. '''
short_opt = 'hc:'
long_opt = ['help', 'config=']
opts, args = getopt.getopt(sys.argv[1:], short_opt, long_opt)
except getopt.GetoptError, err:
print 'Error: %s' % str(err)
for opt, arg in opts:
if opt in ('-h', '--help'):
elif opt in ('-c', '--config'):
if os.path.isfile(arg):
trackpad_util.trackpad_test_conf = arg
print 'Error: the config file "%s" does not exist.' % arg
print 'Error: This option %s is not handled in program.' % opt
print 'Use config file: %s' % trackpad_util.trackpad_test_conf
def main():
if __name__ == '__main__':