fortune Idler
authorMark Tearle <[email protected]>
Thu, 30 Sep 2004 15:17:44 +0000 (15:17 +0000)
committerMark Tearle <[email protected]>
Thu, 30 Sep 2004 15:17:44 +0000 (15:17 +0000)
sql-edition/servers/Idler.py
sql-edition/servers/VendServer.py

index 392da6b..fc7573a 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-import string, time
+import string, time, popen2, os
 from random import random
 from MessageKeeper import MessageKeeper
 
@@ -19,6 +19,9 @@ class Idler:
        def finished(self):
                return False
 
+       def affinity(self):
+               return 1
+
 class TrainIdler(Idler):
        def __init__(self, v):
                self.idle_state = 0
@@ -226,3 +229,17 @@ class ClockIdler(Idler):
                if output != self.last:
                        self.v.display(" %8.8s " % (output))
                        self.last = output
+
+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 15
index d15165d..3f2c72f 100755 (executable)
@@ -15,7 +15,7 @@ from VendingMachine import VendingMachine, VendingException
 from MessageKeeper import MessageKeeper
 from HorizScroll import HorizScroll
 from random import random, seed
-from Idler import TrainIdler,GrayIdler,StringIdler,ClockIdler
+from Idler import TrainIdler,GrayIdler,StringIdler,ClockIdler,FortuneIdler
 import socket
 from posix import geteuid
 
@@ -189,12 +189,13 @@ idler = None
 def setup_idlers(v):
        global idlers, idler
        idlers = [
-               ClockIdler(v),
                StringIdler(v, text="Kill 'em all", repeat=False),
                StringIdler(v, text=CREDITS),
                StringIdler(v, text=str(math.pi) + "            "),
                StringIdler(v, text=str(math.e) + "            "),
                StringIdler(v),
+               FortuneIdler(v),
+               ClockIdler(v),
                GrayIdler(v),
                TrainIdler(v),
                GrayIdler(v,one="*",zero="-"),

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