X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=sql-edition%2Fservers%2FVendServer.py;h=e18d8a3e99a6072fb3d1cf01612e964c0c1e2a1f;hb=9fdb8cada3f6eee30acb2d5296d68983838ea44c;hp=f68cf1a93bfafa272e9ebf530caf08b84e6a514f;hpb=f999ec660c14d546a1cd6e25c4bef5bdfe5d6dc7;p=uccvend-vendserver.git diff --git a/sql-edition/servers/VendServer.py b/sql-edition/servers/VendServer.py index f68cf1a..e18d8a3 100755 --- a/sql-edition/servers/VendServer.py +++ b/sql-edition/servers/VendServer.py @@ -18,7 +18,7 @@ from MessageKeeper import MessageKeeper from HorizScroll import HorizScroll from random import random, seed from Idler import GreetingIdler,TrainIdler,GrayIdler,StringIdler,ClockIdler,FortuneIdler,FileIdler,PipeIdler -from SnackConfig import get_snacks, get_snack +from SnackConfig import get_snack#, get_snacks import socket from posix import geteuid from LDAPConnector import get_uid, set_card_id @@ -94,10 +94,13 @@ class DispenseDatabase: def scroll_options(username, mk, welcome = False): if welcome: - # Balance checking: crap code, [DAA]'s fault - acct = os.popen('dispense acct %s' % username) - balance = acct.read()[15:22] - acct.close() + # 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() + # 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), @@ -105,13 +108,18 @@ def scroll_options(username, mk, welcome = False): else: msg = [] choices = ' '*10+'CHOICES: ' - try: - coke_machine = file('/home/other/coke/coke_contents') - cokes = coke_machine.readlines() - coke_machine.close() - except: - cokes = [] - pass + + # 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() + 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))); + for c in cokes: c = c.strip() (slot_num, price, slot_name) = c.split(' ', 2) @@ -407,7 +415,8 @@ def make_selection(v, vstatus): vstatus.mk.set_message('OPENSESAME') logging.info('dispensing a door for %s'%vstatus.username) if geteuid() == 0: - ret = os.system('su - "%s" -c "dispense door"'%vstatus.username) + #ret = os.system('su - "%s" -c "dispense door"'%vstatus.username) + ret = os.system('dispense -u "%s" door'%vstatus.username) else: ret = os.system('dispense door') if ret == 0: @@ -425,7 +434,7 @@ def make_selection(v, vstatus): return elif vstatus.cur_selection[1] == '8': v.display('GOT DRINK?') - if ((os.system('su - "%s" -c "dispense %s"'%(vstatus.username, vstatus.cur_selection[0])) >> 8) != 0): + if ((os.system('dispense -u "%s" coke:%s'%(vstatus.username, vstatus.cur_selection[0])) >> 8) != 0): v.display('SEEMS NOT') else: v.display('GOT DRINK!') @@ -437,15 +446,23 @@ def make_selection(v, vstatus): price, shortname, name = get_snack( '--' ) dollarprice = "$%.2f" % ( price / 100.0 ) v.display(vstatus.cur_selection+' - %s'%dollarprice) - exitcode = os.system('su - "%s" -c "dispense give oday %d"'%(vstatus.username, price)) >> 8 + exitcode = os.system('dispense -u "%s" give \>snacksales %d "%s"'%(vstatus.username, price, name)) >> 8 +# exitcode = os.system('dispense -u "%s" give \>sales\:snack %d "%s"'%(vstatus.username, price, name)) >> 8 +# exitcode = os.system('dispense -u "%s" snack:%s'%(vstatus.username, vstatus.cur_selection)) >> 8 if (exitcode == 0): # magic dispense syslog service syslog.syslog(syslog.LOG_INFO | syslog.LOG_LOCAL4, "vended %s (slot %s) for %s" % (name, vstatus.cur_selection, vstatus.username)) v.vend(vstatus.cur_selection) v.display('THANK YOU') + elif (exitcode == 5): # RV_BALANCE + v.display('NO MONEY?') + elif (exitcode == 4): # RV_ARGUMENTS (zero give causes arguments) + v.display('EMPTY SLOT') + elif (exitcode == 1): # RV_BADITEM (Dead slot) + v.display('EMPTY SLOT') else: syslog.syslog(syslog.LOG_INFO | syslog.LOG_LOCAL4, "failed vending %s (slot %s) for %s (code %d)" % (name, vstatus.cur_selection, vstatus.username, exitcode)) - v.display('NO MONEY?') + v.display('UNK ERROR') sleep(1) @@ -938,7 +955,7 @@ def parse_args(): from optparse import OptionParser op = OptionParser(usage="%prog [OPTION]...") - op.add_option('-f', '--config-file', default='/etc/dispense/servers.conf', metavar='FILE', dest='config_file', help='use the specified config file instead of /etc/dispense/servers.conf') + op.add_option('-f', '--config-file', default='/etc/dispense2/servers.conf', metavar='FILE', dest='config_file', help='use the specified config file instead of /etc/dispense/servers.conf') op.add_option('--serial', action='store_true', default=True, dest='use_serial', help='use the serial port') op.add_option('--lat', action='store_true', default=False, dest='use_lat', help='use LAT') op.add_option('--virtualvend', action='store_false', default=True, dest='use_serial', help='use the virtual vending server instead of LAT') @@ -1069,6 +1086,8 @@ def do_vend_server(options, config_opts): sleep(5) continue +# run_forever(rfh, wfh, options, config_opts) + try: run_forever(rfh, wfh, options, config_opts) except VendingException: