abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcpy_test.py
Go to the documentation of this file.
1 # You can use 'from pyabc import *' and then not need the pyabc. prefix everywhere
2 import pyabc
3 
4 # A new command is just a function that accepts a list of string arguments
5 # The first argument is always the name of the command
6 # It MUST return an integer. -1: user quits, -2: error. Return 0 for success.
7 
8 # a simple command that just prints its arguments and returns success
9 def pytest1_cmd(args):
10  print args
11  return 0
12 
13 # registers the command:
14 # The first argument is the function
15 # The second argument is the category (mainly for the ABC help command)
16 # The third argument is the new command name
17 # Keet the fourth argument 0, or consult with Alan
18 pyabc.add_abc_command(pytest1_cmd, "Python-Test", "pytest1", 0)
19 
20 # a simple command that just prints its arguments and runs the command 'scorr -h'
21 def pytest2_cmd(args):
22  print args
23  pyabc.run_command('scorr -h')
24  return 0
25 
26 pyabc.add_abc_command(pytest2_cmd, "Python-Test", "pytest2", 0)
27 
28 # Now a more complicated command with argument parsing
29 # This command gets two command line arguments -c and -v. -c cmd runs the command 'cmd -h' and -v prints the python version
30 # for more details see the optparse module: http://docs.python.org/library/optparse.html
31 
32 import optparse
33 
34 def pytest3_cmd(args):
35  usage = "usage: %prog [options]"
36 
37  parser = optparse.OptionParser(usage, prog="pytest3")
38 
39  parser.add_option("-c", "--cmd", dest="cmd", help="command to ask help for")
40  parser.add_option("-v", "--version", action="store_true", dest="version", help="display Python Version")
41 
42  options, args = parser.parse_args(args)
43 
44  if options.version:
45  print sys.version
46  return 0
47 
48  if options.cmd:
49  pyabc.run_command("%s -h"%options.cmd)
50  return 0
51 
52  return 0
53 
54 pyabc.add_abc_command(pytest3_cmd, "Python-Test", "pytest3", 0)
def pytest1_cmd
Definition: abcpy_test.py:9
def pytest3_cmd
Definition: abcpy_test.py:34
def pytest2_cmd
Definition: abcpy_test.py:21