From 91714f5d8c77c1dff1a169cce7c5874b053b7810 Mon Sep 17 00:00:00 2001 From: Mark Tearle Date: Thu, 30 Sep 2004 15:17:44 +0000 Subject: [PATCH] fortune Idler --- sql-edition/servers/Idler.py | 19 ++++++++++++++++++- sql-edition/servers/VendServer.py | 5 +++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/sql-edition/servers/Idler.py b/sql-edition/servers/Idler.py index 392da6b..fc7573a 100755 --- a/sql-edition/servers/Idler.py +++ b/sql-edition/servers/Idler.py @@ -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 diff --git a/sql-edition/servers/VendServer.py b/sql-edition/servers/VendServer.py index d15165d..3f2c72f 100755 --- a/sql-edition/servers/VendServer.py +++ b/sql-edition/servers/VendServer.py @@ -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="-"), -- 2.20.1