Beispiel #1
0
def publish(name, desc, path, port):
    global server, localip
    if not server:
        ip = getip()
        if ip.startswith('127.'):
            # if we have no internet connection, this can happen.
            return
        localip = socket.inet_aton(ip)
        server = Zeroconf.Zeroconf(ip)

    hostname = socket.gethostname().split('.')[0]
    host = hostname + ".local"
    name = "%s-%s" % (hostname, name)

    # advertise to browsers
    svc = Zeroconf.ServiceInfo('_http._tcp.local.',
                               name + '._http._tcp.local.',
                               server = host,
                               port = port,
                               properties = {'description': desc,
                                             'path': "/" + path},
                               address = localip, weight = 0, priority = 0)
    server.registerService(svc)

    # advertise to Mercurial clients
    svc = Zeroconf.ServiceInfo('_hg._tcp.local.',
                               name + '._hg._tcp.local.',
                               server = host,
                               port = port,
                               properties = {'description': desc,
                                             'path': "/" + path},
                               address = localip, weight = 0, priority = 0)
    server.registerService(svc)
Beispiel #2
0
 def init_autodiscovery(self):
     """
     Inicializa el descubrimiento automático de los servidores TagFS.
     """
     self._zeroconf = Zeroconf.Zeroconf(self._daemon.hostname)
     zeroconf_service_name = '{n}.{t}'.format(n=self._pyro_uri, t=ZEROCONF_SERVICE_TYPE)
     self._zeroconf_service = Zeroconf.ServiceInfo(ZEROCONF_SERVICE_TYPE, zeroconf_service_name, 
                                                   socket.inet_aton(self._daemon.hostname),
                                                   self._daemon.port, 0, 0, {})
     self._zeroconf.registerService(self._zeroconf_service)
Beispiel #3
0
 def _init_autodiscovery(self):
     """
     Inicializa el descubrimiento automático de los servidores.
     """
     self._servers = {}
     self._servers_mutex = threading.Lock()
     self.addService = self._server_added
     self.removeService = self._server_removed
     self._zeroconf = Zeroconf.Zeroconf(self._address)
     self._zeroconf_browser = Zeroconf.ServiceBrowser(
         self._zeroconf, ZEROCONF_SERVICE_TYPE, self)
Beispiel #4
0
def getzcpaths():
    ip = getip()
    if ip.startswith('127.'):
        return
    server = Zeroconf.Zeroconf(ip)
    l = listener()
    Zeroconf.ServiceBrowser(server, "_hg._tcp.local.", l)
    time.sleep(1)
    server.close()
    for value in l.found.values():
        name = value.name[:value.name.index('.')]
        url = "http://%s:%s%s" % (socket.inet_ntoa(value.address), value.port,
                                  value.properties.get("path", "/"))
        yield "zc-" + name, url
Beispiel #5
0
    def run(self):	
	
        self.localhostname = split(socket.gethostname(),'.')[0]+'.local.'
	try:
	        self.localip = socket.gethostbyname(self.localhostname)
	        self.zeroconf = Zeroconf.Zeroconf(self.localip)
	except:
		return
	self.active = True

        toRegister = self.services()
        for i in toRegister:
            service = Zeroconf.ServiceInfo(
	    i["type"]+".local.",
            i["name"]+"."+i["type"]+".local.",
	    socket.inet_aton(self.localip),
	    i["port"],
	    0,
	    0,
	    i["properties"],
	    self.localhostname)
	    self.zeroconf.registerService(service)
Beispiel #6
0
def main():
	usage = """Fusedaap :""" + fuse.Fuse.fusage
	server = DaapFS()
	server.fuse_args.setmod('foreground')
	server.parse(errex=1)
	server.multithreaded = True
	hostMan = HostManager()
	hdh = HostDirHandler(server.dirSup.requestDirLease("/hosts"))
	hostMan.addHandler(hdh)
	adh = ArtistDirHandler(server.dirSup.requestDirLease("/artists"))
	hostMan.addHandler(adh)
	r = Zeroconf.Zeroconf()
	r.addServiceListener(daapZConfType, hostMan)
	try:
		server.main() # main loop
	except:
		print 'Exiting . . .'
		r.close()
		return
	logger.info("closing zeroconf in main")
	print "Disconnecting from services . . ."
	r.close() # close zeroconf first so no new servers are connected to
	hostMan.closeAllConnections() 
Beispiel #7
0
def _get_server():
    global server
    if not server:
        server = Zeroconf.Zeroconf()
    return server
Beispiel #8
0
	def testLaunchAndClose(self):
		rv = r.Zeroconf()
		rv.close()
Beispiel #9
0
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
	
"""

__author__ = "Paul Scott-Murphy"
__email__ = "paul at scott dash murphy dot com"
__version__ = "0.12"

from Zeroconf import *
import socket

desc = {'path':'/~paulsm/'}
info = ServiceInfo("_http._tcp.local.", "Paul's Test Web Site._http._tcp.local.", socket.inet_aton("10.0.1.2"), 80, 0, 0, desc, "ash-2.local.")

r = Zeroconf()
print "Registration of a service..."
r.registerService(info)
print "Waiting..."
Beispiel #10
0
 def __init__(self):
     self.r = Zeroconf()
     pass