#!/usr/bin/python # # Interactive shell for using QA test suite import os, sys from optparse import OptionParser from traceback import print_exc from qa import utils from qa.QAAPI import QAAPI sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0]))) parser = OptionParser(add_help_option = False) parser.add_option("-f", "--config", help = "configuration file") parser.add_option("-l", "--log", help="enable logging") parser.add_option("-v", "--verbose", help="be verbose") parser.add_option("--help", action = "help", help = "show this help message and exit") (options, args) = parser.parse_args() # XX Load callable tests try: qaapi = QAAPI(globals(), config = options.config, logging = options.log, verbose = options.verbose) config = qaapi.config plcapi = config.api auth = config.auth except Exception, err: raise # If called by a script if len(sys.argv) > 1 and os.path.exists(sys.argv[1]): # Pop us off the argument stack sys.argv.pop(0) execfile(sys.argv[0]) else: prompt = "[QA]" # Readline and tab completion support import atexit import readline import rlcompleter print 'Type "help" for more information.' # Load command history history_path = os.path.join(os.environ["HOME"], ".qa_history") try: file(history_path, 'a').close() readline.read_history_file(history_path) atexit.register(readline.write_history_file, history_path) except IOError: pass # Enable tab completion readline.parse_and_bind("tab: complete") try: while True: command = "" while True: # Get line try: if command == "": sep = ">>> " else: sep = "... " line = raw_input(prompt + sep) # Ctrl-C except KeyboardInterrupt: command = "" print break # Build up multi-line command command += line # Blank line or first line does not end in : if line == "" or (command == line and line[-1] != ':'): break command += os.linesep # Blank line if command == "": continue # Quit elif command in ["q", "quit", "exit"]: break try: try: # Try evaluating as an expression and printing the result result = eval(command) if result is not None: print result except SyntaxError: # Fall back to executing as a statement exec command except Exception, err: print_exc() except EOFError: print pass