Source code for eventmodule.EventHandler
from sys import (argv,exit)
from lxml import etree
from .docopt import docopt
import coverage
import os
curdir = os.path.dirname(os.path.abspath(__file__))
cov = coverage.Coverage(config_file=curdir+"/.coveragerc")
cov.start()
docopt_interface=\
"""EventHandler
Usage:
API.py (handle_event | handle_example | handle_tests) [--patient=<patient_xml> --event=<number> --coverage]
API.py (-h | --help)
Options:
-h --help Show this screen.
--patient=<patient_xml> Location of the patient xml file
--event=<number> Number of the event that needs to be executed
--coverage Create coverage report during run
"""
[docs]class EventHandler():
"""
This is the EventHandler class that should be subclassed by any Event Handler
(piece of software) within the in-silico-trial.
:ivar etree_xml root: contains a lxml instance with all information from the patient_xml file
:ivar etree_xml patient: contains a lxml instance with patient specific information
:ivar etree_xml event: contains a lxml instance with the event specific information
:ivar etree_xml insist: contains a lxml instance with the insist generic trial information
"""
[docs] def __init__(self,action=None, patient_xml=None,event_number=None, do_coverage=None):
arguments = docopt(docopt_interface, version='0.1') #: Read in the command line arguments
self.root = None #: XML tree containing everything, including the patient and event
self.patient = None #: XML tree containing information about the patient
self.event = None #: XML tree containing information about the event
self.insist = None #: XML tree containing the in silico trial
if not hasattr(self,"example_event_number"):
self.example_event_number = None
if not hasattr(self,"example_patient_xml"):
self.example_patient_xml = None
if (do_coverage == None):
do_coverage = arguments["--coverage"]
if (not do_coverage):
cov.stop()
if (action == None):
action = argv[1]
if patient_xml == None:
patient_xml = arguments["--patient"]
if event_number == None:
event_number = arguments["--event"]
if action=="handle_example" or action=="handle_tests":
if not event_number:
event_number = self.example_event_number
if not patient_xml:
patient_xml = self.example_patient_xml
if event_number == None or patient_xml == None:
raise ValueError("--event or --patient not given as commandline argument and no override")
self.parseTavernaInput(patient_xml,event_number)
getattr(self, action)()
#TODO optional arguments are possible with kwargs
if(do_coverage):
cov.stop()
cov.report()
[docs] def handle_event(self):
"""
A method that should be implemented in the API
"""
raise NotImplementedError("Please implement the handle_event method to handle events")
[docs] def handle_example(self):
"""
A method that should be implemented in the API
"""
raise NotImplementedError("Please implement the handle_example method to handle example")
[docs] def handle_tests(self):
"""
A method that should be implemented in the API
"""
raise NotImplementedError("Please implement the handle_example method to handle example")
if __name__ == "__main__":
print("This file should not be called directly")
exit(1)