Commit c46bfcfa authored by Mark Tearle's avatar Mark Tearle
Browse files

Remove redundant code associated with Bernard Postgres Dispense prototype

parent 8be035ce
# vim:ts=4
USE_DB = 0
import ConfigParser
import sys, os, string, re, pwd, signal, math, syslog
import logging, logging.handlers
from traceback import format_tb
if USE_DB: import pg
from time import time, sleep, mktime, localtime
from subprocess import Popen, PIPE
from LATClient import LATClient, LATClientException
......@@ -95,36 +93,6 @@ class VendConfigFile:
except ConfigParser.Error, e:
raise SystemExit("Error reading config file "+config_file+": " + str(e))
class DispenseDatabaseException(Exception): pass
class DispenseDatabase:
def __init__(self, vending_machine, host, name, user, password):
self.vending_machine = vending_machine
self.db = pg.DB(dbname = name, host = host, user = user, passwd = password)
self.db.query('LISTEN vend_requests')
def process_requests(self):
logging.debug('database processing')
query = 'SELECT request_id, request_slot FROM vend_requests WHERE request_handled = false'
outstanding = self.db.query(query).getresult()
except (pg.error,), db_err:
raise DispenseDatabaseException('Failed to query database: %s\n'%(db_err.strip()))
for (id, slot) in outstanding:
(worked, code, string) = self.vending_machine.vend(slot)
logging.debug (str((worked, code, string)))
if worked:
query = 'SELECT vend_success(%s)'%id
query = 'SELECT vend_failed(%s)'%id
def handle_events(self):
notifier = self.db.getnotify()
while notifier is not None:
notify = self.db.getnotify()
This class manages the current state of the vending machine.
......@@ -927,18 +895,10 @@ class VendServer():
logging.debug('PING is ' + str(
if USE_DB: db = DispenseDatabase(v, cf.DBServer, cf.DBName, cf.DBUser, cf.DBPassword)
while True:
if USE_DB:
except DispenseDatabaseException, e:
logging.error('Database error: '+str(e))
timeout = self.time_to_next_update()
(event, params) = self.v.next_event(timeout)
self.run_handler(event, params)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment