Hi,
I have extented the python script with to buttons: connect and quit
Too I have tried to prevent some warnings:
PYTHONVER=2.4 pychecker avahi-discover.py >> avahi-discover.warn
Warnings...
/usr/lib/python2.4/site-packages/avahi/SimpleGladeApp.py:92: Local variable
(glade_dir) shadows global defined on line 43 in file avahi-discover.py
/usr/lib/python2.4/site-packages/avahi/SimpleGladeApp.py:93: Local variable
(glade_dir) shadows global defined on line 43 in file avahi-discover.py
/usr/lib/python2.4/site-packages/avahi/SimpleGladeApp.py:114: (repr) shadows
builtin
/usr/lib/python2.4/site-packages/avahi/SimpleGladeApp.py:116: (repr) shadows
builtin
/usr/lib/python2.4/site-packages/avahi/SimpleGladeApp.py:200: Parameter (glade)
not used
/usr/lib/python2.4/site-packages/avahi/SimpleGladeApp.py:200: Parameter
(widget_name) not used
/usr/lib/python2.4/site-packages/avahi/SimpleGladeApp.py:223: Parameter (args)
not used
/usr/lib/python2.4/site-packages/avahi/SimpleGladeApp.py:231: Parameter (args)
not used
/usr/lib/python2.4/site-packages/avahi/SimpleGladeApp.py:239: Parameter (args)
not used
/usr/lib/python2.4/site-packages/avahi/SimpleGladeApp.py:247: Parameter (args)
not used
/usr/lib/python2.4/site-packages/avahi/SimpleGladeApp.py:255: Parameter (args)
not used
/usr/lib/python2.4/site-packages/avahi/SimpleGladeApp.py:255: Parameter
(window) not used
/usr/lib/python2.4/site-packages/avahi/SimpleGladeApp.py:261: No global
(widget) found
/usr/lib/python2.4/site-packages/avahi/SimpleGladeApp.py:278: Parameter (args)
not used
/usr/lib/python2.4/site-packages/avahi/SimpleGladeApp.py:334: Parameter
(glade_path) not used
avahi-discover.py:53: Parameter (args) not used
avahi-discover.py:53: Parameter (widget) not used
avahi-discover.py:58: No module attribute (startfile) found
avahi-discover.py:70: No class attribute (info_label) found
avahi-discover.py:72: Parameter (args) not used
avahi-discover.py:73: (iter) shadows builtin
avahi-discover.py:79: No class attribute (info_label) found
avahi-discover.py:103: Function (service_resolved) has too many arguments (12)
avahi-discover.py:103: Parameter (flags) not used
avahi-discover.py:126: No class attribute (info_label) found
avahi-discover.py:137: Parameter (flags) not used
avahi-discover.py:139: Comparisons with False are not necessary and may not
work as expected
avahi-discover.py:144: Comparisons with False are not necessary and may not
work as expected
avahi-discover.py:146: Comparisons with False are not necessary and may not
work as expected
avahi-discover.py:152: No class attribute (tree_view) found
avahi-discover.py:154: Parameter (flags) not used
avahi-discover.py:156: No class attribute (info_label) found
avahi-discover.py:161: Comparisons with False are not necessary and may not
work as expected
avahi-discover.py:166: Comparisons with False are not necessary and may not
work as expected
avahi-discover.py:171: Comparisons with False are not necessary and may not
work as expected
avahi-discover.py:177: Parameter (flags) not used
avahi-discover.py:207: No global (new_service_type) found
avahi-discover.py:207: No global (stype) found
avahi-discover.py:209: Parameter (flags) not used
avahi-discover.py:210: Comparisons with False are not necessary and may not
work as expected
avahi-discover.py:213: Comparisons with False are not necessary and may not
work as expected
avahi-discover.py:230: Function (update_label) has too many arguments (11)
avahi-discover.py:230: Parameter (aprotocol) not used
avahi-discover.py:240: No class attribute (info_label) found
avahi-discover.py:251: No class attribute (tree_view) found
avahi-discover.py:254: No class attribute (tree_view) found
avahi-discover.py:260: No class attribute (tree_view) found
avahi-discover.py:284: No global (domain) found
[EMAIL PROTECTED]:~/py$
And I added a optional command line argument domain name to parse.
If you find it a goot idea, please check it in.
claus
--- avahi-0.6.9.orig/avahi-discover-standalone/avahi-discover.glade 2006-03-25 18:47:40.000000000 +0100
+++ avahi-0.6.9/avahi-discover-standalone/avahi-discover.glade 2006-03-25 18:48:14.000000000 +0100
@@ -4,26 +4,30 @@
<glade-interface>
<widget class="GtkWindow" id="main_window">
+ <property name="width_request">520</property>
+ <property name="height_request">620</property>
<property name="visible">True</property>
<property name="title" translatable="yes">Avahi Discovery</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
- <property name="default_width">500</property>
- <property name="default_height">400</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
+ <property name="icon_name">gtk-network</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
- <signal handler="gtk_main_quit" name="destroy" after="False"/>
+ <property name="urgency_hint">False</property>
+ <signal name="destroy" handler="gtk_main_quit"/>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="border_width">12</property>
+ <property name="width_request">420</property>
+ <property name="height_request">520</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">12</property>
@@ -39,12 +43,13 @@
<child>
<widget class="GtkTreeView" id="tree_view">
+ <property name="height_request">300</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">True</property>
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
- <property name="enable_search">True</property>
+ <property name="enable_search">False</property>
<property name="fixed_height_mode">False</property>
<property name="hover_selection">False</property>
<property name="hover_expand">False</property>
@@ -53,7 +58,7 @@
</child>
</widget>
<packing>
- <property name="padding">0</property>
+ <property name="padding">2</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
@@ -61,6 +66,7 @@
<child>
<widget class="GtkLabel" id="info_label">
+ <property name="height_request">100</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes"><i>No service currently selected.</i></property>
@@ -79,11 +85,45 @@
<property name="angle">0</property>
</widget>
<packing>
- <property name="padding">0</property>
+ <property name="padding">2</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
+
+ <child>
+ <widget class="GtkButton" id="button1">
+ <property name="visible">True</property>
+ <property name="tooltip">Open a client session to the discovered service</property>
+ <property name="label">gtk-connect</property>
+ <property name="use_stock">True</property>
+ <property name="relief">GTK_RELIEF_HALF</property>
+ <property name="focus_on_click">True</property>
+ <signal name="clicked" handler="on_button1_clicked" last_modification_time="Thu, 25 Mar 2004 16:36:54 GMT"/>
+ </widget>
+ <packing>
+ <property name="padding">2</property>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkButton" id="button2">
+ <property name="visible">True</property>
+ <property name="tooltip">Quit this service discovery program</property>
+ <property name="label">gtk-quit</property>
+ <property name="use_stock">True</property>
+ <property name="relief">GTK_RELIEF_HALF</property>
+ <property name="focus_on_click">True</property>
+ <signal name="clicked" handler="gtk_main_quit"/>
+ </widget>
+ <packing>
+ <property name="padding">2</property>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
</widget>
</child>
</widget>
--- avahi-0.6.9.orig/avahi-python/avahi-discover.in 2006-03-25 18:43:36.000000000 +0100
+++ avahi-0.6.9/avahi-python/avahi-discover.in 2006-03-25 18:50:15.000000000 +0100
@@ -42,14 +42,39 @@
class Main_window(SimpleGladeApp):
def __init__(self, path="avahi-discover.glade", root="main_window", domain=None, **kwargs):
+ if not domain is None:
+ print "The the user wants us to browse the domain '%s'" % domain
+ self.domain = domain
path = os.path.join(glade_dir, path)
gtk.window_set_default_icon_name("gnome-networktool")
SimpleGladeApp.__init__(self, path, root, domain, **kwargs)
+ def on_button1_clicked(self, widget, *args):
+ url = "%s://%s:%i" % (self.protocol, self.address, self.port)
+ cmd = url
+ if self.protocol == "ssh" or self.protocol == "http" or self.protocol == "snmp":
+ if sys.platform == "win32":
+ os.startfile(url)
+ else:
+ if self.protocol == "snmp":
+ cmd = "xterm -e \'snmpstatus %s; sleep 5 \'&" % (self.address)
+ os.system(cmd) # do not wait
+ elif self.protocol == "ssh":
+ cmd = "xterm -e \'%s [EMAIL PROTECTED] \'&" % (self.protocol, self.address)
+ os.system(cmd) # do not wait
+ else: # see too http://www.mozilla.org/unix/remote.html
+ cmd = "firefox -remote \'openURL(%s,new-tab)\' || firefox \'%s \'&" % (url, url)
+ os.system(cmd) # do not wait
+ print "System:", str(cmd)
+ self.info_label.set_markup("<b>%s</b>" % url)
+
def on_tree_view_cursor_changed(self, widget, *args):
- (model, iter) = widget.get_selection().get_selected()
- (name,interface,protocol,stype,domain) = self.treemodel.get(iter,1,2,3,4,5)
+ (model, myiter) = widget.get_selection().get_selected()
+ (name,interface,protocol,stype,domain) = self.treemodel.get(myiter,1,2,3,4,5)
if stype == None:
+ self.protocol = None
+ self.address = None
+ self.port = None
self.info_label.set_markup("<i>No service currently selected.</i>")
return
#Asynchronous resolving
@@ -61,7 +86,7 @@
if protocol == avahi.PROTO_INET6:
return "IPv6"
return "n/a"
-
+
def siocgifname(self, interface):
if interface <= 0:
return "n/a"
@@ -73,16 +98,33 @@
return "Wide Area"
else:
return str(self.siocgifname(interface)) + " " + str(self.protoname(protocol))
-
- def service_resolved(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
+
+ def service_resolved(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags=None):
+ # FIXME: Function (service_resolved) has too many arguments (12)
+ if stype == "_snmp._tcp":
+ self.protocol = "snmp"
+ elif stype == "_http._tcp":
+ self.protocol = "http"
+ elif stype == "_ssh._tcp" or stype == "_workstation._tcp":
+ self.protocol = "ssh"
+ else:
+ self.protocol = stype
+ self.address = address
+ self.port = port
+
print "Service data for service '%s' of type '%s' in domain '%s' on %i.%i:" % (name, stype, domain, interface, protocol)
+ print "aprotocol=", str(aprotocol) ###tbd###
+ print "flags=", str(flags) ###tbd###
print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, str(avahi.txt_array_to_string_array(txt)))
self.update_label(interface, protocol, name, stype, domain, host, aprotocol, address, port, avahi.txt_array_to_string_array(txt))
-
+
def print_error(self, err):
error_label = "<b>Error:</b> %s" % (err)
+ self.protocol = None
+ self.address = None
+ self.port = None
self.info_label.set_markup(error_label)
print "Error:", str(err)
@@ -93,13 +135,14 @@
return service_type_db[stype]
except KeyError:
return stype
-
+
def new_service(self, interface, protocol, name, stype, domain, flags):
print "Found service '%s' of type '%s' in domain '%s' on %i.%i." % (name, stype, domain, interface, protocol)
+ print "flags=", str(flags) ###tbd###
if self.zc_ifaces.has_key((interface,protocol)) == False:
ifn = self.get_interface_name(interface, protocol)
-
+
self.zc_ifaces[(interface,protocol)] = self.insert_row(self.treemodel, None, ifn, None,interface,protocol,None,domain)
if self.zc_domains.has_key((interface,protocol,domain)) == False:
self.zc_domains[(interface,protocol,domain)] = self.insert_row(self.treemodel, self.zc_ifaces[(interface,protocol)], domain,None,interface,protocol,None,domain)
@@ -113,6 +156,7 @@
def remove_service(self, interface, protocol, name, stype, domain, flags):
print "Service '%s' of type '%s' in domain '%s' on %i.%i disappeared." % (name, stype, domain, interface, protocol)
+ print "flags=", str(flags) ###tbd###
self.info_label.set_markup("")
treeiter=self.services_browsed[(interface, protocol, name, stype, domain)]
parent = self.treemodel.iter_parent(treeiter)
@@ -133,23 +177,24 @@
parent = self.treemodel.iter_parent(treeiter)
self.treemodel.remove(treeiter)
del self.zc_ifaces[(interface,protocol)]
-
+
def new_service_type(self, interface, protocol, stype, domain, flags):
global service_browsers
- # Are we already browsing this domain for this type?
+ # Are we already browsing this domain for this type?
if service_browsers.has_key((interface, protocol, stype, domain)):
return
-
+
print "Browsing for services of type '%s' in domain '%s' on %i.%i ..." % (stype, domain, interface, protocol)
-
+ print "flags=", str(flags) ###tbd###
+
b = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceBrowserNew(interface, protocol, stype, domain, dbus.UInt32(0))), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
b.connect_to_signal('ItemNew', self.new_service)
b.connect_to_signal('ItemRemove', self.remove_service)
service_browsers[(interface, protocol, stype, domain)] = b
- def browse_domain(self, interface, protocol, domain):
+ def browse_domain(self, interface, protocol, domain, flags=None):
global service_type_browsers
# Are we already browsing this domain?
@@ -158,13 +203,14 @@
if self.stype is None:
print "Browsing domain '%s' on %i.%i ..." % (domain, interface, protocol)
-
+ print "flags=", str(flags) ###tbd###
+
b = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.ServiceTypeBrowserNew(interface, protocol, domain, dbus.UInt32(0))), avahi.DBUS_INTERFACE_SERVICE_TYPE_BROWSER)
b.connect_to_signal('ItemNew', self.new_service_type)
service_type_browsers[(interface, protocol, domain)] = b
else:
- new_service_type(interface, protocol, stype, domain)
+ self.new_service_type(interface, protocol, self.stype, domain, flags)
def new_domain(self,interface, protocol, domain, flags):
if self.zc_ifaces.has_key((interface,protocol)) == False:
@@ -173,7 +219,7 @@
if self.zc_domains.has_key((interface,protocol,domain)) == False:
self.zc_domains[(interface,protocol,domain)] = self.insert_row(self.treemodel, self.zc_ifaces[(interface,protocol)], domain,None,interface,protocol,None,domain)
if domain != "local":
- self.browse_domain(interface, protocol, domain)
+ self.browse_domain(interface, protocol, domain, flags)
def pair_to_dict(self, l):
res = dict()
@@ -185,9 +231,11 @@
if len(tmp[0]) > 0:
res[tmp[0]] = tmp[1]
return res
-
+
def update_label(self,interface, protocol, name, stype, domain, host, aprotocol, address, port, txt):
+ # FIXME: Function (update_label) has too many arguments (11)
+ # FIXME: Parameter (aprotocol) not used
if len(txt) != 0:
txts = ""
txtd = self.pair_to_dict(txt)
@@ -219,34 +267,41 @@
column.set_expand(True);
self.tree_view.append_column(column)
- self.domain = None
- self.stype = None
+ # self.domain = None ###tbd### never set? ck
+ self.stype = None ###tbd### never set? ck
+ self.protocol = None
+ self.address = None
+ self.port = None
self.zc_ifaces = {}
self.zc_domains = {}
self.zc_types = {}
self.services_browsed = {}
-
+
self.bus = dbus.SystemBus()
self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
if self.domain is None:
- # Explicitly browse .local
+ print "Explicitly browse .local:"
self.browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "local")
-
- # Browse for other browsable domains
+
+ print "Browse for other browsable domains:"
db = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.DomainBrowserNew(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, "", avahi.DOMAIN_BROWSER_BROWSE, dbus.UInt32(0))), avahi.DBUS_INTERFACE_DOMAIN_BROWSER)
db.connect_to_signal('ItemNew', self.new_domain)
else:
- # Just browse the domain the user wants us to browse
- self.browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, domain)
+ print "Just browse the domain %s the user wants us to browse" % self.domain
+ self.browse_domain(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, self.domain)
-
-def main():
- main_window = Main_window()
+
+def main(domain=None, **kwargs):
+ main_window = Main_window(domain=domain, **kwargs)
main_window.run()
-
+
if __name__ == "__main__":
- main()
+ if len(sys.argv) > 1 :
+ domain=sys.argv[1]
+ else:
+ domain=None
+ main(domain)
-
+# vim:tabstop=4 shiftwidth=4 expandtab
_______________________________________________
avahi mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/avahi