incubator-tashi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strou...@apache.org
Subject svn commit: r1366274 - /incubator/tashi/trunk/src/tashi/client/test.py
Date Fri, 27 Jul 2012 04:17:38 GMT
Author: stroucki
Date: Fri Jul 27 04:17:37 2012
New Revision: 1366274

URL: http://svn.apache.org/viewvc?rev=1366274&view=rev
Log:
test: more learning on optparse

Modified:
    incubator/tashi/trunk/src/tashi/client/test.py

Modified: incubator/tashi/trunk/src/tashi/client/test.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/client/test.py?rev=1366274&r1=1366273&r2=1366274&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/client/test.py (original)
+++ incubator/tashi/trunk/src/tashi/client/test.py Fri Jul 27 04:17:37 2012
@@ -3,13 +3,40 @@
 import optparse
 import sys
 
+def remoteCommand(command, options):
+	print "Doing command %s options %s" % (command, options)
+	return 0
+
 def setHostState(args):
 	parser = optparse.OptionParser()
-	parser.add_option("--host")
+	parser.set_usage("%s setHostState [options]" % sys.argv[0])
+	parser.add_option("--host", help="Set the state of this host", action="store", type="string",
dest="hostname")
+	parser.add_option("--state", help="Change state to this value", action="store", type="string",
dest="state")
+	(options, arguments) = parser.parse_args(args)
+	print options
+	print arguments
+	if options.hostname is None or options.state is None:
+		print "A mandatory option is missing\n"
+		parser.print_help()
+		sys.exit(-1)
+
+	remoteCommand("shs", options)
 	return 0
 
 def setHostNotes(args):
 	parser = optparse.OptionParser()
+	parser.set_usage("%s setHostNotes [options]" % sys.argv[0])
+	parser.add_option("--host", help="Annotate this host with the note (mandatory)", action="store",
type="string", dest="hostname")
+	parser.add_option("--notes", help="Annotate the host with this note (mandatory)", action="store",
type="string", dest="notes")
+	(options, arguments) = parser.parse_args(args)
+	print options
+	print arguments
+	if options.hostname is None or options.notes is None:
+		print "A mandatory option is missing\n"
+		parser.print_help()
+		sys.exit(-1)
+
+	remoteCommand("shn", options)
 	return 0
 
 cmdsdesc = (



Mime
View raw message