CANFilter wurde vollständig zu einem Thread umgebaut. swich wurde angefangen umzubauen (nicht funktionsfähig) .gitignore wurde zum Repository hinzugefügt
58 lines
No EOL
1.3 KiB
Python
58 lines
No EOL
1.3 KiB
Python
'''
|
|
Created on 15.11.2013
|
|
|
|
@author: Philipp Rauch
|
|
@version: 0.01
|
|
'''
|
|
|
|
import MySQLdb
|
|
import threading
|
|
import Queue
|
|
from CANFilter import CANFilter
|
|
|
|
MYSQL = 0
|
|
CSV = 1
|
|
XML = 2
|
|
JSON = 3
|
|
|
|
class Swich(threading.Thread):
|
|
|
|
def __init__(self, source = MYSQL):
|
|
threading.Thread.__init__(self)
|
|
self.source = source
|
|
|
|
def __del__(self):
|
|
if self.source == MYSQL:
|
|
self.CAN.join()
|
|
|
|
def initialisiere(self):
|
|
if self.source == MYSQL:
|
|
self.CAN = CANFilter()
|
|
self.CAN.start()
|
|
|
|
self.connection = MySQLdb.connect("url", "user", "password", "database_name")
|
|
self.cursor = self.connection.cursor()
|
|
self.queue = Queue.Queue()
|
|
return self.queue, self.CAN
|
|
|
|
elif self.source == CSV:
|
|
pass
|
|
|
|
elif self.source == XML:
|
|
pass
|
|
|
|
elif self.source == JSON:
|
|
pass
|
|
|
|
else:
|
|
return
|
|
|
|
def run(self):
|
|
while True:
|
|
sql = 'SELECT * FROM %s ORDER BY timestamp DESC LIMIT 1'
|
|
item = Swich.queue.get(block = True) #item is a string which names the table that will be returned (newest values)
|
|
|
|
print self.cursor.execute(sql % item)
|
|
|
|
def setQueue(self, item):
|
|
self.queue.put(item) |