#!/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
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"""
"""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
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):
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')
StringIdler.__init__(self, v, text,repeat=repeat)
def affinity(self):
- return 8
+ return self._affinity