Skip to content
Browse files

Update twistd plugins to use config files (and add basic client/serve…

…r configs)
  • Loading branch information...
1 parent 1e8f748 commit 01983d9a8086a720b62a52ef9fe1ec07859aacae @robgolding63 committed Feb 1, 2011
Showing with 90 additions and 29 deletions.
  1. +5 −0 client.conf
  2. +8 −0 server.conf
  3. +29 −11 twisted/plugins/backtracd_plugin.py
  4. +22 −7 twisted/plugins/backtracserverd_plugin.py
  5. +26 −11 twisted/plugins/backtracweb_plugin.py
View
5 client.conf
@@ -0,0 +1,5 @@
+[backtracd]
+
+server = localhost
+port = 8123
+secret_key = password
View
8 server.conf
@@ -0,0 +1,8 @@
+[backtracserverd]
+
+listen_port = 8123
+backup_root = /tmp/backtrac/backups
+
+[backtracweb]
+
+listen_port = 8000
View
40 twisted/plugins/backtracd_plugin.py
@@ -1,3 +1,6 @@
+import sys
+import ConfigParser
+
from zope.interface import implements
from twisted.python import usage
@@ -9,27 +12,42 @@
class Options(usage.Options):
optParameters = (
- ('server', 's', None, 'The server to connect to', str),
- ('port', 'p', None, 'The port to connect to the server on', int),
- ('secret-key', 'k', None, 'The secret key to authenticate with', str),
+ ('config', '', '/etc/backtrac/backtracd.conf',
+ 'Config file', str),
)
-
- def postOptions(self):
- if not self['server'] or not self['port'] or not self['secret-key']:
- raise usage.UsageError
class ClientServiceMaker(object):
implements(IServiceMaker, IPlugin)
tapname = 'backtracd'
description = 'Backtrac Client Daemon'
options = Options
+ def getConfig(self, config_file):
+ try:
+ cp = ConfigParser.SafeConfigParser()
+ cp.read(config_file)
+ except:
+ print >> sys.stderr, 'Error reading config file:', config_file
+ sys.exit(1)
+ return cp
+
def makeService(self, options):
def makeClient(broker):
BackupClient(broker).start()
- broker = BackupBroker(server=options['server'], port=options['port'],
- secret_key=options['secret-key'])
- broker.connect().addCallback(makeClient)
- return broker.service
+
+ config = options['config']
+ cp = self.getConfig(config)
+ try:
+ server = cp.get('backtracd', 'server')
+ port = cp.getint('backtracd', 'port')
+ secrey_key = cp.get('backtracd', 'secret_key')
+ broker = BackupBroker(server=server, port=port,
+ secret_key=secrey_key)
+ broker.connect().addCallback(makeClient)
+ return broker.service
+ except ConfigParser.Error:
+ raise
+ print >> sys.stderr, 'Error parsing config file:', config
+ sys.exit(1)
serviceMaker = ClientServiceMaker()
View
29 twisted/plugins/backtracserverd_plugin.py
@@ -1,4 +1,6 @@
import os
+import sys
+import ConfigParser
from zope.interface import implements
@@ -12,21 +14,34 @@
class Options(usage.Options):
optParameters = (
- ('port', 'p', None, 'The port to listen on', int),
+ ('config', '', '/etc/backtrac/backtracserverd.conf',
+ 'Config file', str),
)
-
- def postOptions(self):
- if not self['port']:
- raise usage.UsageError
class ServerServiceMaker(object):
implements(IServiceMaker, IPlugin)
tapname = 'backtracserverd'
description = 'Backtrac Server Daemon'
options = Options
+ def getConfig(self, config_file):
+ try:
+ cp = ConfigParser.SafeConfigParser()
+ cp.read(config_file)
+ except:
+ print >> sys.stderr, 'Error reading config file:', config_file
+ sys.exit(1)
+ return cp
+
def makeService(self, options):
- server = BackupServer(port=options['port'])
- return server.service
+ config = options['config']
+ cp = self.getConfig(config)
+ try:
+ port = cp.getint('backtracserverd', 'listen_port')
+ server = BackupServer(port=port)
+ return server.service
+ except ConfigParser.Error:
+ print >> sys.stderr, 'Error parsing config file:', config
+ sys.exit(1)
serviceMaker = ServerServiceMaker()
View
37 twisted/plugins/backtracweb_plugin.py
@@ -1,5 +1,6 @@
-import sys
import os
+import sys
+import ConfigParser
from zope.interface import implements
@@ -16,19 +17,26 @@
class Options(usage.Options):
optParameters = (
- ('port', 'p', None, 'The port to listen on', int),
+ ('config', '', '/etc/backtrac/backtracserverd.conf',
+ 'Config file', str),
)
-
- def postOptions(self):
- if not self['port']:
- raise usage.UsageError
class ServerServiceMaker(object):
implements(IServiceMaker, IPlugin)
tapname = 'backtracweb'
description = 'Backtrac Web Interface'
options = Options
+ def getConfig(self, config_file):
+ try:
+ cp = ConfigParser.SafeConfigParser()
+ cp.read(config_file)
+ except:
+ print >> sys.stderr, 'Error reading config file:', config_file
+ sys.exit(1)
+ return cp
+
+
def wsgi_resource(self):
pool = threadpool.ThreadPool()
pool.start()
@@ -37,10 +45,17 @@ def wsgi_resource(self):
return wsgi_resource
def makeService(self, options):
- application = service.Application('backtracweb')
- site = server.Site(self.wsgi_resource())
- svc = internet.TCPServer(options['port'], site)
- svc.setServiceParent(application)
- return svc
+ config = options['config']
+ cp = self.getConfig(config)
+ try:
+ port = cp.getint('backtracweb', 'listen_port')
+ application = service.Application('backtracweb')
+ site = server.Site(self.wsgi_resource())
+ svc = internet.TCPServer(port, site)
+ svc.setServiceParent(application)
+ return svc
+ except ConfigParser.Error:
+ print >> sys.stderr, 'Error parsing config file:', config
+ sys.exit(1)
serviceMaker = ServerServiceMaker()

0 comments on commit 01983d9

Please sign in to comment.
Something went wrong with that request. Please try again.