Commit e8ee5a44 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras
Browse files

TC part written (untested)

parent c4376192
......@@ -12,21 +12,19 @@
be placed in a docking window.
(c) 2016 European Space Agency
Authors: Maxime Perrotin, Thanassis Tsiodras
'''
__author__ = "Maxime Perrotin, Thanassis Tsiodras"
__license__ = "LGPL"
__version__ = "1.0"
__url__ = "http://taste.tuxfamily.org"
import sys
import os
from PySide.QtCore import (QObject, Signal, Slot, Qt, QRectF, QPointF, QPoint)
from PySide.QtGui import QDockWidget
__author__ = "Maxime Perrotin, Thanassis Tsiodras"
__license__ = "LGPL"
__version__ = "1.0"
__url__ = "http://taste.tuxfamily.org"
# User must list explicitly the classes he wants to expose to the GUI:
__all__ = ['SQLTelecommands', 'SQLTelemetries']
......@@ -38,7 +36,7 @@ class TM(QDockWidget, QObject):
# specify a name for the combo button
name = 'Generic TM'
def __init__(self, asn1_type=None, parent=None):
def __init__(self, unused_asn1_type=None, parent=None):
''' Initialisation of the Widget '''
super(TM, self).__init__(parent)
......@@ -64,7 +62,7 @@ class TC(QDockWidget, QObject):
# specify a name for the combo button
name = 'Generic TM'
def __init__(self, asn1_type=None, parent=None):
def __init__(self, unused_asn1_type=None, parent=None):
''' Initialisation of the Widget '''
super(TC, self).__init__(parent)
......@@ -73,17 +71,47 @@ class SQLTelecommands(TC):
''' Handle Postgresql databases for telecommands '''
name = 'Get TCs from db'
session = None
dbname = None
asn1SQLclasses = {}
def __init__(self, asn1_typename, parent=None):
''' Initialise the widget '''
super(SQLTelecommands, self).__init__(asn1_typename, parent)
# to do here = create a table widget, and place all the entries
# of the given ASN.1 type
if SQLTelecommands.session is None:
SQLTelecommands.connectToDB()
SQLTelecommands.session = SQLTelecommands.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 connectToDB():
pass
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], config_info[1]
except:
print "The sql_db/db.info is either missing or invalid!"
print "Aborting..."
sys.exit(1)
SQLTelecommands.dbname = dbname
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
@staticmethod
def applicable():
......@@ -91,13 +119,21 @@ class SQLTelecommands(TC):
return os.path.isdir("sql_db")
def getPageIndexes(self, offset, number):
# Thanassis, please fill this one
pass
return [
x.asn1
for x in SQLTelecommands.session.query(
self._asn1_klass
).filter(
self._asn1_klass.iid.between(offset, offset + number)
)
]
def sql2asn1(self, idx):
''' Thanassis: please retrieve the db entry for index "lineNb"
and convert it to an ASN.1 native type '''
pass
return SQLTelecommands.session.query(
self._asn1_klass
).filter(
self._asn1_klass.iid == idx
).first()
def onUpdateButtonClick(self, lineNb):
''' When user clicks on Update, the content of the selected TC will
......@@ -128,7 +164,6 @@ class SQLTelemetries(TM):
@Slot()
def update(self, value):
''' Receive ASN.1 value '''
pass
# value should be in native ASN.1 format
if self.mode == 'recording':
# Convert value to SQL entry and store in DB
......
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