Browse Source

Start wip branch. Server change into a twistd plugin.

wip
Maurizio Porrato 9 years ago
parent
commit
5029308039
4 changed files with 71 additions and 61 deletions
  1. +1
    -0
      .gitignore
  2. +6
    -2
      frn/manager/remote.py
  3. +0
    -59
      server.py
  4. +64
    -0
      twisted/plugins/frnserver.py

+ 1
- 0
.gitignore View File

@@ -6,3 +6,4 @@ recordings/*
sounds/*
*.sqlite3
*.shelve
dropin.cache

+ 6
- 2
frn/manager/remote.py View File

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

+ 0
- 59
server.py View File

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

+ 64
- 0
twisted/plugins/frnserver.py View File

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

Loading…
Cancel
Save