Package flumotion :: Package extern :: Package command :: Package command :: Module tcommand
[hide private]

Source Code for Module flumotion.extern.command.command.tcommand

 1  # -*- Mode: Python -*- 
 2  # vi:si:et:sw=4:sts=4:ts=4 
 3   
 4  """ 
 5  A helper class for Twisted commands. 
 6  """ 
 7   
 8  from twisted.internet import defer 
 9   
10  import command 
11   
12  # FIXME: move this to the command module 
13 -class TwistedCommand(command.Command):
14
15 - def installReactor(self):
16 """ 17 Override me to install your own reactor. 18 """ 19 from twisted.internet import reactor 20 self.reactor = reactor
21
22 - def do(self, args):
23 self.installReactor() 24 25 def later(): 26 try: 27 d = defer.maybeDeferred(self.doLater, args) 28 except Exception: 29 self.reactor.stop() 30 raise 31 32 d.addCallback(lambda _: self.reactor.stop()) 33 def eb(failure): 34 self.stderr.write('Failure: %s\n' % failure.getErrorMessage()) 35 36 self.reactor.stop()
37 d.addErrback(eb)
38 39 self.reactor.callLater(0, later) 40 41 self.reactor.run() 42
43 - def doLater(self):
44 raise NotImplementedError
45