#!/usr/bin/env python

from time import time
from optparse import OptionParser

from cloudknowledge.client import *

parser = OptionParser(usage="usage: %prog [options]\n\nNote that you can specifiy multiple sets and gets. 'Get' is processed first.")
parser.add_option("-g","--get", action="append", type="string", dest="get", default=[], help="Get the named value from the network. Requires one argument which is the name of the value that is to fetch.")
parser.add_option("-s","--set", action="append", type="string", nargs=2, dest="set", default=[], help="Set the named value in the network. Requires two arguments: the name and the value to set.")
parser.add_option("-t","--timeout", action="store", type="int", dest="timeout", default=5, help="Optionally set the timeout to use for all network-transactions. Mostly affects the 'get'.")

(opts,args) = parser.parse_args()

c = CloudClient(opts.timeout)

for getkey in opts.get:
	print "'%s' returned '%s'" % (getkey, c.getvalue(getkey, None))

for key,value in opts.set:
	c.publishvalue(key, value)

