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/*
6 6
 sounds/*
7 7
 *.sqlite3
8 8
 *.shelve
9
+dropin.cache

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

@@ -40,8 +40,12 @@ class RemoteManager(object):
40 40
 
41 41
     implements(IManager)
42 42
 
43
-    def __init__(self, reactor, server='frn.no-ip.info', port=10025, maskParrot=True):
44
-        self.reactor = reactor
43
+    def __init__(self, server='frn.no-ip.info', port=10025, maskParrot=True, reactor=None):
44
+        if reactor is None:
45
+            from twisted.internet import reactor
46
+            self.reactor = reactor
47
+        else:
48
+            self.reactor = reactor
45 49
         self.server = server
46 50
         self.port = port
47 51
         self.maskParrot = maskParrot

+ 0
- 59
server.py View File

@@ -1,59 +0,0 @@
1
-#!/usr/bin/env python
2
-# -*- coding: utf-8 -*-
3
-#
4
-# Copyright 2010 Maurizio Porrato <maurizio.porrato@gmail.com>
5
-# See LICENSE.txt for copyright info
6
-
7
-from twisted.internet import reactor
8
-from frn.protocol.server import FRNServer, FRNServerFactory
9
-from twisted.enterprise.adbapi import ConnectionPool
10
-from frn.manager.remote import RemoteManager
11
-from frn.manager.dummy import DummyManager
12
-from frn.user import FRNUser
13
-from twisted.python import log
14
-
15
-if __name__ == '__main__':
16
-    import sys
17
-    from os.path import dirname, join as pjoin
18
-    from ConfigParser import ConfigParser
19
-
20
-    log.startLogging(sys.stderr)
21
-
22
-    basedir = dirname(__file__)
23
-
24
-    acfg = ConfigParser()
25
-    acfg.read(['/etc/grn/accounts.conf',
26
-        pjoin(basedir,'accounts.conf'), 'accounts.conf'])
27
-
28
-    scfg = ConfigParser()
29
-    scfg.read(['/etc/grn/servers.conf',
30
-        pjoin(basedir,'servers.conf'), 'servers.conf'])
31
-
32
-    argc = len(sys.argv)
33
-
34
-    if argc >= 3:
35
-        account_name = sys.argv[1]
36
-        server_name = sys.argv[2]
37
-
38
-        server = scfg.get(server_name, 'server')
39
-        port = scfg.getint(server_name, 'port')
40
-        backup_server = scfg.get(server_name, 'backup_server')
41
-        backup_port = scfg.getint(server_name, 'backup_port')
42
-        owner = acfg.get(account_name, 'email')
43
-        password = acfg.get(account_name, 'password')
44
-
45
-        reactor.listenTCP(10024, FRNServerFactory(
46
-            pjoin(basedir, 'tracker.shelve'),
47
-    #        DatabaseUserStore(
48
-    #            ConnectionPool("sqlite3", "frn_users.sqlite3",
49
-    #                check_same_thread=False)),
50
-            RemoteManager(reactor),
51
-    #        DummyManager(),
52
-            FRNUser(
53
-                SN=server,PT=port,
54
-                BN=backup_server, BP=backup_port,
55
-                OW=owner,PW=password)
56
-        ))
57
-        reactor.run()
58
-
59
-# vim: set et ai sw=4 ts=4 sts=4:

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

@@ -0,0 +1,64 @@
1
+# -*- coding: utf-8 -*-
2
+#
3
+# Copyright 2010 Maurizio Porrato <maurizio.porrato@gmail.com>
4
+# See LICENSE.txt for copyright info
5
+
6
+from zope.interface import implements
7
+from twisted.plugin import IPlugin
8
+from twisted.application.service import IServiceMaker
9
+from twisted.application import internet
10
+from frn.protocol.server import FRNServer, FRNServerFactory
11
+from frn.manager.remote import RemoteManager
12
+from frn.user import FRNUser
13
+
14
+from os.path import curdir, join as pjoin
15
+from ConfigParser import ConfigParser
16
+from twisted.python import usage
17
+
18
+
19
+class Options(usage.Options):
20
+
21
+    optParameters = [
22
+        ["confdir", "c", curdir, "Directory containing config files"]
23
+    ]
24
+
25
+    def parseArgs(self, serverdef):
26
+        account_name, server_name = serverdef.split(':', 1)
27
+
28
+        basedir = self['confdir']
29
+        acfg = ConfigParser()
30
+        acfg.read(['/etc/grn/accounts.conf',
31
+            pjoin(basedir,'accounts.conf'), 'accounts.conf'])
32
+
33
+        scfg = ConfigParser()
34
+        scfg.read(['/etc/grn/servers.conf',
35
+            pjoin(basedir,'servers.conf'), 'servers.conf'])
36
+
37
+        self['server'] = scfg.get(server_name, 'server')
38
+        self['port'] = scfg.getint(server_name, 'port')
39
+        self['backup_server'] = scfg.get(server_name, 'backup_server')
40
+        self['backup_port'] = scfg.getint(server_name, 'backup_port')
41
+        self['owner'] = acfg.get(account_name, 'email')
42
+        self['password'] = acfg.get(account_name, 'password')
43
+
44
+
45
+class FRNServerServiceMaker(object):
46
+    implements(IServiceMaker, IPlugin)
47
+    tapname = "frnserver"
48
+    description = "Freeradionetwork server"
49
+    options = Options
50
+
51
+    def makeService(self, options):
52
+        return internet.TCPServer(options['port'],
53
+            FRNServerFactory(
54
+                pjoin(options['confdir'], 'tracker.shelve'),
55
+                RemoteManager(),
56
+                FRNUser(
57
+                    SN=options['server'],PT=options['port'],
58
+                    BN=options['backup_server'], BP=options['backup_port'],
59
+                    OW=options['owner'],PW=options['password'])
60
+            ))
61
+
62
+serviceMaker = FRNServerServiceMaker()
63
+
64
+# vim: set et ai sw=4 ts=4 sts=4:

Loading…
Cancel
Save