00001
00002 import sys; import sha; import optparse; from xmlrpclib import *
00003 p = optparse.OptionParser(usage="usage: %prog [options] <key> <value>")
00004 p.add_option("-g", "--gateway", dest="gateway", metavar="GW",
00005 default="http://localhost:1234/",
00006 help="gateway URI, list at http://opendht.org/servers.txt")
00007 p.add_option("-t", "--ttl", dest="ttl", default="3600", metavar="TTL",
00008 type="int", help="how long (in seconds) to store the value")
00009 p.add_option("-s", "--secret", dest="secret", default="", metavar="SEC",
00010 help="can be used to remove the value later")
00011 (opts, args) = p.parse_args()
00012 if (len(args) < 2): p.print_help(); sys.exit(1)
00013 pxy = ServerProxy(opts.gateway); res = {0:"Success", 1:"Capacity", 2:"Again"}
00014 key = Binary(sha.new(args[0]).digest()); val = Binary(args[1])
00015 ttl = int(opts.ttl); shash = Binary(sha.new(opts.secret).digest())
00016 if (opts.secret == ""): print res[pxy.put(key, val, ttl, "put.py")]
00017 else: print res[pxy.put_removable(key, val, "SHA", shash, ttl, "put.py")]