Changeset 1913

Show
Ignore:
Timestamp:
09/24/06 07:30:09 (2 years ago)
Author:
godoy
Message:

Applying patch that makes our Bonjour/ZeroConf work with Avahi that is
the only program available with some Linux distributions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/turbogears/startup.py

    r1606 r1913  
    6060                mtime = os.stat(filename).st_mtime 
    6161            except OSError, e: 
    62                if orig_filename.endswith('.pyc') and e[0] == errno.ENOENT: 
    63                        # This prevents us from endlessly restarting if there is an old .pyc lying around 
    64                        # after a .py file has been deleted 
    65                        try: os.unlink(orig_filename) 
    66                        except: pass 
     62                if orig_filename.endswith('.pyc') and e[0] == errno.ENOENT: 
     63                    # This prevents us from endlessly restarting if there is an old .pyc lying around 
     64                    # after a .py file has been deleted 
     65                    try: os.unlink(orig_filename) 
     66                    except: pass 
    6767                sys.exit(3) # force reload 
    6868            if filename not in mtimes: 
     
    7777webpath = "" 
    7878 
    79 DNS_SD = '/usr/bin/dns-sd' 
    8079DNS_SD_PID = None 
    8180 
     
    8483    if DNS_SD_PID: 
    8584        return 
    86     if os.path.exists(DNS_SD): 
    87         # bonjour advertise 
    88         if not hasattr(cherrypy, "root") or not cherrypy.root: 
    89             return 
    90         if not package: 
    91             package = cherrypy.root.__module__ 
    92             package = package[:package.find(".")] 
    93         args = [ 
    94             DNS_SD, 
    95             '-R', 
    96             package + ": " + turbogears.config.get('server.environment'), 
    97             "_http._tcp", 
    98             "." + turbogears.config.get('server.socket_host', ''), 
    99             str(turbogears.config.get('server.socket_port')), 
    100             "path=/" 
    101         ] 
    102         # it might be nice to use subprocess and redirect IO to /dev/null 
    103         DNS_SD_PID = os.spawnv(os.P_NOWAIT, args[0], args) 
    104         atexit.register(stop_bonjour) 
     85    if (not hasattr(cherrypy, "root")) or (not cherrypy.root): 
     86        return 
     87    if not package: 
     88        package = cherrypy.root.__module__ 
     89        package = package[:package.find(".")] 
     90 
     91    host = turbogears.config.get('server.socket_host', '') 
     92    port = str(turbogears.config.get('server.socket_port')) 
     93    env = turbogears.config.get('server.environment') 
     94    name = package + ": " + env 
     95    type = "_http._tcp" 
     96 
     97    cmds = [['/usr/bin/avahi-publish-service', ["-H", host, name, type, port]], 
     98            ['/usr/bin/dns-sd', ['-R', name, type, "."+host, port, "path=/"]]] 
     99 
     100    for cmd, args in cmds: 
     101        # TODO:. This check is flawed.  If one has both services installed and 
     102        # avahi isn't the one running, then this won't work.  We should either 
     103        # try registering with both or checking what service is running and use 
     104        # that.  Program availability on the filesystem was never enough... 
     105        if os.path.exists(cmd): 
     106            DNS_SD_PID = os.spawnv(os.P_NOWAIT, cmd, [cmd]+args) 
     107            atexit.register(stop_bonjour) 
     108            break 
    105109 
    106110def stop_bonjour():