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

Testing TMs infinite recursion

parent 5d942756
...@@ -21,6 +21,7 @@ __url__ = "http://taste.tuxfamily.org" ...@@ -21,6 +21,7 @@ __url__ = "http://taste.tuxfamily.org"
import sys import sys
import os import os
import importlib
from PySide.QtCore import (QObject, Signal, Slot, Qt, QRectF, QPointF, QPoint) from PySide.QtCore import (QObject, Signal, Slot, Qt, QRectF, QPointF, QPoint)
from PySide.QtGui import QDockWidget from PySide.QtGui import QDockWidget
...@@ -78,20 +79,20 @@ def connect_to_db(): ...@@ -78,20 +79,20 @@ def connect_to_db():
raise Exception( raise Exception(
"The sql_db/db.info is either missing or invalid!") "The sql_db/db.info is either missing or invalid!")
os.chdir("sql_db") os.chdir("sql_db")
for key, val in vars(__import__(dbname + "_model")).iteritems(): global db_module
if key not in globals(): db_module = importlib.import_module(dbname + "_model")
globals()[key] = val
os.chdir("..") os.chdir("..")
from sqlalchemy import create_engine from sqlalchemy import create_engine
engine = create_engine(sqlalchemy_url, echo=False) engine = create_engine(sqlalchemy_url, echo=False)
globals()['Base'].metadata.create_all(engine) getattr(db_module, 'Base').metadata.create_all(engine)
from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import sessionmaker
SessionFactory = sessionmaker(bind=engine) SessionFactory = sessionmaker(bind=engine)
session = SessionFactory() session = SessionFactory()
return session, dbname return session, dbname
class SQLTelecommands(TC): #class SQLTelecommands(TC):
class SQLTelecommands(object):
'''Load telecommands from the database''' '''Load telecommands from the database'''
name = 'Get TCs from DB' name = 'Get TCs from DB'
session = None session = None
...@@ -99,13 +100,14 @@ class SQLTelecommands(TC): ...@@ -99,13 +100,14 @@ class SQLTelecommands(TC):
def __init__(self, asn1_typename, parent=None): def __init__(self, asn1_typename, parent=None):
''' Initialise the widget ''' ''' Initialise the widget '''
super(SQLTelecommands, self).__init__(asn1_typename, parent) #super(SQLTelecommands, self).__init__(asn1_typename, parent)
super(SQLTelecommands, self).__init__()
if SQLTelecommands.session is None: if SQLTelecommands.session is None:
SQLTelecommands.session, SQLTelecommands.dbname = \ SQLTelecommands.session, SQLTelecommands.dbname = \
connect_to_db() connect_to_db()
self._asn1_typename = asn1_typename self._asn1_typename = asn1_typename
typename_sql = asn1_typename + "_SQL" typename_sql = asn1_typename + "_SQL"
self._asn1_klass = globals().get(typename_sql, None) self._asn1_klass = getattr(db_module, typename_sql, None)
if self._asn1_klass is None: if self._asn1_klass is None:
print "No class", typename_sql, "found in", SQLTelecommands.dbname print "No class", typename_sql, "found in", SQLTelecommands.dbname
...@@ -133,7 +135,7 @@ class SQLTelecommands(TC): ...@@ -133,7 +135,7 @@ class SQLTelecommands(TC):
if row is not None: if row is not None:
return row.asn1 return row.asn1
else: else:
return None raise IndexError("Index %d out of range" % idx)
def onUpdateButtonClick(self, lineNb): def onUpdateButtonClick(self, lineNb):
''' When user clicks on Update, the content of the selected TC will ''' When user clicks on Update, the content of the selected TC will
...@@ -148,7 +150,8 @@ class SQLTelecommands(TC): ...@@ -148,7 +150,8 @@ class SQLTelecommands(TC):
self.send.emit(as_asn1) # use signal to send data to the GUI self.send.emit(as_asn1) # use signal to send data to the GUI
class SQLTelemetries(TM): #class SQLTelemetries(TM):
class SQLTelemetries(object):
'''Save telemetries in the database''' '''Save telemetries in the database'''
name = 'Store TMs in DB' name = 'Store TMs in DB'
session = None session = None
...@@ -156,7 +159,8 @@ class SQLTelemetries(TM): ...@@ -156,7 +159,8 @@ class SQLTelemetries(TM):
def __init__(self, parent=None): def __init__(self, parent=None):
''' Initialise the widget ''' ''' Initialise the widget '''
super(SQLTelemetries, self).__init__(parent) #super(SQLTelemetries, self).__init__(parent)
super(SQLTelemetries, self).__init__()
# to do here = display a window with two buttons: # to do here = display a window with two buttons:
# "start storing in DB", "stop storing in DB" # "start storing in DB", "stop storing in DB"
self.mode = 'recording' self.mode = 'recording'
...@@ -169,12 +173,11 @@ class SQLTelemetries(TM): ...@@ -169,12 +173,11 @@ class SQLTelemetries(TM):
''' Receive ASN.1 value ''' ''' Receive ASN.1 value '''
if self.mode == 'recording': if self.mode == 'recording':
klass = value.__class__.__name__ + "_SQL" klass = value.__class__.__name__ + "_SQL"
asn1_klass = globals().get(klass, None) asn1_klass = getattr(db_module, klass, None)
if asn1_klass is None: if asn1_klass is None:
raise Exception( raise Exception(
"No class " + klass + " found in " + SQLTelemetries.dbname) "No class " + klass + " found in " + SQLTelemetries.dbname)
db_row = object.__new__(globals()[asn1_klass]) db_row = getattr(db_module, asn1_klass)(value)
db_row.__init__(value)
iid = db_row.save(SQLTelemetries.session) iid = db_row.save(SQLTelemetries.session)
SQLTelemetries.session.commit() SQLTelemetries.session.commit()
return iid return iid
......
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