git.ucc.asn.au
/
zanchey
/
dispense2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
switch from popen2 to subprocess (fix deprecation warnings)
[zanchey/dispense2.git]
/
sql-edition
/
servers
/
VendServer.py
diff --git
a/sql-edition/servers/VendServer.py
b/sql-edition/servers/VendServer.py
index
e18d8a3
..
8d62489
100755
(executable)
--- a/
sql-edition/servers/VendServer.py
+++ b/
sql-edition/servers/VendServer.py
@@
-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