define PLC_MAIL_FROM_ADDRESS
[tests.git] / qaapi / qash
1 #!/usr/bin/python
2 #
3 # Interactive shell for using QA test suite
4
5
6
7 import os, sys
8 from optparse import OptionParser
9 from traceback import print_exc
10 from qa import utils
11 from qa.QAAPI import QAAPI
12
13 sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
14
15 parser = OptionParser(add_help_option = False)
16 parser.add_option("-f", "--config", help = "configuration file")
17 parser.add_option("-l", "--log", help="enable logging")
18 parser.add_option("-v", "--verbose", help="be verbose")
19 parser.add_option("--help", action = "help", help = "show this help message and exit")
20 (options, args) = parser.parse_args()
21
22 # XX Load callable tests
23 try:
24     qaapi = QAAPI(globals(), 
25          config = options.config, 
26          logging = options.log,
27          verbose = options.verbose)
28     config = qaapi.config
29     plcapi = config.api
30     auth = config.auth
31 except Exception, err:
32     raise
33
34 # If called by a script
35 if len(sys.argv) > 1 and os.path.exists(sys.argv[1]):
36     # Pop us off the argument stack
37     sys.argv.pop(0)
38     execfile(sys.argv[0])
39
40 else:
41     prompt = "[QA]"
42     
43      # Readline and tab completion support
44     import atexit
45     import readline
46     import rlcompleter
47
48     print 'Type "help" for more information.'
49     # Load command history
50     history_path = os.path.join(os.environ["HOME"], ".qa_history")
51     try:
52         file(history_path, 'a').close()
53         readline.read_history_file(history_path)
54         atexit.register(readline.write_history_file, history_path)
55     except IOError:
56         pass
57
58     # Enable tab completion
59     readline.parse_and_bind("tab: complete")
60
61     try:
62         while True:
63             command = ""
64             while True:
65                 # Get line
66                 try:
67                     if command == "":
68                         sep = ">>> "
69                     else:
70                         sep = "... "
71                     line = raw_input(prompt + sep)
72                 # Ctrl-C
73                 except KeyboardInterrupt:
74                     command = ""
75                     print
76                     break
77
78                 # Build up multi-line command
79                 command += line
80
81                 # Blank line or first line does not end in :
82                 if line == "" or (command == line and line[-1] != ':'):
83                     break
84
85                 command += os.linesep
86
87             # Blank line
88             if command == "":
89                 continue
90             # Quit
91             elif command in ["q", "quit", "exit"]:
92                 break
93
94             try:
95                 try:
96                     # Try evaluating as an expression and printing the result
97                     result = eval(command)
98                     if result is not None:
99                         print result
100                 except SyntaxError:
101                     # Fall back to executing as a statement
102                     exec command
103             except Exception, err:
104                 print_exc()
105
106     except EOFError:
107         print
108         pass