Fix the code to connect to the virtual vend thing again
[uccvend-vendserver.git] / sql-edition / servers / Idler.py
index 48e819a..5fe61cf 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-import string
+import string, time, popen2, os
 from random import random
 from MessageKeeper import MessageKeeper
 
@@ -15,6 +15,12 @@ class Idler:
 
        def reset(self):
                pass
+       
+       def finished(self):
+               return False
+
+       def affinity(self):
+               return 1
 
 class TrainIdler(Idler):
        def __init__(self, v):
@@ -183,12 +189,12 @@ class GrayIdler(Idler):
 
 
 class StringIdler(Idler):
-       def __init__(self, v, text="Hello Cruel World!  "):
+       def __init__(self, v, text="Hello Cruel World!  ",repeat=True):
                self.v = v
                self.mk = MessageKeeper(v)
-               self.text = self.clean_text(text)
+               self.text = self.clean_text(text) + "          "
                
-               msg = [("",False, None),(self.text, True, 0.8)]
+               msg = [("",False, None),(self.text, repeat, 0.8)]
                self.mk.set_messages(msg)
 
        def clean_text(self, text):
@@ -210,6 +216,46 @@ class StringIdler(Idler):
        def next(self):
                self.mk.update_display()
 
-       def reset(self):
-               pass
-               #self.mk.update_display(forced=True)
+       def finished(self):     
+               return self.mk.done()
+
+class ClockIdler(Idler):
+       def __init__(self, v):
+               self.v = v
+               self.last = None
+
+       def next(self):
+               output = time.strftime("%H:%M:%S")
+               if output != self.last:
+                       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"
+               text = "I broke my wookie...."
+               if os.access(fortune,os.F_OK|os.X_OK):
+                       (stdout, stdin) = popen2.popen2(fortune)
+                       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