[IPython-dev] Magics that multiplex

MinRK benjaminrk at gmail.com
Wed Jul 25 13:51:02 EDT 2012


On Wed, Jul 25, 2012 at 10:40 AM, David Quigley <dpquigl at davequigley.com>wrote:

> 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?


There's definitely nothing wrong with using your own parsing if you have a
reason to - the magic API is that you get a line (or line and cell), and
you do something with that.  No further restrictions.


> 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.
>

I don't *think* we have any library code to make subcommands easier, so I
think you are probably on the right path using ArgumentParser with
subparsers.


>
> Dave
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20120725/16e62bf0/attachment.html>


More information about the IPython-dev mailing list