document idlers and slow them down!
[zanchey/dispense2.git] / sql-edition / servers / Idler.py
index fc7573a..e56f8d7 100755 (executable)
@@ -6,20 +6,26 @@ from MessageKeeper import MessageKeeper
 
 orderings = None
 
+IDLER_TEXT_SPEED=1.8
+
 class Idler:
        def __init__(self, v):
                self.v = v
 
        def next(self):
+               """Displays next stage of the idler"""
                pass
 
        def reset(self):
+               """Resets the idler to a known intial state"""
                pass
        
        def finished(self):
+               """Returns True if the idler is considered finished"""
                return False
 
        def affinity(self):
+               """How much we want this idler to be the next one chosen"""
                return 1
 
 class TrainIdler(Idler):
@@ -194,7 +200,7 @@ class StringIdler(Idler):
                self.mk = MessageKeeper(v)
                self.text = self.clean_text(text) + "          "
                
-               msg = [("",False, None),(self.text, repeat, 0.8)]
+               msg = [("",False, None),(self.text, repeat, IDLER_TEXT_SPEED)]
                self.mk.set_messages(msg)
 
        def clean_text(self, text):
@@ -230,6 +236,9 @@ class ClockIdler(Idler):
                        self.v.display(" %8.8s " % (output))
                        self.last = output
 
+       def affinity(self):
+               return 3 
+
 class FortuneIdler(StringIdler):
        def __init__(self, v):
                fortune = "/usr/games/fortune"
@@ -242,4 +251,30 @@ class FortuneIdler(StringIdler):
                StringIdler.__init__(self, v, text,repeat=False)
 
        def affinity(self):
-               return 15
+               return 20
+
+class PipeIdler(StringIdler):
+       def __init__(self, v, command, args):
+               text = "I ate my cookie...."
+               if os.access(command,os.F_OK|os.X_OK):
+                       (stdout, stdin) = popen2.popen2(command+' '+args)
+                       text = string.join(stdout.readlines())
+                       stdout.close()
+                       stdin.close()
+               StringIdler.__init__(self, v, text,repeat=False)
+
+       def affinity(self):
+               return 20
+
+class FileIdler(StringIdler):
+       def __init__(self, v, thefile=None, repeat=False):
+               text = "I broke my wookie...."
+
+               if file and os.access(thefile,os.F_OK|os.R_OK):
+                       f = file(thefile,'r')
+                       text = string.join(f.readlines())
+                       f.close()
+               StringIdler.__init__(self, v, text,repeat=repeat)
+
+       def affinity(self):
+               return 8 

UCC git Repository :: git.ucc.asn.au