Commit 6bd655a7 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Specify property file with the cli

parent 34271366
......@@ -16,7 +16,7 @@ import sys
import platform
import re
import logging
import optparse
import argparse
import time
from functools import partial
from ctypes import CDLL
......@@ -130,7 +130,7 @@ def gui():
# Exit app on Ctrl-C
signal.signal(signal.SIGINT, signal.SIG_DFL)
usage = 'usage: gui.py [--udp=IP_Address:in_Port:out_Port]'
#usage = 'usage: gui.py [--udp=IP_Address:in_Port:out_Port]'
version = 'taste auto-gui %s' % (__version__)
# Set up the logging facilities
......@@ -143,19 +143,22 @@ def gui():
sys.stdout = myPrint
# Parse the command line
parser = optparse.OptionParser(usage=usage, version=version)
parser.add_option('-v', '--verbose', action='store_true', default=False,
parser = argparse.ArgumentParser(version=version)
parser.add_argument('-g', '--verbose', action='store_true', default=False,
help='Display debug information')
parser.add_option('--udp', dest='udp', metavar='RemoteIP:inPort:outPort',
parser.add_argument('--udp', dest='udp', metavar='RemoteIP:inPort:outPort',
help='Use UDP sockets instead of message queues')
parser.add_option('-l', '--shared_lib', action='store_true', default=False,
help='Use a shared library instead of msgQ or UDP')
parser.add_option('-r', '--reset', action='store_true', default=False,
parser.add_argument('-l', '--shared_lib', action='store_true',
default=False, help='Simulate SDL system, '
'using a shared library')
parser.add_argument('-r', '--reset', action='store_true', default=False,
help='Do not try to restore windows layout')
parser.add_option('-i', '--ivpath', dest='ivpath',
parser.add_argument('-p', '--properties', dest='properties',
help='Specify a file containing stop conditions')
parser.add_argument('-i', '--ivpath', dest='ivpath',
default='./InterfaceView.aadl',
help='Path and filename of the system interface view')
options, args = parser.parse_args()
options = parser.parse_args()
if options.verbose:
log.setLevel(logging.DEBUG)
else:
......@@ -334,6 +337,8 @@ def gui():
else:
sdlButton = toolbar.addAction('SDL')
sdlButton.triggered.connect(sdl.startStop)
if options.properties:
sdl.load_properties(options.properties)
# Set the ASN.1 data type of each TC editor
......
......@@ -2,7 +2,7 @@
# Resource object code
#
# Created: Fri Mar 20 20:00:31 2015
# Created: Sat Mar 21 16:33:04 2015
# by: The Resource Compiler for PySide (Qt v4.8.6)
#
# WARNING! All changes made in this file will be lost!
......
......@@ -140,7 +140,7 @@ class sdlHandler(QObject):
undo_button.clicked.connect(self.undo)
redo_button.clicked.connect(self.redo)
# Placeholder to keep a list of properties to be checked at runtime
self.properties = []
self.properties = {}
self.prop_dll = None
@property
......@@ -203,33 +203,50 @@ class sdlHandler(QObject):
self.check_state()
self.init_state = self.current_hash = self.on_event()
self.init_timers()
# Try loading property file
self.load_properties()
def load_properties(self):
def load_properties(self, prop_file=None):
''' Try loading a shared object with properties to verify
Properties are e.g. stop conditions, processed by the "properties.py"
module, and transformed to Ada code compiled as a dynamic library.
There may be several properties, this function tries to retrieve
them all without a priori knowledge of their content '''
if not prop_file:
return
try:
self.prop_dll = ctypes.CDLL('lib{}_stop_conditions.so'
.format(self.proc.processName))
except OSError as err:
self.log_area.addItem('No properties to load')
else:
self.log_area.addItem('Found property file')
idx = 0
while True:
try:
prop = getattr(self.prop_dll, '_property_{}'.format(idx))
prop.restype = ctypes.c_uint
self.properties.append(prop)
except AttributeError:
break
else:
idx +=1
self.log_area.addItem('Loaded {} properties'.format(idx))
self.log_area.addItem('lib{}_stop_conditions.so not found'
.format(self.proc.processName))
return
properties = []
idx = 0
while True:
try:
prop = getattr(self.prop_dll, '_property_{}'.format(idx))
prop.restype = ctypes.c_uint
properties.append(prop)
except AttributeError:
break
else:
idx +=1
self.log_area.addItem('Loaded {} properties'.format(idx))
self.log_area.addItem('Property file: {}'.format(prop_file))
try:
with open(prop_file, 'r') as pt:
props, syntax, semantic, warnings, term = \
opengeode.ogParser.parseSingleElement('stop_if',
pt.read(),
self.proc)
if syntax or semantic:
raise IOError('Properties parsing error')
except IOError as err:
self.log_area.addItem('Could not open property file!')
return
if idx != len(props):
self.log_area.addItem('Wrong number of properties found!')
return
self.properties = {ppty.inputString: ptr for ppty, ptr in zip(props, properties)}
def check_properties(self, statehash):
''' Check the properties at runtime
......@@ -238,9 +255,9 @@ class sdlHandler(QObject):
if not self.prop_dll:
return
self.restore_global_state(statehash, dll=self.prop_dll)
for idx, check in enumerate(self.properties):
for text, check in self.properties.viewitems():
if check():
self.log_area.addItem('Property {} was violated'.format(idx))
self.log_area.addItem('Property "{}" is true'.format(text))
@Slot()
def startStop(self):
......
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