import sys

if len(sys.argv) == 1:
  print """advertise_lookup.py -- 
  resolve keys to values on the Seattle advertise services

Usage:
  python advertise_lookup.py ONE_ID [ FURTHER_IDs... ]
"""

from repyportability import *
add_dy_support(locals())

advertise = dy_import_module("advertise.r2py")

for identifier in sys.argv[1:]:
  try:
    resultslist = advertise.advertise_lookup(identifier)
    print "'" + identifier + "' maps to", len(resultslist), "value(s):", resultslist 
  except advertise.AdvertiseError:
    print "(Error looking up " + identifier +")"


@@ -121,16 +121,44 @@
 services
+, %0A  or look up public keys.
 %0A%0AUsage:
@@ -217,200 +217,1008 @@
 . %5D%0A
-%22%22%22%0A%0Afrom repyportability import *%0Aadd_dy_support(locals())%0A%0Aadvertise = dy_import_module(%22advertise.r2py%22)%0A%0Afor identifier in sys.argv%5B1:%5D:%0A  try:%0A    resultslist = advertise.advertise_lookup
+  python advertise_lookup.py --key PUBKEY_FILE_NAME %5B FURTHER_FILENAMEs....%5D%0A%0AExamples:%0A  python advertise_lookup.py time_server%0A  python advertise_lookup.py --key servicevessel.publickey%0A%22%22%22%0A  exit()%0A%0Afrom repyportability import *%0Aadd_dy_support(locals())%0A%0Aadvertise = dy_import_module(%22advertise.r2py%22)%0Aexperimentlib = dy_import_module(%22experimentlib.r2py%22)%0A%0A# Default to looking up IDs, not public keys%0Alookup_function = advertise.advertise_lookup%0A%0A# If we are told to look up keys from files (and not the single %0A# string %22--key%22), use a different lookup function.%0Aif sys.argv%5B1%5D == %22--key%22 and len(sys.argv)%3E2:%0A  def load_key_and_look_it_up(key_file_name):%0A    identity = experimentlib.create_identity_from_key_files(key_file_name)%0A    return experimentlib.lookup_node_locations_by_identity(identity)%0A  lookup_function = load_key_and_look_it_up%0A  # Drop %22--keys%22 from argv, this is not a key file name!%0A  sys.argv.pop(1)%0A%0A%0Afor identifier in sys.argv%5B1:%5D:%0A  try:%0A    resultslist = lookup_function
 (ide
@@ -1325,33 +1325,95 @@
 ept 
-advertise.AdvertiseError:
+Exception, e:%0A    # Do a blanket except because there are many possible exception types
 %0A   
@@ -1454,13 +1454,31 @@
 tifier +
+ %22: %22 + repr(e) + 
 %22)%22%0A%0A

Add public key lookup to `advertise_lookup.py`