Changeset 20

Show
Ignore:
Timestamp:
09/17/07 06:42:12 (1 year ago)
Author:
devja..@anarkystic.com
Message:

added a process protocol, preparing for network connection reconnector thingee

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • fizzjik/fizzjik/input/basic.py

    r19 r20  
    4848class PollingInput(Input): 
    4949    delay = 10 
    50     startDelayed = Tru
     50    immediate = Fals
    5151 
    5252    def __init__(self): 
     
    5656    def startService(self): 
    5757        Input.startService(self) 
    58         self.poller.start(self.delay, not self.startDelayed
     58        self.poller.start(self.delay, self.immediate
    5959     
    6060    @if_config('enabled') 
  • fizzjik/fizzjik/output/lpr.py

    r17 r20  
    11import os 
    22 
    3 from twisted.application import service 
    4 from twisted.internet import protocol, reactor 
     3from fizzjik.interfaces import IOutput, implements 
     4from fizzjik.process import ProcessService, ProcessProtocol 
    55 
    6  
    7 from fizzjik.interfaces import IOutput, IConfigurable, implements 
    8 from fizzjik.config import ConfigurableMixin, if_config 
    9  
    10 class LPRProcessProtocol(protocol.ProcessProtocol): 
     6class LPRProcessProtocol(ProcessProtocol): 
    117    posix_exec = 'lpr' 
    128    posix_args = ['lpr'] 
    139 
    14     def __init__(self, platform="posix"): 
    15         self.platform = platform 
    16  
    17     def connectionMade(self): 
    18         print "connection made..." 
    19  
    20     def spawn(self, *args): 
    21         self.running = True 
    22         reactor.spawnProcess(self, self.getExec(), args=self.getArgs()+list(args), env=os.environ) 
    23  
    24     def kill(self): 
    25         self.transport.signalProcess('KILL') 
    26  
    27     def processEnded(self, reason): 
    28         print reason 
    29      
    30     def outReceived(self, line): 
    31         print "\n".join(["out >> %s"%(x) for x in line.splitlines()]) 
    32      
    33     def errReceived(self, line): 
    34         print "\n".join(["err !! %s"%(x) for x in line.splitlines()]) 
    35     
    36     def getExec(self): 
    37         return getattr(self, '%s_exec'%(self.platform)) 
    38      
    39     def getArgs(self): 
    40         return getattr(self, '%s_args'%(self.platform)) 
    41  
    42     def print_(self, f): 
    43         self.spawn() 
     10    def print_(self, f, *args): 
     11        self.spawn(*args) 
    4412        data = f.read() 
    4513        self.transport.write(data) 
    4614        self.transport.closeStdin() 
    4715 
    48 class LPRService(service.Service, ConfigurableMixin): 
     16class LPRService(ProcessService): 
    4917    implements(IOutput) 
    50      
    5118    enabled = True 
    5219    platform = "posix" 
    5320 
    54     @if_config('enabled') 
    55     def startService(self): 
    56         self.printer = LPRProcessProtocol(self.platform) 
    57         pass 
    58  
    59     def stopService(self): 
    60         pass 
    61      
    62     def print_(self, f): 
     21    def print_(self, f, *args): 
    6322        if self.reallyPrint: 
    64             self.printer.print_(f
     23            self.protocol.print_(f, *args
    6524        else: 
    6625            print "would be printing:",  
    6726            print f.name 
    68  
    69     def stop(self): 
    70         self.printer.stop() 
    71  
    72  
  • fizzjik/test.cfg

    r19 r20  
    2323has_outputs = False 
    2424 
     25[NetworkConnectionSensor] 
     26delay = 10 
     27 
    2528[MPlayerService] 
    2629enabled = False 
  • fizzjik/test.py

    r19 r20  
    2020 
    2121from fizzjik.output.basic import Echo 
     22from fizzjik.output.lpr import LPRService 
    2223from fizzjik.output.growl import GrowlService 
    2324