From 6130e39b18b5f53902e4eab14f6d5cdde5219563 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Mon, 1 Nov 2010 01:35:04 -0700 Subject: initial commit of public abc --- src/python/abcpy_test.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/python/abcpy_test.py (limited to 'src/python/abcpy_test.py') diff --git a/src/python/abcpy_test.py b/src/python/abcpy_test.py new file mode 100644 index 00000000..912cae9f --- /dev/null +++ b/src/python/abcpy_test.py @@ -0,0 +1,54 @@ +# You can use 'from pyabc import *' and then not need the pyabc. prefix everywhere +import pyabc + +# A new command is just a function that accepts a list of string arguments +# The first argument is always the name of the command +# It MUST return an integer. -1: user quits, -2: error. Return 0 for success. + +# a simple command that just prints its arguments and returns success +def pytest1_cmd(args): + print args + return 0 + +# registers the command: +# The first argument is the function +# The second argument is the category (mainly for the ABC help command) +# The third argument is the new command name +# Keet the fourth argument 0, or consult with Alan +pyabc.add_abc_command(pytest1_cmd, "Python-Test", "pytest1", 0) + +# a simple command that just prints its arguments and runs the command 'scorr -h' +def pytest2_cmd(args): + print args + pyabc.run_command('scorr -h') + return 0 + +pyabc.add_abc_command(pytest2_cmd, "Python-Test", "pytest2", 0) + +# Now a more complicated command with argument parsing +# This command gets two command line arguments -c and -v. -c cmd runs the command 'cmd -h' and -v prints the python version +# for more details see the optparse module: http://docs.python.org/library/optparse.html + +import optparse + +def pytest3_cmd(args): + usage = "usage: %prog [options]" + + parser = optparse.OptionParser(usage) + + parser.add_option("-c", "--cmd", dest="cmd", help="command to ask help for") + parser.add_option("-v", "--version", action="store_true", dest="version", help="display Python Version") + + options, args = parser.parse_args(args) + + if options.version: + print sys.version + return 0 + + if options.cmd: + pyabc.run_command("%s -h"%options.cmd) + return 0 + + return 0 + +pyabc.add_abc_command(pytest3_cmd, "Python-Test", "pytest3", 0) -- cgit v1.2.3