[IPython-dev] Magics that multiplex
David Quigley
dpquigl at davequigley.com
Wed Jul 25 13:40:40 EDT 2012
I'm working on implementing a magic that multiplexes its behavior based
on the first token of the line after the magic. An example of a tool
which would do something like this is semanage or ip which based on the
second token ( port, login, fcontext, etc...) Behaves differently. I'm
doing it this way because these commands really belong to the same
component and are generic enough in name that they will appear again.
For example I want to have server start, server stop, server status be
magic commands. Is there functionality to do this already in the magics
subsystem? I looked at the parse_options code in Magics and it doesn't
seem to handle that kind of usecase (although I'd be glad to be proven
wrong). Alternatively I've used argparse in the past with subparsers to
do just that. argparse.ArgumentParser can have subparsers added to it to
then process arguments based on the second token in the line. Is there
anything incorrect about using an option parser that isn't
Magics.parse_options? Is there an already existing way to do this? I'm
using the rel-0.13 tag from git but can use -dev if necessary.
Dave
More information about the IPython-dev
mailing list