Your SlideShare is downloading. ×
0
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *Nix
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Pycon 2008: Python Command-line Tools *Nix

2,324

Published on

Writing Unix Command-line tools in Python

Writing Unix Command-line tools in Python

0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,324
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
37
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Creating Agile Unix Command Line Tools With Python(Using Subprocess, Optparse, Doctest and more) Noah Gift PyCon 2008
  • 2. QUICK WARNING!!!PLEASE DO NOT SATURATE THE PYCONNETWORK WITH ICMP REQUESTSWAIT UNTIL YOU GET HOME AND DO IT ONYOUR NEIGHBOR’S OPEN WIRELESS ACCESSPOINT
  • 3. Python Standard Library:A command line tool’s dream come true Optparse: Option Handling Subprocess: Elegant, One Stop, System Call API ConfigParser: Read/Write config files Threading/Queue: Concurrency Generators: http://www.dabeaz.com/generators/Generators.pdf Doctest: Example Driven Testing Python Egg’s w/Entry Point: Simple way to install scripts
  • 4. Ideas for Command Line Tools Pure Python: No systems calls, but do “Unix stuff” Unix Mashups Mix Python + System to solve new problems. Network Tools Wrapping Use existing tools, change the API, or behavior
  • 5. The Basics: Subprocess + Optparse Subprocess and Optparse: Just like chocolate and peanut butter. Alone they are good, but together they make a tasty treat.
  • 6. Subprocess: Tips for lazy people If you don’t care about stdout, use subprocess.call If you want to do something with stdout, use subprocess.Popen
  • 7. subprocess.call WrapEvaluate return code, send output to /dev/null
  • 8. OptparseOptparse is easy, all the tricky stuff is solved for you
  • 9. Creating a Python/Unix Mashup Tool Multi-Threaded Ping Sweep Wrap system ping command in subprocess Create a queue Spawn some threads It is that easy
  • 10. Multi-Threaded Ping Sweep
  • 11. Convert It To A Command Line Tool
  • 12. Adding SNMP Discovery(another queue, some more threads)
  • 13. Doctest Example
  • 14. A Pure Python Tool Scapy+Storm +Optparse
  • 15. Integrating Config Files With Your Tool
  • 16. Using Setuptools To Distribute ToolMake an eggCreate an entry point Entry points install your script into Operating System script directory, “for free”Create a --upgrade flag and integrate upgrades intoyour tool by using the Python Package Index
  • 17. ReferencesThis Presentation and Examples: http://code.noahgift.com/pycon2008SNMP and Python: http://www.ibm.com/developerworks/aix/library/ au-netsnmpnipython/Scapy: http://www.secdev.org/projects/scapy/Storm: https://storm.canonical.com/Entry Points: http://peak.telecommunity.com/DevCenter/setuptools#automatic-script-creation

×