which

mk mrkafk at gmail.com
Fri Feb 5 12:07:11 EST 2010


Jean-Michel Pichavant wrote:

 > To be honest I have not enough courrage to dive into yout 1000 lines of
 > script :-)

Understandable.

 > What I can say however:
 >
 > 1/ your interface is somehow broken. You ask actions through options (-c
 > -y -s), meaning one can possibly use all these 3 options  together. Your
 > code won't handle it (you are using elif statements). What happens if I
 > use no option at all ?

You get this:

Linux RH [17:35] root ~ # cssh.py -c "ps|wc" -s /tmp/s.sh

Following options that you specified are mutually exclusive:
-s / --script (value: /tmp/s.sh)
-c / --cmd (value: ps|wc)
You have to specify exactly one of options -c / --cmd, or -s / --script, 
or -y / --copy.

I wrote additional logic to handle such situations, I don't rely 
entirely on optparse.

 > 2/ executing a script, or copying a directory are both commands as well.
 > myProg -s /tmp/myscript.sh
 > is nothing more than
 > myProg -c '/bin/sh myscript.sh'

True. But you have to copy the script to remote machine in the first 
place. It's more convenient to do this using one option (copy to remote 
machine & execute there).

 > myProg -y file1
 > is nothing more than
 > myProg -c 'cp file1 towhatever'

Err but this is command to copy a local file/dir to *remote* machine. 
Like scp (in fact it uses scp protocol internally).

 >
 > 3/ check your user parameters before creating your SSHThread, and create
 > your SSHThread with already validated parameters. You don't want to
 > pollute you SSHThread code with irrelevant user error check.
 >
 >
 > my humble conclusion:
 >
 > 1/ rewrite your interface with
 > prog command args [options]
 >
 > 2/ Simplify your SSHThread by handling only  shell commands
 >
 > 3/ at the CLI level (right after parameter validation), mute you copy &
 > script
 > command to a shell command and pass it to SSHThread.
 >
 > Cheers,
 >
 > JM
 >
 >




More information about the Python-list mailing list