/
backtracd_plugin.py
53 lines (44 loc) · 1.56 KB
/
backtracd_plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import sys
import ConfigParser
from zope.interface import implements
from twisted.python import usage
from twisted.plugin import IPlugin
from twisted.application.service import IServiceMaker
from backtrac.client.broker import BackupBroker
from backtrac.client import BackupClient
class Options(usage.Options):
optParameters = (
('config', '', '/etc/backtrac/backtracd.conf',
'Config file', str),
)
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()
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()