Switch modularized

*the switch is prepared to load different modules
*module database is implemented
*code cleanup
*config can load lists
*add global debug mode
*ems has a method to update the buffer
This commit is contained in:
Philipp Rauch 2013-11-28 12:41:01 +01:00
parent 8d56806c03
commit 0d0e49d684
9 changed files with 311 additions and 208 deletions

43
scr/modules/database.py Normal file
View file

@ -0,0 +1,43 @@
'''
Created on 26.11.2013
@author: rauchp
'''
from MySQLdb import connect
def setup(conf):
connection = connect(host = conf['mySQL_server'],
user = conf['mySQL_user'],
passwd = conf['mySQL_pass'],
db = conf['mySQL_database'],
port = int(conf['mySQL_port']))
cursor = connection.cursor()
return cursor
def loop(cursor, item):
sql_values = 'SELECT * FROM %s ORDER BY timestamp DESC LIMIT 1'
sql_collums = 'SHOW COLUMNS FROM %s'
path = item.split('/')
if path[0] == '':
path.remove('')
collums = []
cursor.execute(sql_collums % path[len(path) -1])
for cul in cursor:
collums.append(cul[0])
cursor.execute(sql_values % path[len(path) -1])
for row in cursor:
values = row
result = {}
for i in range(len(collums)):
result[collums[i]] = values[i]
# for p in range(len(path)):
# result = { path.pop() : result }
result = {item : result}
return result