I wrote several small Python scripts to start clusters inside cloud infrastructures with distributed filesystems. Now, I integrated the code into a single command-line application but the code quality is very bad.
http://code.google.com/p/diffuser/source/browse/trunk/diffuser.py
The application needs to send lots of commands via SSH with paramiko. Each command that is send via SSH needs three lines of code:
stdin, stdout, stderr = client.exec_command("<command>")
print stdout.readlines()
print stderr.readlines()
How can I improve the code quality?
Commands are executed in a shell, so you can use regular shell syntax to combine them together. As a first step, I’d issue a batch of commands in a single exec_command:
In addition, I consider it unnecessary to start a fresh sudo for each of them. So I’d rather write