/[anoncvs]/projects/dispense2/sql-edition/servers/SnackConfig.py


UCC Code Repository

Contents of /projects/dispense2/sql-edition/servers/SnackConfig.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download) (as text)
Wed May 4 14:35:06 2011 UTC (10 years ago) by tpg
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +25 -56 lines
File MIME type: text/x-python
Updated snack config to use `dispense iteminfo` for prices (goodbye config file)

1 #!/usr/bin/env python
2
3 class VendingException( Exception ): pass
4
5 import subprocess
6 import os, re
7
8 def get_snack( slot ):
9
10 if slot == "--":
11 return (0, 'nothing', 'Nothing')
12 cmd = 'dispense iteminfo snack:%s' % slot
13 # print 'cmd = %s' % cmd
14 try:
15 # info = subprocess.check_output(["dispense","iteminfo",'snack:%s'%slot])
16 raw = os.popen(cmd)
17 info = raw.read()
18 raw.close()
19 # print 'cmd (2) = %s' % cmd
20 # print 'info = "%s"' % info
21 m = re.match("\s*[a-z]+:\d+\s+(\d+)\.(\d\d)\s+([^\n]+)", info)
22 val = ( int(m.group(1))*100 + int(m.group(2)), m.group(3), m.group(3) )
23 # print 'Price: %i, Name: %s' % (val[0], val[1])
24 except BaseException as e:
25 print "BaseException"
26 print e
27 val = (0, 'error', 'Error')
28 except:
29 print "Unknown exception"
30 val = (0, 'error', 'Error')
31 return val
32
33 def get_price( slot ):
34 p, sn, n = get_snacks( slot )
35 return p
36
37 def get_name( slot ):
38 p, sn, n = get_snacks( slot )
39 return n
40
41 def get_short_name( slot ):
42 p, sn, n = get_snacks( slot )
43 return sn
44
45 if __name__ == '__main__':
46 print "Don't run this"

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26