Proyecto

General

Perfil

« Anterior | Siguiente » 

Revisión 91

Añadido avahi con twisted

Ver diferencias:

Server.py
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with ControlAula. If not, see <http://www.gnu.org/licenses/>.
# along with ControlIES. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from twisted.internet import reactor
from Utils.avahiClient import avahiClient
from twisted.web import static, server
from twisted.web.server import Session
from twisted.python.components import registerAdapter
import MainLoop
from zope.interface import Interface, Attribute, implements
from Plugins.LdapConnection import LdapConnection, ILdapConnection
import os.path
registerAdapter(LdapConnection, Session, ILdapConnection)
# Start up the web service.
......
#Root.PageDir='/home/chisco/Proyectos/controlies/www'
site = server.Site(Root)
#my_server = static.File('/home/chisco/workspace/adminies/www/')
fileName = '/tmp/controlIES.ltpsSevers'
if os.path.isfile(fileName):
os.remove(fileName)
f = open(fileName, 'w')
def _add_location(self, name, address, port):
f = open(fileName, 'r+')
f.write(name)
f.close()
print "add"
def _remove_location(self, name, address, port):
print "remove"
#remove ipv6 entries:
if address.find(":") == -1:
print "removed:" + name,address,port
try:
_monitor = avahiClient()
_monitor.add_callback('new-service', _add_location)
_monitor.add_callback('remove-service', _remove_location)
_monitor.start()
except Exception, ex:
error_msg = "Couldn't initialize Avahi monitor: %s" % str(ex)
#raise InitializeFailure(self.name, error_msg)
from twisted.internet import reactor
reactor.listenTCP(7778,site)
reactor.run()

Exportar a: Unified diff