+random_client_id=None
+def get_random_client_id():
+ global random_client_id
+
+ if (random_client_id is None) and os.path.exists("/opt/planetstack/random_client_id"):
+ # try to use the last one we used, if we saved it
+ try:
+ random_client_id = open("/opt/planetstack/random_client_id","r").readline().strip()
+ print "get_random_client_id: loaded %s" % random_client_id
+ except:
+ print "get_random_client_id: failed to read /opt/planetstack/random_client_id"
+
+ if random_client_id is None:
+ random_client_id = base64.urlsafe_b64encode(os.urandom(12))
+ print "get_random_client_id: generated new id %s" % random_client_id
+
+ # try to save it for later (XXX: could race with another client here)
+ try:
+ open("/opt/planetstack/random_client_id","w").write("%s\n" % random_client_id)
+ except:
+ print "get_random_client_id: failed to write /opt/planetstack/random_client_id"
+
+ return random_client_id
+
+# decorator that marks dispatachable event methods