summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornoah <noah@656d521f-e311-0410-88e0-e7920216d269>2006-11-18 02:33:15 +0000
committernoah <noah@656d521f-e311-0410-88e0-e7920216d269>2006-11-18 02:33:15 +0000
commit45b9669e99c36f1eb34672c473aa1afcca3044ba (patch)
tree14e41a1fc783918f1e813d3d59edd50c84689c8a
parentadfd8966d802b54629dd16289cd57b774ce80177 (diff)
downloadpexpect-45b9669e99c36f1eb34672c473aa1afcca3044ba.tar.gz
Fixed some silly errors in CLI parsing.
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@442 656d521f-e311-0410-88e0-e7920216d269
-rwxr-xr-xpexpect/examples/hive.py46
1 files changed, 28 insertions, 18 deletions
diff --git a/pexpect/examples/hive.py b/pexpect/examples/hive.py
index 01f68b9..02d9184 100755
--- a/pexpect/examples/hive.py
+++ b/pexpect/examples/hive.py
@@ -98,7 +98,7 @@ def main ():
global CMD_HELP
try:
- optlist, args = getopt.getopt(sys.argv[1:], 'h?', ['help','h','?','samepw','username=','password='])
+ optlist, args = getopt.getopt(sys.argv[1:], 'h?', ['help','h','?','sameuser','samepw', 'username=','password='])
except Exception, e:
print str(e)
exit_with_usage()
@@ -107,36 +107,46 @@ def main ():
if [elem for elem in options if elem in ['-h','--h','-?','--?','--help']]:
exit_with_usage(0)
+ if '--sameuser' in options:
+ sameuser = True
+ else:
+ sameuser = False
if '--samepw' in options:
samepw = True
else:
samepw = False
- if samepw:
- if '--username' in options:
- username = options['--username']
- else:
- username = raw_input('username: ')
- if '--password' in options:
- password = options['--password']
- else:
- password = getpass.getpass('password: ')
+ cli_username = ''
+ if '--username' in options:
+ cli_username = options['--username']
+ else:
+ cli_username = raw_input('username: ')
+ cli_password = ''
+ if '--password' in options:
+ cli_password = options['--password']
+ else:
+ cli_password = getpass.getpass('password: ')
hive = {}
hive_names = []
for host_connect_string in args:
hcd = parse_host_connect_string (host_connect_string)
hostname = hcd['hostname']
- username = hcd['username']
- password = hcd['password']
port = hcd['port']
- print 'connecting to', hostname
- if not samepw:
- if username == '':
- username = raw_input('username: ')
- if password == '':
- password = getpass.getpass('password: ')
if port == '':
port = None
+ if len(hcd['username']) > 0 and not sameuser:
+ username = hcd['username']
+ elif cli_username == '':
+ username = raw_input('username: ')
+ else:
+ username = cli_username
+ if len(hcd['password']) > 0 and not samepw:
+ password = hcd['password']
+ elif cli_password == '':
+ password = raw_input('password: ')
+ else:
+ password = cli_password
+ print 'connecting to', hostname
try:
hive[hostname] = pxssh.pxssh()
hive[hostname].login(hostname, username, password, port)