switch from popen2 to subprocess (fix deprecation warnings)
authorDavid Adam (zanchey) <zanchey@ucc.gu.uwa.edu.au>
Thu, 19 Jan 2012 12:37:51 +0000 (20:37 +0800)
committerDavid Adam (zanchey) <zanchey@ucc.gu.uwa.edu.au>
Thu, 19 Jan 2012 12:37:51 +0000 (20:37 +0800)
sql-edition/servers/Idler.py
sql-edition/servers/VendServer.py

index ff73c2a..5b66455 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 
 #!/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
 
 from random import random
 from MessageKeeper import MessageKeeper
 
@@ -281,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):
                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):
                StringIdler.__init__(self, v, text,repeat=False)
 
        def affinity(self):
@@ -294,10 +293,8 @@ class PipeIdler(StringIdler):
        def __init__(self, v, command, args):
                text = "I ate my cookie...."
                if os.access(command,os.F_OK|os.X_OK):
        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):
                StringIdler.__init__(self, v, text,repeat=False)
 
        def affinity(self):
index e18d8a3..8d62489 100755 (executable)
@@ -10,7 +10,7 @@ import logging, logging.handlers
 from traceback import format_tb
 if USE_DB: import pg
 from time import time, sleep, mktime, localtime
 from traceback import format_tb
 if USE_DB: import pg
 from time import time, sleep, mktime, localtime
-from popen2 import popen2
+from subprocess import Popen, PIPE
 from LATClient import LATClient, LATClientException
 from SerialClient import SerialClient, SerialClientException
 from VendingMachine import VendingMachine, VendingException
 from LATClient import LATClient, LATClientException
 from SerialClient import SerialClient, SerialClientException
 from VendingMachine import VendingMachine, VendingException
@@ -94,13 +94,10 @@ class DispenseDatabase:
 
 def scroll_options(username, mk, welcome = False):
        if welcome:
 
 def scroll_options(username, mk, welcome = False):
        if welcome:
-               # Balance checking: crap code, [DAA]'s fault
-               # Updated 2011 to handle new dispense [MRD]
-               raw_acct = os.popen('dispense acct %s' % username)
-               acct = raw_acct.read()
+               # Balance checking
+               acct, unused = Popen(['dispense', 'acct', username], close_fds=True, stdout=PIPE).communicate()
                # this is fucking appalling
                balance = acct[acct.find("$")+1:acct.find("(")].strip()
                # this is fucking appalling
                balance = acct[acct.find("$")+1:acct.find("(")].strip()
-               raw_acct.close()
         
                msg = [(center('WELCOME'), False, TEXT_SPEED),
                           (center(username), False, TEXT_SPEED),
         
                msg = [(center('WELCOME'), False, TEXT_SPEED),
                           (center(username), False, TEXT_SPEED),
@@ -112,10 +109,8 @@ def scroll_options(username, mk, welcome = False):
        # Get coke contents
        cokes = []
        for i in range(0, 7):
        # Get coke contents
        cokes = []
        for i in range(0, 7):
-               cmd = 'dispense iteminfo coke:%i' % i
-               raw = os.popen(cmd)
-               info = raw.read()
-               raw.close()
+               args = ('dispense', 'iteminfo', 'coke:%i' % i)
+               info, unused = Popen(args, close_fds=True, stdout=PIPE).communicate()
                m = re.match("\s*[a-z]+:\d+\s+(\d+)\.(\d\d)\s+([^\n]+)", info)
                cents = int(m.group(1))*100 + int(m.group(2))
                cokes.append('%i %i %s' % (i, cents, m.group(3)));
                m = re.match("\s*[a-z]+:\d+\s+(\d+)\.(\d\d)\s+([^\n]+)", info)
                cents = int(m.group(1))*100 + int(m.group(2))
                cokes.append('%i %i %s' % (i, cents, m.group(3)));

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