I am new to autotest and ever since I started using it, I found myself fumbling around trying to find or run tests. It seemed more complicated than it should be to be productive.
Now I understand autotest is mainly used for automation, but it can also be useful to the individual developer who wants to run some tests local in a controlled environment. As a person who enjoys the subcommands found in git and perf, I decided to create a framework to support subcommands to help me navigate around autotest. This patch is the basic piece that hooks into autotest. Later patches add commands that I find useful (and I hope others do too :-) ). The approach I took was to try and keep the original autotest workflow and just quickly jump into a function to test for certains commands and process them. Otherwise, just return and do the normal autotest workflow. Signed-off-by: Don Zickus <[email protected]> --- client/bin/autotest | 5 +++- client/bin/cmdparser.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletions(-) create mode 100644 client/bin/cmdparser.py diff --git a/client/bin/autotest b/client/bin/autotest index 7d36a05..1d19cba 100755 --- a/client/bin/autotest +++ b/client/bin/autotest @@ -7,7 +7,7 @@ import common from optparse import OptionParser from autotest_lib.client.bin import job from autotest_lib.client.common_lib import global_config - +from autotest_lib.client.bin import cmdparser # Use the name of the binary to find the real installation directory # aka $AUTODIR. Update our path to include the $AUTODIR/bin/tests @@ -74,6 +74,9 @@ def usage(): options, args = parser.parse_args() +cmd_parser = cmdparser.CommandParser() +args = cmd_parser.parse_args(args) + # Check for a control file if not in prebuild mode. if len(args) != 1 and options.client_test_setup is None: print "Missing control file!" diff --git a/client/bin/cmdparser.py b/client/bin/cmdparser.py new file mode 100644 index 0000000..f2683f0 --- /dev/null +++ b/client/bin/cmdparser.py @@ -0,0 +1,54 @@ +"""A command parser utility + + Just some wrapper commands around autotest client + + Copyright Don Zickus <[email protected]> 2011 +""" + +import copy, os, platform, re, shutil, sys, time, traceback, types, glob +import logging, getpass, errno, weakref + +class CommandParser(): + """A client-side command wrapper for newbies + + """ + + cmdlist = ['help'] + + def __init__(self): + return + + def parse_args(self, args): + """ + Process a client side command + + @param args: command line args + """ + + if len(args) and args[0] in self.cmdlist: + cmd = args.pop(0) + else: + #do things the traditional way + return args + + try: + args = getattr(self, cmd)(args) + except SystemExit as e: + sys.exit(e) + except: + sys.stderr.write("Failed: command %s\n" % cmd) + sys.exit(1) + + # args are cleaned up, return to process the traditional way + return args + + def help(self, args): + """ + List the commands and their usage strings + + @param args is not used here + """ + + print "help\t\tOutput a list of supported commands" + raise SystemExit(0) + -- 1.7.6.4 _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
