Discussion:
CLI framework using python
vijnaana
2014-10-09 12:20:34 UTC
Permalink
Hi,

I need to develop a python CLI framework.

For example if i need to set an ip address in linux:

ifconfig eth0 172.16.25.125

I should be able to use python to do the above.

1. The user will execute a python script to which i will pass the params eth0 and ip address (something like ifconf.py eth0 172.16.25.125)

2. Within the script i grab the params and do something to the effect of user executing 'ifconfig eth0 172.16.25.125' from the shell.

3. There are other such commands for which i will be using python scripts. I came across pyCLI, but it doesn't have much documentation, so couldn't figure out how to move forward.

4. The CLI framework needs to reuse code so i didn't want to use pure python and develop a framework from scratch. Rather use something like pyCLI/CLIFF.

The problem is lack of documentation with examples on how to use the above.

Any guidance would be greatly appreciated.

Regards & Thanks,
Vij
Unix SA
2014-10-09 15:25:40 UTC
Permalink
Hello,

Go for Optparse.. Look at below docs on how to use it.

http://pymotw.com/2/optparse/

Regards,
DJ
Post by vijnaana
Hi,
I need to develop a python CLI framework.
ifconfig eth0 172.16.25.125
I should be able to use python to do the above.
1. The user will execute a python script to which i will pass the params
eth0 and ip address (something like ifconf.py eth0 172.16.25.125)
2. Within the script i grab the params and do something to the effect of
user executing 'ifconfig eth0 172.16.25.125' from the shell.
3. There are other such commands for which i will be using python scripts.
I came across pyCLI, but it doesn't have much documentation, so couldn't
figure out how to move forward.
4. The CLI framework needs to reuse code so i didn't want to use pure
python and develop a framework from scratch. Rather use something like
pyCLI/CLIFF.
The problem is lack of documentation with examples on how to use the above.
Any guidance would be greatly appreciated.
Regards & Thanks,
Vij
--
https://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141009/6b4d02ab/attachment.html>
Gelonida N
2014-10-09 16:00:57 UTC
Permalink
Post by Unix SA
Hello,
Go for Optparse.. Look at below docs on how to use it.
http://pymotw.com/2/optparse/
For newer projects I'd suggest argparse (part of Python since 2.7 and
can be downloaded / installed for 2.5 / 2.6).

https://docs.python.org/2.7/library/argparse.html

argparse is very powerfull. you might be interested in looking at
subparsers.


For calling commands in a slightly nicer way than os.system /
sybprocess.Popen you might look at sh or plumbum

https://pypi.python.org/pypi/sh

https://pypi.python.org/pypi/plumbum
Post by Unix SA
Regards,
DJ
On Thu, Oct 9, 2014 at 5:50 PM, <vijnaana at gmail.com
Hi,
I need to develop a python CLI framework.
ifconfig eth0 172.16.25.125
I should be able to use python to do the above.
1. The user will execute a python script to which i will pass the
params eth0 and ip address (something like ifconf.py eth0
172.16.25.125)
2. Within the script i grab the params and do something to the
effect of user executing 'ifconfig eth0 172.16.25.125' from the shell.
3. There are other such commands for which i will be using python
scripts. I came across pyCLI, but it doesn't have much
documentation, so couldn't figure out how to move forward.
4. The CLI framework needs to reuse code so i didn't want to use
pure python and develop a framework from scratch. Rather use
something like pyCLI/CLIFF.
The problem is lack of documentation with examples on how to use the above.
Any guidance would be greatly appreciated.
Regards & Thanks,
Vij
--
https://mail.python.org/mailman/listinfo/python-list
Rustom Mody
2014-10-10 08:43:22 UTC
Permalink
Post by Gelonida N
For calling commands in a slightly nicer way than os.system /
sybprocess.Popen you might look at sh or plumbum
https://pypi.python.org/pypi/sh
https://pypi.python.org/pypi/plumbum
Both of these look quite nice!
[Im looking at them from a couple of angles
1. Using python as a scripting language
2. Notion of DSL
]

Can you tell me in short whats the difference??
Gelonida N
2014-10-10 11:58:11 UTC
Permalink
Post by Rustom Mody
Post by Gelonida N
For calling commands in a slightly nicer way than os.system /
sybprocess.Popen you might look at sh or plumbum
https://pypi.python.org/pypi/sh
https://pypi.python.org/pypi/plumbum
Both of these look quite nice!
[Im looking at them from a couple of angles
1. Using python as a scripting language
2. Notion of DSL
]
Can you tell me in short whats the difference??
Not really, both are quite new to me as well.

On a first glanced I prefered sh

However: plumbum works also on Windows systems.

As I have to write some code for Windows, some code for Linux and some
code for both platforms I think plumbum might be nicer as I can stick to
one syntax.

So far I used both of them just in very tiny scripts.

Most of my code still uses subprocess.Popen or my own clumsy wrappers
around it.
Python UL
2014-10-09 16:08:52 UTC
Permalink
Post by vijnaana
Hi,
I need to develop a python CLI framework.
ifconfig eth0 172.16.25.125
I should be able to use python to do the above.
1. The user will execute a python script to which i will pass the params eth0 and ip address (something like ifconf.py eth0 172.16.25.125)
2. Within the script i grab the params and do something to the effect of user executing 'ifconfig eth0 172.16.25.125' from the shell.
3. There are other such commands for which i will be using python scripts. I came across pyCLI, but it doesn't have much documentation, so couldn't figure out how to move forward.
4. The CLI framework needs to reuse code so i didn't want to use pure python and develop a framework from scratch. Rather use something like pyCLI/CLIFF.
The problem is lack of documentation with examples on how to use the above.
Any guidance would be greatly appreciated.
Regards & Thanks,
Vij
Hi Vij

Maybe you can have a look at iPython:
http://ipython.org/ipython-doc/stable/interactive/tutorial.html

gr
Arno
Jean-Michel Pichavant
2014-10-09 13:11:39 UTC
Permalink
----- Original Message -----
From: vijnaana at gmail.com
Hi,
I need to develop a python CLI framework.
[snip]
3. There are other such commands for which i will be using python
scripts. I came across pyCLI, but it doesn't have much
documentation, so couldn't figure out how to move forward.
Any guidance would be greatly appreciated.
Regards & Thanks,
Vij
https://pythonhosted.org/pyCLI/

The doc features a quick tour and basic usage section + the complete API, illustrated with examples.

Why don't you show us some code you've written using pyCli, maybe we could help.

JM



-- IMPORTANT NOTICE:

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
vijnaana bhairava
2014-10-14 13:33:10 UTC
Permalink
Hi Folks,

The requirement is to develop a CLI framework in python for a linux router.
The suggestions i got is to use PyCli/Cliff. Not sure which would be the right choice! Also, a few APIs are mentioned here:

https://pythonhosted.org/pyCLI/#module-cli.app

Since i couldn't find any actual implementation which uses pyCli,
i can't figure out how to make use of pyCLI.

Another question i have is whether it uses argparse?
If so, what value add does PYCLI do?

Regards,
vij
Post by vijnaana
Hi,
I need to develop a python CLI framework.
ifconfig eth0 172.16.25.125
I should be able to use python to do the above.
1. The user will execute a python script to which i will pass the params eth0 and ip address (something like ifconf.py eth0 172.16.25.125)
2. Within the script i grab the params and do something to the effect of user executing 'ifconfig eth0 172.16.25.125' from the shell.
3. There are other such commands for which i will be using python scripts. I came across pyCLI, but it doesn't have much documentation, so couldn't figure out how to move forward.
4. The CLI framework needs to reuse code so i didn't want to use pure python and develop a framework from scratch. Rather use something like pyCLI/CLIFF.
The problem is lack of documentation with examples on how to use the above.
Any guidance would be greatly appreciated.
Regards & Thanks,
Vij
Chris Angelico
2014-10-14 13:43:16 UTC
Permalink
Post by vijnaana bhairava
Another question i have is whether it uses argparse?
If so, what value add does PYCLI do?
It depends what you mean by "CLI framework". If you simply mean
something like hg, where you have subcommands and options and so on,
all you really need is argument parsing. Take the simplest possible
solution and run with it!

ChrisA
Naoki INADA
2014-10-14 14:15:35 UTC
Permalink
Click_ is another CLI framework.

It support multi-level nested command like git and it has some nice utilities.

I love it's design.






.. _click: http://click.pocoo.org/3/




?
Sent from Mailbox

On Tue, Oct 14, 2014 at 10:35 PM, vijnaana bhairava <vijnaana at gmail.com>
Post by vijnaana bhairava
Hi Folks,
The requirement is to develop a CLI framework in python for a linux router.
https://pythonhosted.org/pyCLI/#module-cli.app
Since i couldn't find any actual implementation which uses pyCli,
i can't figure out how to make use of pyCLI.
Another question i have is whether it uses argparse?
If so, what value add does PYCLI do?
Regards,
vij
Post by vijnaana
Hi,
I need to develop a python CLI framework.
ifconfig eth0 172.16.25.125
I should be able to use python to do the above.
1. The user will execute a python script to which i will pass the params eth0 and ip address (something like ifconf.py eth0 172.16.25.125)
2. Within the script i grab the params and do something to the effect of user executing 'ifconfig eth0 172.16.25.125' from the shell.
3. There are other such commands for which i will be using python scripts. I came across pyCLI, but it doesn't have much documentation, so couldn't figure out how to move forward.
4. The CLI framework needs to reuse code so i didn't want to use pure python and develop a framework from scratch. Rather use something like pyCLI/CLIFF.
The problem is lack of documentation with examples on how to use the above.
Any guidance would be greatly appreciated.
Regards & Thanks,
Vij
--
https://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141014/3f449336/attachment.html>
vijnaana bhairava
2014-10-15 16:05:14 UTC
Permalink
Hi Naoki,

I am new to python programming. Getting used to writing basic scripts to understand python.

To understand 'Click' i may need some more guidance.

For e.g if i were to do 'ifconfig -a' from Click, how would the program look like. That will help me get started.

What i am looking for is a class based approach.

For e.g all interface related commands could come under class Interface and 'ifconfig' would probably be a method.

I would like to see one working program to get a feel for 'Click'

Thank You!
vij
Post by Naoki INADA
Click_ is another CLI framework.
It support multi-level nested command like git and it has some nice utilities.
I love it's design.
.. _click: http://click.pocoo.org/3/
--
Sent from Mailbox
Hi Folks,
The requirement is to develop a CLI framework in python for a linux router.
https://pythonhosted.org/pyCLI/#module-cli.app
Since i couldn't find any actual implementation which uses pyCli,
i can't figure out how to make use of pyCLI.
Another question i have is whether it uses argparse?
If so, what value add does PYCLI do?
Regards,
vij
Post by vijnaana
Hi,
I need to develop a python CLI framework.
ifconfig eth0 172.16.25.125
I should be able to use python to do the above.
1. The user will execute a python script to which i will pass the params eth0 and ip address (something like ifconf.py eth0 172.16.25.125)
2. Within the script i grab the params and do something to the effect of user executing 'ifconfig eth0 172.16.25.125' from the shell.
3. There are other such commands for which i will be using python scripts. I came across pyCLI, but it doesn't have much documentation, so couldn't figure out how to move forward.
4. The CLI framework needs to reuse code so i didn't want to use pure python and develop a framework from scratch. Rather use something like pyCLI/CLIFF.
The problem is lack of documentation with examples on how to use the above.
Any guidance would be greatly appreciated.
Regards & Thanks,
Vij
--
https://mail.python.org/mailman/listinfo/python-list
Loading...