Add util to generate unique ids.
This commit is contained in:
parent
21d1294c7a
commit
2415fee0ed
@ -1,8 +1,6 @@
|
|||||||
import Service
|
import Service
|
||||||
import sha
|
|
||||||
import binascii
|
|
||||||
import time
|
|
||||||
|
|
||||||
|
import sugar.util
|
||||||
|
|
||||||
def is_group_service_type(stype):
|
def is_group_service_type(stype):
|
||||||
"""Return True if the service type matches a group
|
"""Return True if the service type matches a group
|
||||||
@ -11,21 +9,6 @@ def is_group_service_type(stype):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _stringify_sha(sha_hash):
|
|
||||||
"""Convert binary sha1 hash data into printable characters."""
|
|
||||||
print_sha = ""
|
|
||||||
for char in sha_hash:
|
|
||||||
print_sha = print_sha + binascii.b2a_hex(char)
|
|
||||||
return print_sha
|
|
||||||
|
|
||||||
def _sha_data(data):
|
|
||||||
"""sha1 hash some bytes."""
|
|
||||||
sha_hash = sha.new()
|
|
||||||
sha_hash.update(data)
|
|
||||||
return sha_hash.digest()
|
|
||||||
|
|
||||||
|
|
||||||
__GROUP_NAME_TAG = "Name"
|
__GROUP_NAME_TAG = "Name"
|
||||||
__GROUP_RESOURCE_TAG = "Resource"
|
__GROUP_RESOURCE_TAG = "Resource"
|
||||||
|
|
||||||
@ -37,10 +20,8 @@ def new_group_service(group_name, resource):
|
|||||||
raise ValueError("group resource must be a valid string.")
|
raise ValueError("group resource must be a valid string.")
|
||||||
|
|
||||||
# Create a randomized service type
|
# Create a randomized service type
|
||||||
data_string = "%s%s%s%s" % (time.time(), random.randint(10000, 100000), \
|
data = "%s%s" % (group_name, resource)
|
||||||
group_name, resource)
|
stype = "_%s_group_olpc._udp" % sugar.util.unique_id(data)
|
||||||
hash_string = _stringify_sha(_sha_data(data_string))
|
|
||||||
stype = "_%s_group_olpc._udp" % hash_string
|
|
||||||
|
|
||||||
properties = {__GROUP_NAME_TAG: group_name, __GROUP_RESOURCE_TAG: resource }
|
properties = {__GROUP_NAME_TAG: group_name, __GROUP_RESOURCE_TAG: resource }
|
||||||
owner_nick = ""
|
owner_nick = ""
|
||||||
|
@ -69,7 +69,7 @@ class ActivityDbusService(dbus.service.Object):
|
|||||||
SHELL_SERVICE_NAME + ".ActivityContainer")
|
SHELL_SERVICE_NAME + ".ActivityContainer")
|
||||||
|
|
||||||
self._activity_id = self._activity_container.add_activity("")
|
self._activity_id = self._activity_container.add_activity("")
|
||||||
self._object_path = SHELL_SERVICE_PATH + "/Activities/%d" % self._activity_id
|
self._object_path = SHELL_SERVICE_PATH + "/Activities/%s" % self._activity_id
|
||||||
|
|
||||||
print "ActivityDbusService: object path is '%s'" % self._object_path
|
print "ActivityDbusService: object path is '%s'" % self._object_path
|
||||||
|
|
||||||
@ -77,8 +77,8 @@ class ActivityDbusService(dbus.service.Object):
|
|||||||
SHELL_SERVICE_NAME + ".ActivityHost")
|
SHELL_SERVICE_NAME + ".ActivityHost")
|
||||||
|
|
||||||
# Now let us register a peer service so the Shell can poke it
|
# Now let us register a peer service so the Shell can poke it
|
||||||
self._peer_service_name = ACTIVITY_SERVICE_NAME + "%d" % self._activity_id
|
self._peer_service_name = ACTIVITY_SERVICE_NAME + "%s" % self._activity_id
|
||||||
self._peer_object_path = ACTIVITY_SERVICE_PATH + "/%d" % self._activity_id
|
self._peer_object_path = ACTIVITY_SERVICE_PATH + "/%s" % self._activity_id
|
||||||
self._service = dbus.service.BusName(self._peer_service_name, bus=self._bus)
|
self._service = dbus.service.BusName(self._peer_service_name, bus=self._bus)
|
||||||
dbus.service.Object.__init__(self, self._service, self._peer_object_path)
|
dbus.service.Object.__init__(self, self._service, self._peer_object_path)
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ class Activity(object):
|
|||||||
self._activity_object = activity_object
|
self._activity_object = activity_object
|
||||||
self._activity_id = activity_id
|
self._activity_id = activity_id
|
||||||
self._window_id = self._activity_object.get_host_xembed_id()
|
self._window_id = self._activity_object.get_host_xembed_id()
|
||||||
print "Activity: XEMBED window ID is %d" % self._window_id
|
print "Activity: XEMBED window ID is %s" % self._window_id
|
||||||
self._plug = gtk.Plug(self._window_id)
|
self._plug = gtk.Plug(self._window_id)
|
||||||
self.on_connected_to_shell()
|
self.on_connected_to_shell()
|
||||||
|
|
||||||
|
@ -7,26 +7,21 @@ pygtk.require('2.0')
|
|||||||
import gtk
|
import gtk
|
||||||
import pango
|
import pango
|
||||||
|
|
||||||
|
import sugar.util
|
||||||
from sugar.shell.PresenceWindow import PresenceWindow
|
from sugar.shell.PresenceWindow import PresenceWindow
|
||||||
from sugar.shell.Owner import ShellOwner
|
from sugar.shell.Owner import ShellOwner
|
||||||
|
|
||||||
activity_counter = 0
|
|
||||||
|
|
||||||
class ActivityHost(dbus.service.Object):
|
class ActivityHost(dbus.service.Object):
|
||||||
|
|
||||||
def __init__(self, activity_container, activity_name):
|
def __init__(self, activity_container, activity_name):
|
||||||
global activity_counter
|
|
||||||
|
|
||||||
self.activity_name = activity_name
|
self.activity_name = activity_name
|
||||||
self.ellipsize_tab = False
|
self.ellipsize_tab = False
|
||||||
|
|
||||||
self.activity_container = activity_container
|
self.activity_container = activity_container
|
||||||
|
|
||||||
self.activity_id = activity_counter
|
self.activity_id = sugar.util.unique_id()
|
||||||
activity_counter += 1
|
|
||||||
|
|
||||||
self.dbus_object_name = "/com/redhat/Sugar/Shell/Activities/%d" % self.activity_id
|
self.dbus_object_name = "/com/redhat/Sugar/Shell/Activities/%s" % self.activity_id
|
||||||
#print "object name = %s"%self.dbus_object_name
|
|
||||||
|
|
||||||
dbus.service.Object.__init__(self, activity_container.service, self.dbus_object_name)
|
dbus.service.Object.__init__(self, activity_container.service, self.dbus_object_name)
|
||||||
self.socket = gtk.Socket()
|
self.socket = gtk.Socket()
|
||||||
@ -290,7 +285,7 @@ class ActivityContainer(dbus.service.Object):
|
|||||||
|
|
||||||
@dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer", \
|
@dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer", \
|
||||||
in_signature="s", \
|
in_signature="s", \
|
||||||
out_signature="i", \
|
out_signature="s", \
|
||||||
sender_keyword="sender")
|
sender_keyword="sender")
|
||||||
def add_activity(self, activity_name, sender):
|
def add_activity(self, activity_name, sender):
|
||||||
#print "hello world, activity_name = '%s', sender = '%s'"%(activity_name, sender)
|
#print "hello world, activity_name = '%s', sender = '%s'"%(activity_name, sender)
|
||||||
|
Loading…
Reference in New Issue
Block a user