Change avahi-dump-all to accept service type to browse for
authorLennart Poettering <lennart@poettering.net>
Sat, 6 Aug 2005 01:20:28 +0000 (01:20 +0000)
committerLennart Poettering <lennart@poettering.net>
Sat, 6 Aug 2005 01:20:28 +0000 (01:20 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@243 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-utils/avahi-dump-all.in
avahi-utils/avahi-publish-service.in

index c90e964..69a8bfd 100755 (executable)
@@ -19,7 +19,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 # USA.
 
-import sys
+import sys, getopt
 
 try:
     import avahi, gobject, dbus
@@ -32,6 +32,41 @@ try:
 except ImportError, e:
     pass
 
+def usage(retval = 0):
+    print "%s [options] <type>\n" % sys.argv[0]
+    print "   -h --help      Show this help"
+    print "   -d --domain    The domain to browse"
+    print "   -a --all       Show all services, regardless of the type"
+    sys.exit(retval)
+
+try:
+    opts, args = getopt.getopt(sys.argv[1:], "hd:a", ["help", "domain=", "all"])
+except getopt.GetoptError:
+    usage(2)
+
+domain = None
+stype = None
+show_all = False
+    
+for o, a in opts:
+    if o in ("-h", "--help"):
+        usage()
+
+    if o in ("-d", "--domain"):
+        domain = a
+
+    if o in ("-a", "--all"):
+        show_all = True
+
+if len(args) > 1:
+    usage(2)
+
+if len(args) >= 1:
+    stype = args[0];
+
+if stype is None and not show_all:
+    usage(2)
+
 service_type_browsers = {}
 service_browsers = {}
 
@@ -77,18 +112,21 @@ def new_service_type(interface, protocol, type, domain):
     service_browsers[(interface, protocol, type, domain)] = b
 
 def browse_domain(interface, protocol, domain):
-    global server, service_type_browsers
+    global server, service_type_browsers, stype
 
     # Are we already browsing this domain?
     if service_type_browsers.has_key((interface, protocol, domain)):
         return
 
-    print "Browsing domain '%s' on %s.%i ..." % (domain, siocgifname(interface), protocol)
-    
-    b = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceTypeBrowserNew(interface, protocol, domain)), avahi.DBUS_INTERFACE_SERVICE_TYPE_BROWSER)
-    b.connect_to_signal('ItemNew', new_service_type)
+    if stype is None:
+        print "Browsing domain '%s' on %s.%i ..." % (domain, siocgifname(interface), protocol)
 
-    service_type_browsers[(interface, protocol, domain)] = b
+        b = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.ServiceTypeBrowserNew(interface, protocol, domain)), avahi.DBUS_INTERFACE_SERVICE_TYPE_BROWSER)
+        b.connect_to_signal('ItemNew', new_service_type)
+
+        service_type_browsers[(interface, protocol, domain)] = b
+    else:
+        new_service_type(interface, protocol, stype, domain)
 
 def new_domain(interface, protocol, domain):
 
@@ -97,11 +135,6 @@ def new_domain(interface, protocol, domain):
         browse_domain(interface, protocol, domain)
 
 
-domain = None
-
-if len(sys.argv) > 1:
-    domain = sys.argv[1]
-        
 bus = dbus.SystemBus()
 server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
 
index 3000ea9..50b1908 100755 (executable)
@@ -40,7 +40,7 @@ def usage(retval = 0):
     sys.exit(retval)
 
 try:
-    opts, args = getopt.getopt(sys.argv[1:], "d:H:", ["help", "domain=", "host="])
+    opts, args = getopt.getopt(sys.argv[1:], "hd:H:", ["help", "domain=", "host="])
 except getopt.GetoptError:
     usage(2)