Package sparked :: Module tap
[hide private]
[frames] | no frames]

Source Code for Module sparked.tap

 1  # Copyright (c) 2010 Arjan Scherpenisse 
 2  # See LICENSE for details. 
 3   
 4  """ 
 5  Twisted Application Persistence package for the startup of the twisted sparked plugin. 
 6  """ 
 7   
 8  import tempfile 
 9  import dbus.mainloop.glib 
10   
11  from twisted.python import usage 
12   
13  from twisted.python import log 
14  from twisted.python.filepath import FilePath 
15  from twisted.python.logfile import LogFile 
16   
17  from sparked import launcher, application 
18   
19   
20 -class Options(usage.Options):
21 - def parseOptions(self, o):
22 sparkedOpts, self.appName, appOpts = launcher.splitOptions(o) 23 self.opts = launcher.Options() 24 self.opts.parseOptions(sparkedOpts) 25 26 if not self.appName: 27 self.opts.opt_help() 28 29 self.module, self.appName = launcher.loadModule(self.appName) 30 31 if hasattr(self.module, 'Options'): 32 self.appOpts = self.module.Options() 33 else: 34 self.appOpts = application.Options() 35 self.appOpts.parseOptions(appOpts)
36 37 38
39 -def makeService(config):
40 41 # Create dbus mainloop 42 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) 43 44 # Check if it is the right thing 45 if not hasattr(config.module, 'Application'): 46 raise usage.UsageError("Invalid application module: " + config.appName) 47 48 # Instantiate the main application 49 s = config.module.Application(config.opts, config.appOpts) 50 51 # Assign the 'application id' 52 if config.opts['id']: 53 s.id = config.opts['id'] 54 else: 55 s.id = config.appName 56 57 # assign temppath 58 s.tempPath = application.getTempPath(config.appName, s.id) 59 60 # Set quitflag 61 s.quitFlag = launcher.QuitFlag(s.tempPath.child("quitflag")) 62 63 # Set the name 64 s.setName(config.appName) 65 66 # Set up logging in /tmp/log, maximum 9 rotated log files. 67 if config.opts['logfile']: 68 logfile = config.opts['logfile'] 69 logDir = FilePath(logfile).parent() 70 if not logDir.exists(): 71 logDir.createDirectory() 72 else: 73 logfile = 'sparkd.log' 74 logDir = s.tempPath 75 logFile = LogFile(logfile, logDir.path, maxRotatedFiles=9) 76 log.addObserver(log.FileLogObserver(logFile).emit) 77 78 return s
79