#!/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
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):
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
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()
- raw_acct.close()
msg = [(center('WELCOME'), False, TEXT_SPEED),
(center(username), False, TEXT_SPEED),
# 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)));