| 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 |
|---|
| 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 |
|---|