Start wip branch. Server change into a twistd plugin.
This commit is contained in:
rodič
bd3197dc56
revize
5029308039
|
@ -6,3 +6,4 @@ recordings/*
|
|||
sounds/*
|
||||
*.sqlite3
|
||||
*.shelve
|
||||
dropin.cache
|
||||
|
|
|
@ -40,8 +40,12 @@ class RemoteManager(object):
|
|||
|
||||
implements(IManager)
|
||||
|
||||
def __init__(self, reactor, server='frn.no-ip.info', port=10025, maskParrot=True):
|
||||
self.reactor = reactor
|
||||
def __init__(self, server='frn.no-ip.info', port=10025, maskParrot=True, reactor=None):
|
||||
if reactor is None:
|
||||
from twisted.internet import reactor
|
||||
self.reactor = reactor
|
||||
else:
|
||||
self.reactor = reactor
|
||||
self.server = server
|
||||
self.port = port
|
||||
self.maskParrot = maskParrot
|
||||
|
|
59
server.py
59
server.py
|
@ -1,59 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright 2010 Maurizio Porrato <maurizio.porrato@gmail.com>
|
||||
# See LICENSE.txt for copyright info
|
||||
|
||||
from twisted.internet import reactor
|
||||
from frn.protocol.server import FRNServer, FRNServerFactory
|
||||
from twisted.enterprise.adbapi import ConnectionPool
|
||||
from frn.manager.remote import RemoteManager
|
||||
from frn.manager.dummy import DummyManager
|
||||
from frn.user import FRNUser
|
||||
from twisted.python import log
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
from os.path import dirname, join as pjoin
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
log.startLogging(sys.stderr)
|
||||
|
||||
basedir = dirname(__file__)
|
||||
|
||||
acfg = ConfigParser()
|
||||
acfg.read(['/etc/grn/accounts.conf',
|
||||
pjoin(basedir,'accounts.conf'), 'accounts.conf'])
|
||||
|
||||
scfg = ConfigParser()
|
||||
scfg.read(['/etc/grn/servers.conf',
|
||||
pjoin(basedir,'servers.conf'), 'servers.conf'])
|
||||
|
||||
argc = len(sys.argv)
|
||||
|
||||
if argc >= 3:
|
||||
account_name = sys.argv[1]
|
||||
server_name = sys.argv[2]
|
||||
|
||||
server = scfg.get(server_name, 'server')
|
||||
port = scfg.getint(server_name, 'port')
|
||||
backup_server = scfg.get(server_name, 'backup_server')
|
||||
backup_port = scfg.getint(server_name, 'backup_port')
|
||||
owner = acfg.get(account_name, 'email')
|
||||
password = acfg.get(account_name, 'password')
|
||||
|
||||
reactor.listenTCP(10024, FRNServerFactory(
|
||||
pjoin(basedir, 'tracker.shelve'),
|
||||
# DatabaseUserStore(
|
||||
# ConnectionPool("sqlite3", "frn_users.sqlite3",
|
||||
# check_same_thread=False)),
|
||||
RemoteManager(reactor),
|
||||
# DummyManager(),
|
||||
FRNUser(
|
||||
SN=server,PT=port,
|
||||
BN=backup_server, BP=backup_port,
|
||||
OW=owner,PW=password)
|
||||
))
|
||||
reactor.run()
|
||||
|
||||
# vim: set et ai sw=4 ts=4 sts=4:
|
|
@ -0,0 +1,64 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright 2010 Maurizio Porrato <maurizio.porrato@gmail.com>
|
||||
# See LICENSE.txt for copyright info
|
||||
|
||||
from zope.interface import implements
|
||||
from twisted.plugin import IPlugin
|
||||
from twisted.application.service import IServiceMaker
|
||||
from twisted.application import internet
|
||||
from frn.protocol.server import FRNServer, FRNServerFactory
|
||||
from frn.manager.remote import RemoteManager
|
||||
from frn.user import FRNUser
|
||||
|
||||
from os.path import curdir, join as pjoin
|
||||
from ConfigParser import ConfigParser
|
||||
from twisted.python import usage
|
||||
|
||||
|
||||
class Options(usage.Options):
|
||||
|
||||
optParameters = [
|
||||
["confdir", "c", curdir, "Directory containing config files"]
|
||||
]
|
||||
|
||||
def parseArgs(self, serverdef):
|
||||
account_name, server_name = serverdef.split(':', 1)
|
||||
|
||||
basedir = self['confdir']
|
||||
acfg = ConfigParser()
|
||||
acfg.read(['/etc/grn/accounts.conf',
|
||||
pjoin(basedir,'accounts.conf'), 'accounts.conf'])
|
||||
|
||||
scfg = ConfigParser()
|
||||
scfg.read(['/etc/grn/servers.conf',
|
||||
pjoin(basedir,'servers.conf'), 'servers.conf'])
|
||||
|
||||
self['server'] = scfg.get(server_name, 'server')
|
||||
self['port'] = scfg.getint(server_name, 'port')
|
||||
self['backup_server'] = scfg.get(server_name, 'backup_server')
|
||||
self['backup_port'] = scfg.getint(server_name, 'backup_port')
|
||||
self['owner'] = acfg.get(account_name, 'email')
|
||||
self['password'] = acfg.get(account_name, 'password')
|
||||
|
||||
|
||||
class FRNServerServiceMaker(object):
|
||||
implements(IServiceMaker, IPlugin)
|
||||
tapname = "frnserver"
|
||||
description = "Freeradionetwork server"
|
||||
options = Options
|
||||
|
||||
def makeService(self, options):
|
||||
return internet.TCPServer(options['port'],
|
||||
FRNServerFactory(
|
||||
pjoin(options['confdir'], 'tracker.shelve'),
|
||||
RemoteManager(),
|
||||
FRNUser(
|
||||
SN=options['server'],PT=options['port'],
|
||||
BN=options['backup_server'], BP=options['backup_port'],
|
||||
OW=options['owner'],PW=options['password'])
|
||||
))
|
||||
|
||||
serviceMaker = FRNServerServiceMaker()
|
||||
|
||||
# vim: set et ai sw=4 ts=4 sts=4:
|
Načítá se…
Odkázat v novém úkolu