From c46bfcfa82d48492d05d0c3555aba71b67692762 Mon Sep 17 00:00:00 2001 From: Mark Tearle Date: Mon, 6 Apr 2015 17:37:06 +0800 Subject: [PATCH] Remove redundant code associated with Bernard Postgres Dispense prototype --- VendServer/VendServer.py | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/VendServer/VendServer.py b/VendServer/VendServer.py index 21fe2c8..be8cea0 100755 --- a/VendServer/VendServer.py +++ b/VendServer/VendServer.py @@ -1,14 +1,12 @@ #!/usr/bin/python # vim:ts=4 -USE_DB = 0 USE_MIFARE = 1 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' - try: - 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 - self.db.query(query).getresult() - else: - query = 'SELECT vend_failed(%s)'%id - self.db.query(query).getresult() - - def handle_events(self): - notifier = self.db.getnotify() - while notifier is not None: - self.process_requests() - 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(self.v.ping())) - if USE_DB: db = DispenseDatabase(v, cf.DBServer, cf.DBName, cf.DBUser, cf.DBPassword) - self.setup_idlers() self.reset_idler() while True: - if USE_DB: - try: - db.handle_events() - 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) -- 2.20.1