Commit 1a980641 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras
Browse files

Telemetry saving code (untested)

parent b68b110b
......@@ -29,47 +29,71 @@ from PySide.QtGui import QDockWidget
__all__ = ['SQLTelecommands', 'SQLTelemetries']
class TM(QDockWidget, QObject):
''' Subclasses of TM will receive ASN.1 data from the GUI whenever a
value is updated (through a Qt slot)
# class TM(QDockWidget, QObject):
# ''' Subclasses of TM will receive ASN.1 data from the GUI whenever a
# value is updated (through a Qt slot)
# '''
# # specify a name for the combo button
# name = 'Generic TM'
#
# def __init__(self, unused_asn1_type=None, parent=None):
# ''' Initialisation of the Widget '''
# super(TM, self).__init__(parent)
#
# @staticmethod
# def applicable():
# '''' Return true is the widget is active '''
# return True
#
# @Slot()
# def update(self, value):
# ''' Receive ASN.1 value '''
# pass
#
#
# class TC(QDockWidget, QObject):
# ''' Subclasses of TC can be used to provide ASN.1 data to the main GUI
# and to automatically send it to the application.
# Example of uses: Buttons, SQL interface...
# Define your widget and send signals at will.
# '''
# send = Signal()
# update = Signal()
# # specify a name for the combo button
# name = 'Generic TM'
#
# def __init__(self, unused_asn1_type=None, parent=None):
# ''' Initialisation of the Widget '''
# super(TC, self).__init__(parent)
def connect_to_db():
'''
# specify a name for the combo button
name = 'Generic TM'
def __init__(self, unused_asn1_type=None, parent=None):
''' Initialisation of the Widget '''
super(TM, self).__init__(parent)
@staticmethod
def applicable():
'''' Return true is the widget is active '''
return True
@Slot()
def update(self, value):
''' Receive ASN.1 value '''
pass
class TC(QDockWidget, QObject):
''' Subclasses of TC can be used to provide ASN.1 data to the main GUI
and to automatically send it to the application.
Example of uses: Buttons, SQL interface...
Define your widget and send signals at will.
'''
send = Signal()
update = Signal()
# specify a name for the combo button
name = 'Generic TM'
def __init__(self, unused_asn1_type=None, parent=None):
''' Initialisation of the Widget '''
super(TC, self).__init__(parent)
This will fetch all _model classes in global scope,
connect to the DB and return a session object.'''
try:
config_info = open("sql_db/db.info").readlines()
sqlalchemy_url, dbname = config_info[0].strip(), config_info[1].strip()
except:
raise Exception(
"The sql_db/db.info is either missing or invalid!")
os.chdir("sql_db")
for key, val in vars(__import__(dbname + "_model")).iteritems():
if key not in globals():
globals()[key] = val
os.chdir("..")
from sqlalchemy import create_engine
engine = create_engine(sqlalchemy_url, echo=False)
globals()['Base'].metadata.create_all(engine)
from sqlalchemy.orm import sessionmaker
SessionFactory = sessionmaker(bind=engine)
session = SessionFactory()
return session, dbname
class SQLTelecommands(TC):
''' Handle Postgresql databases for telecommands '''
name = 'Get TCs from db'
'''Load telecommands from the database'''
name = 'Get TCs from DB'
session = None
dbname = None
......@@ -78,38 +102,13 @@ class SQLTelecommands(TC):
super(SQLTelecommands, self).__init__(asn1_typename, parent)
if SQLTelecommands.session is None:
SQLTelecommands.session, SQLTelecommands.dbname = \
SQLTelecommands.connect_to_db()
connect_to_db()
self._asn1_typename = asn1_typename
typename_sql = asn1_typename + "_SQL"
self._asn1_klass = globals().get(typename_sql, None)
if self._asn1_klass is None:
print "No class", typename_sql, "found in", SQLTelecommands.dbname
@staticmethod
def connect_to_db():
'''
This will fetch all _model classes in global scope,
connect to the DB and return a session object.'''
try:
config_info = open("sql_db/db.info").readlines()
sqlalchemy_url, dbname = config_info[0].strip(), config_info[1].strip()
except:
print "The sql_db/db.info is either missing or invalid!"
print "Aborting..."
sys.exit(1)
os.chdir("sql_db")
for key, val in vars(__import__(dbname + "_model")).iteritems():
if key not in globals():
globals()[key] = val
os.chdir("..")
from sqlalchemy import create_engine
engine = create_engine(sqlalchemy_url, echo=False)
globals()['Base'].metadata.create_all(engine)
from sqlalchemy.orm import sessionmaker
SessionFactory = sessionmaker(bind=engine)
session = SessionFactory()
return session, dbname
@staticmethod
def applicable():
'''' check if there is a sql_db directory, return False otherwise '''
......@@ -150,33 +149,42 @@ class SQLTelecommands(TC):
class SQLTelemetries(TM):
''' Handle Postgresql databases for telecommands '''
name = 'Store in db'
'''Save telemetries in the database'''
name = 'Store TMs in DB'
session = None
dbname = None
def __init__(self, parent=None):
''' Initialise the widget '''
super(SQLTelemetries, self).__init__(parent)
# to do here = display a window with two buttons:
# "start storing in DB", "stop storing in DB"
# Thanassis: please specify what data you need as parameters
# (I can provide the data type name, the database name...)
self.mode = 'recording'
if SQLTelemetries.session is None:
SQLTelemetries.session, SQLTelemetries.dbname = \
connect_to_db()
@Slot()
def update(self, value):
''' Receive ASN.1 value '''
# value should be in native ASN.1 format
if self.mode == 'recording':
# Convert value to SQL entry and store in DB
pass
klass = value.__class__.__name__ + "_SQL"
asn1_klass = globals().get(klass, None)
if asn1_klass is None:
raise Exception(
"No class " + klass + " found in " + SQLTelemetries.dbname)
db_row = object.__new__(globals()[ask1_klass])
db_row.__init__(value)
iid = db_row.save(SQLTelemetries.session)
SQLTelemetries.session.commit()
return iid
else:
pass
return None
@staticmethod
def applicable():
'''' check if there is a sql_db directory, return False otherwise '''
# Thanassis, please fill
return True
return os.path.isdir("sql_db")
if __name__ == '__main__':
# print 'This module can only be imported from the main TASTE guis'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment