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"
import sys
import os
import importlib
from PySide.QtCore import (QObject, Signal, Slot, Qt, QRectF, QPointF, QPoint)
from PySide.QtGui import QDockWidget
......@@ -78,20 +79,20 @@ def connect_to_db():
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
global db_module
db_module = importlib.import_module(dbname + "_model")
os.chdir("..")
from sqlalchemy import create_engine
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
SessionFactory = sessionmaker(bind=engine)
session = SessionFactory()
return session, dbname
class SQLTelecommands(TC):
#class SQLTelecommands(TC):
class SQLTelecommands(object):
'''Load telecommands from the database'''
name = 'Get TCs from DB'
session = None
......@@ -99,13 +100,14 @@ class SQLTelecommands(TC):
def __init__(self, asn1_typename, parent=None):
''' 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:
SQLTelecommands.session, SQLTelecommands.dbname = \
connect_to_db()
self._asn1_typename = asn1_typename
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:
print "No class", typename_sql, "found in", SQLTelecommands.dbname
......@@ -133,7 +135,7 @@ class SQLTelecommands(TC):
if row is not None:
return row.asn1
else:
return None
raise IndexError("Index %d out of range" % idx)
def onUpdateButtonClick(self, lineNb):
''' When user clicks on Update, the content of the selected TC will
......@@ -148,7 +150,8 @@ class SQLTelecommands(TC):
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'''
name = 'Store TMs in DB'
session = None
......@@ -156,7 +159,8 @@ class SQLTelemetries(TM):
def __init__(self, parent=None):
''' 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:
# "start storing in DB", "stop storing in DB"
self.mode = 'recording'
......@@ -169,12 +173,11 @@ class SQLTelemetries(TM):
''' Receive ASN.1 value '''
if self.mode == 'recording':
klass = value.__class__.__name__ + "_SQL"
asn1_klass = globals().get(klass, None)
asn1_klass = getattr(db_module, klass, None)
if asn1_klass is None:
raise Exception(
"No class " + klass + " found in " + SQLTelemetries.dbname)
db_row = object.__new__(globals()[asn1_klass])
db_row.__init__(value)
db_row = getattr(db_module, asn1_klass)(value)
iid = db_row.save(SQLTelemetries.session)
SQLTelemetries.session.commit()
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