X-Git-Url: https://git.ucc.asn.au/?p=zanchey%2Fdispense2.git;a=blobdiff_plain;f=sql-edition%2Fservers%2FIdler.py;h=5b6645517945891c49dd79b8ff6f1c62077410a3;hp=22285ded9a56d20c32976720efbb4ec8589725e7;hb=68807329464d87c004c974ff07ec0db09810002a;hpb=b5c641ee2449ae97bb789cdd29e3b450973ae8bd diff --git a/sql-edition/servers/Idler.py b/sql-edition/servers/Idler.py index 22285de..5b66455 100755 --- a/sql-edition/servers/Idler.py +++ b/sql-edition/servers/Idler.py @@ -1,6 +1,7 @@ #!/usr/bin/env python -import string, time, popen2, os +import string, time, os +from subprocess import Popen, PIPE from random import random from MessageKeeper import MessageKeeper @@ -13,8 +14,8 @@ class Idler: self.v = v def next(self): - """Displays next stage of the idler""" - pass + """Displays next stage of the idler. Returns time to the next step""" + return 1 def reset(self): """Resets the idler to a known intial state""" @@ -28,6 +29,32 @@ class Idler: """How much we want this idler to be the next one chosen""" return 1 +class GreetingIdler(Idler): + def __init__(self, v, secs_to_greeting = None): + self.v = v + self.secs_to_greeting = secs_to_greeting + self.message_displayed = False + + def next(self): + if not self.secs_to_greeting is None: + x = self.secs_to_greeting + self.secs_to_greeting = None + return x + + self.v.display('UCC SNACKS') + self.message_displayed = True + return 5 + + def reset(self): + self.message_displayed = False + self.secs_to_greeting = None + + def finished(self): + return self.message_displayed + + def affinity(self): + return 0 + class TrainIdler(Idler): def __init__(self, v): self.idle_state = 0 @@ -255,10 +282,8 @@ class FortuneIdler(StringIdler): 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() + (lines, unused) = Popen((fortune,), close_fds=True, stdout=PIPE).communicate() + text = string.join(lines) StringIdler.__init__(self, v, text,repeat=False) def affinity(self): @@ -268,18 +293,17 @@ 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() + (lines, unused) = Popen([command,] + args.split(), close_fds=True, stdout=PIPE).communicate() + text = string.join(lines) StringIdler.__init__(self, v, text,repeat=False) def affinity(self): return 20 class FileIdler(StringIdler): - def __init__(self, v, thefile=None, repeat=False): + def __init__(self, v, thefile=None, repeat=False, affinity=8): text = "I broke my wookie...." + self._affinity = affinity if file and os.access(thefile,os.F_OK|os.R_OK): f = file(thefile,'r') @@ -288,4 +312,4 @@ class FileIdler(StringIdler): StringIdler.__init__(self, v, text,repeat=repeat) def affinity(self): - return 8 + return self._affinity