panzi
panzi

Reputation: 7701

How to write a shell in Python

I've written a small console application that can perform certain tasks. The user interface is similar to things like version control systems or yum etc. So basically you can think of it as a domain specific language. Now I'd like to write a (bash like) shell that can execute and auto-complete this language and has a command history (so I do not have to load and save the quite large xml files on each command). In a nutshell I want something like ipython but not for executing python code but my own DSL.

Are there any libraries that help me doing this? I see that there is a readline and rlcompleter module in python but its documentation seems to indicate that this is only for use with the python shell itself, or did I miss something there?

Upvotes: 24

Views: 20751

Answers (2)

Brian Lyttle
Brian Lyttle

Reputation: 14579

You should check out the cmd and cmd2 modules. I think they will do what you want. There was a PyCon talk about these.

Upvotes: 23

zoli2k
zoli2k

Reputation: 3468

If you need an administrative shell to be accessed via network Twisted python framework's manhole is a good solution. Example:

http://www.devshed.com/c/a/Python/SSH-with-Twisted/3/

Upvotes: 3

Related Questions