コード例 #1
0
ファイル: bindings.py プロジェクト: macropin/ovm-ctl
def creds(isatty, user=None, pswd=None, credfile=None):
	while 1:
		user, pswd = get_creds(isatty, user=user, pswd=pswd, credfile=credfile)
		api = apibindings(user, pswd)
		try:
			api.details()
			return (user, pswd)
			
		except CurlException, e:
			if e.retcode == 401:
				if not isatty:
					raise

				print "Invalid username and/or password"
				user = None
				pswd = None
				credfile = None
			else:
				raise
コード例 #2
0
ファイル: bindings.py プロジェクト: macropin/ovm-ctl
			try:
				read_from_file = open(value, 'rU')
			except IOError:
				print 'Could not open file "%s" for reading.'
				raise
			istty = False
		else:
			if istty:
				print 'Warning: option %s not implemented' % opt

	user, pswd = creds(istty, user, pswd, authfile)

	if read_from_file:
		sys.stdin = read_from_file

	api = apibindings(user, pswd)
	if args != []: # got cmdline args
		cmd = " ".join(args)
		ret = cmd_parse(api, cmd, istty)
		return ret
	else:
		return repl(api, istty)

if __name__ == "__main__":
	istty = sys.stdout.isatty() and sys.stdin.isatty()
	try:
		sys.exit(main(sys.argv[1:], istty))
	except SystemExit:
		raise
	except BaseException, ex:
		if DEBUG: