X-Git-Url: https://git.ucc.asn.au/?p=uccvend-vendserver.git;a=blobdiff_plain;f=sql-edition%2Fservers%2FIdler.py;h=5fe61cf02ea860809089429c5ec926fb8ae4dd99;hp=392da6b3b3c9ed36f81e83d04ee952e2c23ea338;hb=7c3379cae4ca6e0fbe09db062aaa31511ab6efe7;hpb=e98c4f3df5b2b7dd54a90902605c72bd41a53272 diff --git a/sql-edition/servers/Idler.py b/sql-edition/servers/Idler.py index 392da6b..5fe61cf 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,33 @@ 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 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