70 lines
1.4 KiB
Python
70 lines
1.4 KiB
Python
|
|
'''
|
||
|
|
Created on 15.11.2013
|
||
|
|
|
||
|
|
@author: Philipp Rauch
|
||
|
|
@version: 0.1
|
||
|
|
'''
|
||
|
|
|
||
|
|
from threading import Thread
|
||
|
|
from Queue import Queue
|
||
|
|
from time import sleep
|
||
|
|
from config import Config
|
||
|
|
|
||
|
|
#import Module
|
||
|
|
import database
|
||
|
|
|
||
|
|
MYSQL = 0
|
||
|
|
CSV = 1
|
||
|
|
XML = 2
|
||
|
|
JSON = 3
|
||
|
|
|
||
|
|
### LOAD CONFIG ###
|
||
|
|
c = Config()
|
||
|
|
conf = c.readConf()
|
||
|
|
|
||
|
|
'''
|
||
|
|
TODO: comment :)
|
||
|
|
'''
|
||
|
|
|
||
|
|
class Switch(Thread):
|
||
|
|
|
||
|
|
def __init__(self, source = MYSQL):
|
||
|
|
Thread.__init__(self)
|
||
|
|
self.source = source
|
||
|
|
|
||
|
|
def initialisiere(self):
|
||
|
|
self.cursor = database.setup(conf)
|
||
|
|
|
||
|
|
### init Query ###
|
||
|
|
self.query = Queue()
|
||
|
|
if conf['config_debug']:
|
||
|
|
print '\tSWITCH-QUERY:\t', self.query
|
||
|
|
|
||
|
|
### init Queue ###
|
||
|
|
self.queue = Queue()
|
||
|
|
if conf['config_debug']:
|
||
|
|
print '\tSWITCH-QUEUE:\t', self.queue
|
||
|
|
|
||
|
|
return self.queue, self.query
|
||
|
|
|
||
|
|
def run(self):
|
||
|
|
while True:
|
||
|
|
# Queue implementaion
|
||
|
|
# Queue contains the tablename for query
|
||
|
|
# item = query.get() #block = True
|
||
|
|
# query should be included in the result
|
||
|
|
|
||
|
|
item = 'dc_labor/device/battery'
|
||
|
|
result = database.loop(self.cursor, item)
|
||
|
|
|
||
|
|
#print 'PUT:\t%s' % result
|
||
|
|
|
||
|
|
self.setQueue(result)
|
||
|
|
sleep(float(conf['mySQL_speed']))
|
||
|
|
|
||
|
|
def setQueue(self, item):
|
||
|
|
self.queue.put(item)
|
||
|
|
|
||
|
|
def getItem(self, block = False):
|
||
|
|
return self.queue.get(block)
|