umstrukturierung
This commit is contained in:
parent
25e406ed8c
commit
98451284d7
14 changed files with 138 additions and 139 deletions
58
Swich/modules/database.py
Normal file
58
Swich/modules/database.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
'''
|
||||
Created on 26.11.2013
|
||||
|
||||
@author: Philipp Rauch
|
||||
'''
|
||||
from profile.database import Database
|
||||
|
||||
_sort_lookup = { 'EA_Last' : 'DateTime' }
|
||||
|
||||
def setup(conf):
|
||||
'''
|
||||
establishes a connection to the database and returns a Database object
|
||||
|
||||
@return: Database object
|
||||
'''
|
||||
|
||||
db = Database()
|
||||
db.loadDatabase(strHost = conf['mySQL_server'],
|
||||
intPort = int(conf['mySQL_port']),
|
||||
strUser = conf['mySQL_user'],
|
||||
strPasswd = conf['mySQL_pass'],
|
||||
strDatabase = conf['mySQL_database'],
|
||||
strTable = None)
|
||||
return db
|
||||
|
||||
def loop(db, item):
|
||||
'''
|
||||
sql_values = 'SELECT * FROM %s ORDER BY %s DESC LIMIT 0, 1'
|
||||
'''
|
||||
path = item.split('/')
|
||||
if path[0] == '':
|
||||
path.remove('')
|
||||
|
||||
table = path[len(path) -1]
|
||||
if table == 'device':
|
||||
tmp = { table : {} }
|
||||
for i in db.getInformation()['Table'].keys():
|
||||
tmp[table][i] = {}
|
||||
return tmp
|
||||
|
||||
try:
|
||||
sort = db.getInformation()['Table_Prime'][table][0]
|
||||
except:
|
||||
try:
|
||||
sort = _sort_lookup[table]
|
||||
except:
|
||||
return { 'error/db_error' : { table : 'no Prime-Key / Sort defined' } }
|
||||
|
||||
res = db.readDatabase(intRowOffset=0, intRowNumber=1, strTable=table, strSort=sort, invertSort=True)
|
||||
result = res.to_dict()
|
||||
|
||||
for k in result:
|
||||
result[k] = result[k][0]
|
||||
|
||||
return {item : result}
|
||||
|
||||
def close(cursor):
|
||||
pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue