# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.
-import sys
+import sys, getopt
try:
import avahi, gobject, dbus
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 = {}
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):
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)