switch from popen2 to subprocess (fix deprecation warnings)
[uccvend-vendserver.git] / sql-edition / servers / Idler.py
index 07be6ab..5b66455 100755 (executable)
@@ -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
 
@@ -32,6 +33,7 @@ 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:
@@ -40,13 +42,15 @@ class GreetingIdler(Idler):
                        return x
 
                self.v.display('UCC SNACKS')
-               return 2
+               self.message_displayed = True
+               return 5
 
        def reset(self):
-               pass
+               self.message_displayed = False
+               self.secs_to_greeting = None
 
        def finished(self):
-               return self.secs_to_greeting == None
+               return self.message_displayed
 
        def affinity(self):
                return 0
@@ -278,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):
@@ -291,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')
@@ -311,4 +312,4 @@ class FileIdler(StringIdler):
                StringIdler.__init__(self, v, text,repeat=repeat)
 
        def affinity(self):
-               return 
+               return self._affinity

UCC git Repository :: git.ucc.asn.au