conduit r1201 - in trunk: . conduit/modules/NetworkModule



Author: johncarr
Date: Sat Jan 12 12:18:23 2008
New Revision: 1201
URL: http://svn.gnome.org/viewvc/conduit?rev=1201&view=rev

Log:
No more python-avahi dep

Modified:
   trunk/ChangeLog
   trunk/conduit/modules/NetworkModule/Peers.py

Modified: trunk/conduit/modules/NetworkModule/Peers.py
==============================================================================
--- trunk/conduit/modules/NetworkModule/Peers.py	(original)
+++ trunk/conduit/modules/NetworkModule/Peers.py	Sat Jan 12 12:18:23 2008
@@ -24,6 +24,26 @@
 PORT_IDX = 0
 VERSION_IDX = 1
 
+def byte_array_to_string(s):
+    r = ""
+    
+    for c in s:
+        
+        if c >= 32 and c < 127:
+            r += "%c" % c
+        else:
+            r += "."
+
+    return r
+
+def txt_array_to_string_array(t):
+    l = []
+
+    for s in t:
+        l.append(byte_array_to_string(s))
+
+    return l
+
 def decode_avahi_text_array_to_dict(array):
     """
     Avahi text arrays are encoded as key=value
@@ -60,10 +80,10 @@
         bus = dbus.SystemBus()
         server = dbus.Interface(
                         bus.get_object(
-                            avahi.DBUS_NAME, 
-                            avahi.DBUS_PATH_SERVER
+                            DBUS_NAME, 
+                            DBUS_PATH_SERVER
                             ), 
-                        avahi.DBUS_INTERFACE_SERVER
+                        DBUS_INTERFACE_SERVER
                         )
 
         # Get this device's hostname
@@ -72,8 +92,8 @@
         # Register this service
         path = server.EntryGroupNew()
         self.group = dbus.Interface(
-                    bus.get_object(avahi.DBUS_NAME, path), 
-                    avahi.DBUS_INTERFACE_ENTRY_GROUP
+                    bus.get_object(DBUS_NAME, path), 
+                    DBUS_INTERFACE_ENTRY_GROUP
                     )
 
     def announce(self):
@@ -82,15 +102,15 @@
         """
         log.debug("Announcing avahi conduit service")
         self.group.AddService(
-                avahi.IF_UNSPEC,        #interface
-                avahi.PROTO_UNSPEC,     #protocol
+                IF_UNSPEC,        #interface
+                PROTO_UNSPEC,     #protocol
                 0,                      #flags
                 self.hostname,          #name
                 AVAHI_SERVICE_NAME,     #service type
                 AVAHI_SERVICE_DOMAIN,   #domain
                 '',                     #host
                 self.port,              #port
-                avahi.string_array_to_txt_array(["version=%s" % conduit.APPVERSION])
+                string_array_to_txt_array(["version=%s" % conduit.APPVERSION])
                 )
         self.group.Commit()
             
@@ -116,23 +136,23 @@
         bus = dbus.SystemBus()
         self.server = dbus.Interface(
                             bus.get_object(
-                                avahi.DBUS_NAME,
-                                avahi.DBUS_PATH_SERVER),
-                            avahi.DBUS_INTERFACE_SERVER)
+                                DBUS_NAME,
+                                DBUS_PATH_SERVER),
+                            DBUS_INTERFACE_SERVER)
 
         self.hostname = self.server.GetHostName()
 
         obj = bus.get_object(
-                            avahi.DBUS_NAME,
+                            DBUS_NAME,
                             self.server.ServiceBrowserNew(
-                                avahi.IF_UNSPEC,
-                                avahi.PROTO_UNSPEC,
+                                IF_UNSPEC,
+                                PROTO_UNSPEC,
                                 AVAHI_SERVICE_NAME, 
                                 AVAHI_SERVICE_DOMAIN,
                                 dbus.UInt32(0)
                                 )
                             )
-        browser = dbus.Interface(obj, avahi.DBUS_INTERFACE_SERVICE_BROWSER)
+        browser = dbus.Interface(obj, DBUS_INTERFACE_SERVICE_BROWSER)
         browser.connect_to_signal('ItemNew', self._new_service)
         browser.connect_to_signal('ItemRemove', self._remove_service)
 
@@ -140,7 +160,7 @@
         """
         DBus callback when a new service is detected
         """
-        #if flags & avahi.LOOKUP_RESULT_OUR_OWN:
+        #if flags & LOOKUP_RESULT_OUR_OWN:
         #    return
 
         service = self.server.ResolveService(
@@ -149,7 +169,7 @@
                                         name, 
                                         type, 
                                         domain,
-                                        avahi.PROTO_UNSPEC, 
+                                        PROTO_UNSPEC, 
                                         dbus.UInt32(0),
                                         reply_handler = self._resolve_service, 
                                         error_handler = self._resolve_error
@@ -159,7 +179,7 @@
         """
         Dbus callback
         """
-        extra_info = avahi.txt_array_to_string_array(txt)
+        extra_info = txt_array_to_string_array(txt)
         extra = decode_avahi_text_array_to_dict(extra_info)
 
         log.debug("Resolved conduit service %s on %s - %s:%s\nExtra Info: %s" % (name, host, address, port, extra_info))
@@ -183,3 +203,56 @@
         """
         log.warn("Avahi/D-Bus error: %s" % repr(error))
 
+
+DBUS_INTERFACE_ADDRESS_RESOLVER = 'org.freedesktop.Avahi.AddressResolver'
+DBUS_INTERFACE_DOMAIN_BROWSER = 'org.freedesktop.Avahi.DomainBrowser'
+DBUS_INTERFACE_ENTRY_GROUP = 'org.freedesktop.Avahi.EntryGroup'
+DBUS_INTERFACE_HOST_NAME_RESOLVER = 'org.freedesktop.Avahi.HostNameResolver'
+DBUS_INTERFACE_RECORD_BROWSER = 'org.freedesktop.Avahi.RecordBrowser'
+DBUS_INTERFACE_SERVER = 'org.freedesktop.Avahi.Server'
+DBUS_INTERFACE_SERVICE_BROWSER = 'org.freedesktop.Avahi.ServiceBrowser'
+DBUS_INTERFACE_SERVICE_RESOLVER = 'org.freedesktop.Avahi.ServiceResolver'
+DBUS_INTERFACE_SERVICE_TYPE_BROWSER = 'org.freedesktop.Avahi.ServiceTypeBrowser'
+DBUS_NAME = 'org.freedesktop.Avahi'
+DBUS_PATH_SERVER = '/'
+DOMAIN_BROWSER_BROWSE = 0
+DOMAIN_BROWSER_BROWSE_DEFAULT = 1
+DOMAIN_BROWSER_BROWSE_LEGACY = 4
+DOMAIN_BROWSER_REGISTER = 2
+DOMAIN_BROWSER_REGISTER_DEFAULT = 3
+ENTRY_GROUP_COLLISION = 3
+ENTRY_GROUP_ESTABLISHED = 2
+ENTRY_GROUP_FAILURE = 4
+ENTRY_GROUP_REGISTERING = 1
+ENTRY_GROUP_UNCOMMITED = 0
+IF_UNSPEC = -1
+LOOKUP_NO_ADDRESS = 8
+LOOKUP_NO_TXT = 4
+LOOKUP_RESULT_CACHED = 1
+LOOKUP_RESULT_LOCAL = 8
+LOOKUP_RESULT_MULTICAST = 4
+LOOKUP_RESULT_OUR_OWN = 16
+LOOKUP_RESULT_STATIC = 32
+LOOKUP_RESULT_WIDE_AREA = 2
+LOOKUP_USE_MULTICAST = 2
+LOOKUP_USE_WIDE_AREA = 1
+PROTO_INET = 0
+PROTO_INET6 = 1
+PROTO_UNSPEC = -1
+PUBLISH_ALLOW_MULTIPLE = 8
+PUBLISH_NO_ANNOUNCE = 4
+PUBLISH_NO_COOKIE = 32
+PUBLISH_NO_PROBE = 2
+PUBLISH_NO_REVERSE = 16
+PUBLISH_UNIQUE = 1
+PUBLISH_UPDATE = 64
+PUBLISH_USE_MULTICAST = 256
+PUBLISH_USE_WIDE_AREA = 128
+SERVER_COLLISION = 3
+SERVER_FAILURE = 4
+SERVER_INVALID = 0
+SERVER_REGISTERING = 1
+SERVER_RUNNING = 2
+SERVICE_COOKIE = 'org.freedesktop.Avahi.cookie'
+SERVICE_COOKIE_INVALID = 0
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]