X-Git-Url: https://git.ucc.asn.au/?p=zanchey%2Fdispense2.git;a=blobdiff_plain;f=sql-edition%2Fservers%2FIdler.py;h=e56f8d755d0bab59c251c2a05231f3fd72a1920b;hp=a231d96a1e63fdd0c51db2c0cc2d613f4bfb0780;hb=1532e6ecbe484e7d181b12d200f4819d160accde;hpb=a8e66437967941cd59b3da7461a8b99a0d1bb2e6 diff --git a/sql-edition/servers/Idler.py b/sql-edition/servers/Idler.py index a231d96..e56f8d7 100755 --- a/sql-edition/servers/Idler.py +++ b/sql-edition/servers/Idler.py @@ -1,24 +1,33 @@ #!/usr/bin/env python -import string, time +import string, time, popen2, os from random import random 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): def __init__(self, v): self.idle_state = 0 @@ -186,12 +195,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, IDLER_TEXT_SPEED)] self.mk.set_messages(msg) def clean_text(self, text): @@ -213,6 +222,9 @@ class StringIdler(Idler): def next(self): self.mk.update_display() + def finished(self): + return self.mk.done() + class ClockIdler(Idler): def __init__(self, v): self.v = v @@ -223,3 +235,46 @@ class ClockIdler(Idler): 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 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