From 1180ca5544328d79ae4032a1855d2ec788ecda4d Mon Sep 17 00:00:00 2001 From: Sebastien Estienne Date: Tue, 4 Oct 2005 01:42:09 +0000 Subject: * small fix everywhere git-svn-id: file:///home/lennart/svn/public/service-discovery-applet/trunk@33 3be567f1-68ff-0310-b24a-ad7cc433fd2f --- INSTALL | 2 +- README | 6 ++ TODO | 9 ++- actions/services/Makefile.am | 10 +++- actions/services/__init__.py | 112 ------------------------------------ actions/services/__init__.py.in | 124 ++++++++++++++++++++++++++++++++++++++++ src/service-discovery-applet.in | 4 ++ 7 files changed, 151 insertions(+), 116 deletions(-) delete mode 100755 actions/services/__init__.py create mode 100755 actions/services/__init__.py.in diff --git a/INSTALL b/INSTALL index 315415f..e9ee4a9 100644 --- a/INSTALL +++ b/INSTALL @@ -1 +1 @@ -./configure --prefix=/usr --sysconfdir=/etc && make && make install +./configure --prefix=/usr --sysconfdir=/etc && make && sudo make install diff --git a/README b/README index a9a8181..0cc8bc6 100644 --- a/README +++ b/README @@ -1,3 +1,9 @@ +requirements: + avahi >= 0.5 +python2.4-gnome2 +python2.4-gnome2 + + You should may have to log out, or restart gnome-panel before being able to use your new applet. You should test that the applet is functionning with the following command: diff --git a/TODO b/TODO index b193144..1123ac5 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,10 @@ * fix ipv6 -* option to not browse our own services * finnish python's plugins -* check adding services * fix transparency when right-clicking +* nicer icons in error notifications + +fix: +** (Service discovery applet:29450): WARNING **: need to free the control here + +./service-discovery-applet:90: GtkWarning: Attempting to add a widget with type GtkEventBox to a PanelApplet, but as a GtkBin subclass a PanelApplet can only contain one widget at a time; it already contains a widget of type GtkEventBox + self.applet.add(self.eb) diff --git a/actions/services/Makefile.am b/actions/services/Makefile.am index 2a28c48..50aa099 100644 --- a/actions/services/Makefile.am +++ b/actions/services/Makefile.am @@ -2,4 +2,12 @@ servicesdir = $(ACTIONSDIR)/services services_SCRIPTS = \ __init__.py -EXTRA_DIST = $(services_SCRIPTS) +__init__.py: __init__.py.in + sed \ + -e 's,@PYTHON\@,$(PYTHON),g' \ + $< > $@ + chmod +x $@ + + + +EXTRA_DIST = __init__.py.in diff --git a/actions/services/__init__.py b/actions/services/__init__.py deleted file mode 100755 index 748e53c..0000000 --- a/actions/services/__init__.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/python - -import subprocess -import gnome - -def pair_to_dict(l): - res = dict() - for el in l: - if "=" not in el: - res[el]='' - else: - tmp = el.split('=',1) - if len(tmp[0]) > 0: - res[tmp[0]] = tmp[1] - return res - - -def build_url(uri = "http", hostname="127.0.0.1", port = None, path = None, username = None, password = None): - if path and path != None: - if path[0] == "/": - path = path[1:] - else: - path = "" - - if username: - if password: - username="%s:%s@" % (username,password) - else: - username="%s@" % (username) - else: - username="" - if port and port != None: - hostname="%s:%i" % (hostname,port) - return "%s://%s%s/%s" % (uri,username,hostname,path) - -def get_txt_value(txts, txt): - if txts.has_key(txt): - return txts[txt] - else: - return None - - -def _http_tcp(name, hostname, address, port, txts): - path = get_txt_value(txts,"path") - username = get_txt_value(txts,"u") - password = get_txt_value(txts,"p") - url = build_url("http",address,port, path, username,password) - gnome.url_show(url) - -def _https_tcp(name, hostname, address, port, txts): - path = get_txt_value(txts,"path") - username = get_txt_value(txts,"u") - password = get_txt_value(txts,"p") - url = build_url("https",address,port, path, username,password) - gnome.url_show(url) - -def _ftp_tcp(name, hostname, address, port, txts): - path = get_txt_value(txts,"path") - username = get_txt_value(txts,"u") - password = get_txt_value(txts,"p") - url = build_url("ftp",address,port, path, username,password) - gnome.url_show(url) - -def _ssh_tcp(name, hostname, address, port, txts): - if txts.has_key("u"): - sshline = "ssh -l %s -p %i %s" % (txts["u"], port, address) - else: - sshline = "ssh -p %i %s" % (port, address) - - cmdline = [] - cmdline.append("gnome-terminal") - cmdline.append("--tab") - cmdline.append("-t %s" % name) - cmdline.append("-e %s" % sshline) - pid = subprocess.Popen(cmdline).pid - -def _sftpssh_tcp(name, hostname, address, port, txts): - path = get_txt_value(txts,"path") - username = get_txt_value(txts,"u") - password = get_txt_value(txts,"p") - url = build_url("ftp",address,port, path, username,password) - gnome.url_show(url) - -def handle(name, stype, hostname, address, port, txts): - if stype == "_http._tcp": - _http_tcp(name, hostname, address, port, txts) - return - if stype == "_https._tcp": - _https_tcp(name, hostname, address, port, txts) - return - if stype == "_ftp._tcp": - _ftp_tcp(name, hostname, address, port, txts) - return - if stype == "_ssh._tcp": - _ssh_tcp(name, hostname, address, port, txts) - return - if stype == "_sftp-ssh._tcp": - _sftpssh_tcp(name, hostname, address, port, txts) - return - - -if __name__ == "__main__": - print build_url() - print build_url("ftp") - print build_url("https","www.google.com") - print build_url("https","www.google.com",80) - print build_url("https","www.google.com",80) - print build_url("https","www.google.com",80,"test") - print build_url("https","www.google.com",80,"/test") - print build_url("https","www.google.com",80,"/test", "user") - print build_url("https","www.google.com",0, "", None, "pass") - print build_url("https","www.google.com",80,"/test", "user", "pass") diff --git a/actions/services/__init__.py.in b/actions/services/__init__.py.in new file mode 100755 index 0000000..dc64db4 --- /dev/null +++ b/actions/services/__init__.py.in @@ -0,0 +1,124 @@ +#!@PYTHON@ +# -*-python-*- +# Copyright (C) 2005 by Sebastien Estienne +# +# This file may be distributed and/or modified under the terms of +# the GNU General Public License version 2 as published by +# the Free Software Foundation. +# This file is distributed without any warranty; without even the implied +# warranty of merchantability or fitness for a particular purpose. +# See "COPYING" in the source distribution for more information. +# +# $id$ +# + +import subprocess +import gnome + +def pair_to_dict(l): + res = dict() + for el in l: + if "=" not in el: + res[el]='' + else: + tmp = el.split('=',1) + if len(tmp[0]) > 0: + res[tmp[0]] = tmp[1] + return res + + +def build_url(uri = "http", hostname="127.0.0.1", port = None, path = None, username = None, password = None): + if path and path != None: + if path[0] == "/": + path = path[1:] + else: + path = "" + + if username: + if password: + username="%s:%s@" % (username,password) + else: + username="%s@" % (username) + else: + username="" + if port and port != None: + hostname="%s:%i" % (hostname,port) + return "%s://%s%s/%s" % (uri,username,hostname,path) + +def get_txt_value(txts, txt): + if txts.has_key(txt): + return txts[txt] + else: + return None + + +def _http_tcp(name, hostname, address, port, txts): + path = get_txt_value(txts,"path") + username = get_txt_value(txts,"u") + password = get_txt_value(txts,"p") + url = build_url("http",address,port, path, username,password) + gnome.url_show(url) + +def _https_tcp(name, hostname, address, port, txts): + path = get_txt_value(txts,"path") + username = get_txt_value(txts,"u") + password = get_txt_value(txts,"p") + url = build_url("https",address,port, path, username,password) + gnome.url_show(url) + +def _ftp_tcp(name, hostname, address, port, txts): + path = get_txt_value(txts,"path") + username = get_txt_value(txts,"u") + password = get_txt_value(txts,"p") + url = build_url("ftp",address,port, path, username,password) + gnome.url_show(url) + +def _ssh_tcp(name, hostname, address, port, txts): + if txts.has_key("u"): + sshline = "ssh -l %s -p %i %s" % (txts["u"], port, address) + else: + sshline = "ssh -p %i %s" % (port, address) + + cmdline = [] + cmdline.append("gnome-terminal") + cmdline.append("--tab") + cmdline.append("-t %s" % name) + cmdline.append("-e %s" % sshline) + pid = subprocess.Popen(cmdline).pid + +def _sftpssh_tcp(name, hostname, address, port, txts): + path = get_txt_value(txts,"path") + username = get_txt_value(txts,"u") + password = get_txt_value(txts,"p") + url = build_url("ftp",address,port, path, username,password) + gnome.url_show(url) + +def handle(name, stype, hostname, address, port, txts): + if stype == "_http._tcp": + _http_tcp(name, hostname, address, port, txts) + return + if stype == "_https._tcp": + _https_tcp(name, hostname, address, port, txts) + return + if stype == "_ftp._tcp": + _ftp_tcp(name, hostname, address, port, txts) + return + if stype == "_ssh._tcp": + _ssh_tcp(name, hostname, address, port, txts) + return + if stype == "_sftp-ssh._tcp": + _sftpssh_tcp(name, hostname, address, port, txts) + return + + +if __name__ == "__main__": + print build_url() + print build_url("ftp") + print build_url("https","www.google.com") + print build_url("https","www.google.com",80) + print build_url("https","www.google.com",80) + print build_url("https","www.google.com",80,"test") + print build_url("https","www.google.com",80,"/test") + print build_url("https","www.google.com",80,"/test", "user") + print build_url("https","www.google.com",0, "", None, "pass") + print build_url("https","www.google.com",80,"/test", "user", "pass") diff --git a/src/service-discovery-applet.in b/src/service-discovery-applet.in index 088d14b..41d9445 100755 --- a/src/service-discovery-applet.in +++ b/src/service-discovery-applet.in @@ -201,8 +201,12 @@ class ServiceDiscoveryApplet(gnomeapplet.Applet): print "Service '%s' of type '%s' in domain '%s' on %s.%i disappeared." % (name, type, domain, self.siocgifname(interface), protocol) if self.show_local_services == False: + # FIXME avahi bug? if self.server.IsServiceLocal( interface, protocol, name, type, domain) == True: + print "is local" return + else: + print "is NOT local" if self.zc_services.has_key((interface, protocol, name, type, domain)): self.zc_types[type].remove(self.zc_services[(interface, protocol, name, type, domain)]) -- cgit