]> git.meshlink.io Git - catta/blobdiff - avahi-python/avahi-bookmarks.in
add man page for avahi-set-host-name
[catta] / avahi-python / avahi-bookmarks.in
index 74037bbc2298adf4a83dd002f3420a75ac801bef..6466a221de28c1236484ce5c11974bad4d1e2a1b 100755 (executable)
@@ -33,8 +33,8 @@ except ImportError:
     pass
 
 try:
-    from twisted.internet import gtk2reactor
-    gtk2reactor.install()
+    from twisted.internet import glib2reactor
+    glib2reactor.install()
     from twisted.internet import reactor
     from twisted.web import server, resource
 except ImportError:
@@ -45,7 +45,7 @@ urlproto = { "_http._tcp" : "http",  "_https._tcp" : "https", "_ftp._tcp" : "ftp
 
 port = 8080
 address = "127.0.0.1"
-use_host_names = False
+use_host_names = None
 domain = "local"
 
 class AvahiBookmarks(resource.Resource):
@@ -53,7 +53,7 @@ class AvahiBookmarks(resource.Resource):
 
     services = {}
 
-    def __init__(self):
+    def __init__(self, use_host_names):
         resource.Resource.__init__(self)
 
         self.bus = dbus.SystemBus()
@@ -65,6 +65,14 @@ class AvahiBookmarks(resource.Resource):
         self.browse_service_type("_https._tcp")
         self.browse_service_type("_ftp._tcp")
 
+        if use_host_names is None:
+            try: 
+                self.use_host_names = self.server.IsNSSSupportAvailable()
+            except:
+                self.use_host_names = False
+        else:
+            self.use_host_names = use_host_names
+
     def browse_service_type(self, stype):
 
         global domain
@@ -109,14 +117,14 @@ class AvahiBookmarks(resource.Resource):
         
         t += '<hr noshade/><p style="font-size: 8; font-family: sans-serif">Served by %s</p></body></html>' % self.version_string
 
-        return t
+        return str(t)
 
 
     def new_service(self, interface, protocol, name, type, domain, flags):
 
         interface, protocol, name, type, domain, host, aprotocol, address, port, txt, flags = self.server.ResolveService(interface, protocol, name, type, domain, avahi.PROTO_UNSPEC, dbus.UInt32(0))
 
-        if use_host_names:
+        if self.use_host_names:
             h = host
         else:
             if aprotocol == avahi.PROTO_INET6:
@@ -135,12 +143,13 @@ def usage(retval = 0):
     print "   -h --help             Show this help"
     print "   -p --port PORT        Specify the port to use (default %u)" % port
     print "   -a --address ADDRESS  Specify the address to bind to (default %s)" % address
-    print "   -H --host-names       Show all services, regardless of the type"
+    print "   -H --host-names       Show links with real hostnames"
+    print "   -A --addresses        Show links with numeric IP addresses"
     print "   -d --domain DOMAIN    Specify the domain to browse" 
     sys.exit(retval)
 
 try:
-    opts, args = getopt.getopt(sys.argv[1:], "hp:a:Hd:", ["help", "port=", "address=", "host-names", "domain="])
+    opts, args = getopt.getopt(sys.argv[1:], "hp:a:HAd:", ["help", "port=", "address=", "host-names", "addresses", "domain="])
 except getopt.GetoptError:
     usage(2)
 
@@ -157,10 +166,13 @@ for o, a in opts:
     if o in ("-H", "--host-names"):
         use_host_names = True
 
+    if o in ("-A", "--addresses"):
+        use_host_names = False
+
     if o in ("-d", "--domain"):
         domain = a
-    
-site = server.Site(AvahiBookmarks())
+
+site = server.Site(AvahiBookmarks(use_host_names))
 reactor.listenTCP(port, site, interface=address)
 
 print "Now point your web browser to http://%s:%u/!" % (address, port)