def __init__(self,settings: dict): # private properties self._channels: list = settings.get('channels') self._user: str = settings.get('user') self._password: str = settings.get('password') self._caprequest: str = settings.get('caprequest') self._server = IrcController.IrcController(settings.get("server"),settings.get("port")) self._messageHandler: MessageHandler = MessageHandler.MessageHandler() self._sendQ: queue.SimpleQueue = queue.SimpleQueue() # public properties self.event: EventHandler = EventHandler self.COMMANDS: MessageHandler.COMMANDS = self._messageHandler.COMMANDS self.startWithThread=threading.Thread(target=self.start, daemon=True).start self.channels: dict = {} self.globalUserState: MessageHandler.globalUSerState = MessageHandler.globalUSerState() # Register System Event functions self.event.on(self.COMMANDS.CONNECTED, self._onConnected) self.event.on(self.COMMANDS.NOTICE, self._onNotice) self.event.on(self.COMMANDS.ROOMSTATE, self._onRoomState) self.event.on(self.COMMANDS.USERSTATE, self._setUserState) self.event.on(self.COMMANDS.MESSAGEIDS.ROOM_MODS, self._setChannelMods) self.event.on(self.COMMANDS.GLOBALUSERSTATE, self._setGlobalUserSate) self.event.on(self.COMMANDS.ROOMSTATE.EMOTE_ONLY, self._onEmotesOnly) self.event.on(self.COMMANDS.ROOMSTATE.FOLLOWERS_ONLY, self._onFollowersOnly) self.event.on(self.COMMANDS.ROOMSTATE.SLOW, self._onSlowMode) self.event.on(self.COMMANDS.ROOMSTATE.SUBS_ONLY, self._onSubsOnly) self.event.on(self.COMMANDS.ROOMSTATE.R9K, self._onR9k)
def m_handler(self, *arg, **karg): _filter = karg["filter"] def _m_handler(bot, update): message = update.effective_message.text reply = self.handler(message=message) if reply is None: return if isinstance(reply, (str, unicode)): update.effective_message.reply_text(reply) else: try: reply_markup = _generateMenu(reply[sadDec._MENU_INDEX_]) update.effective_message.reply_text( reply[sadDec._MESSAGE_INDEX_], reply_markup=reply_markup) except IndexError: logging.error("Bad menu formatting") _newMessageHandler = MessageHandler.MessageHandler( _m_handler, _filter, funcName=self.handler.funcName, description=self.handler.description) return _newMessageHandler
def test_client_discovery_works(self): mh = MessageHandler.MessageHandler(self.client._client_id, testing=True) self.client.set_message_queue(mh) self.client.send_discovery() test = mh.get_queue().get_nowait() self.assertTrue(test is not None)
def __init__(self, settings: dict): """ """ # private properties self._channels: list = settings.get('channels') self._user: str = settings.get('user') self._password: str = settings.get('password') self._caprequest: str = settings.get('caprequest') self._server = IrcController.IrcController(settings.get("server"), settings.get("port")) self._messageHandler: MessageHandler = MessageHandler.MessageHandler() self._sendQ: queue.SimpleQueue = queue.SimpleQueue() # public properties self.event: EventHandler = EventHandler self.COMMANDS: COMMANDS = self._messageHandler.COMMANDS self.startWithThread = threading.Thread(target=self.start, daemon=True).start self.roomState: RoomState = MessageHandler.RoomState self.channels: dict = {} # Register System Event functions self.event.on(self.COMMANDS.CONNECTED, self._onConnected) self.event.on(self.COMMANDS.NOTICE, self._onNotice) self.event.on(self.COMMANDS.ROOMSTATE, self._onRoomState) self.event.on(self.COMMANDS.MESSAGEIDS.ROOM_MODS, self._setChannelMods)
def __init__(self, server, sock, ip_addr): self.sock = sock self.ip_addr = ip_addr self.active = False self.send_queue = Queue.Queue() self.receiver = MessageReceiver(self.sock) self.sender = MessageSender(self.sock) self.handler = MessageHandler() self.server = server self.last_read_time = 0
def __init__(self, gametype, pgui): self.gui = pgui self.filesystem = FileSystem() self.iohandler = IOHandler(gametype, pgui) self.mapmanager = MapManager(self.filesystem.getData('map')) self.mapmanager.getVisibleObjects() self.messagehandler = MessageHandler( self.filesystem.getData("messages")) self.gamerun = False self.securitycamera = True self.talked = False
def run(self): msgHandler = MessageHandler() # self.trigger.emit(msgHandler) @msgHandler.bot.register() def addMessage(msg): print("Msg:\"" + msg.text + "\" received from " + msg.sender.remark_name + " is gonna pass to the main thread.") # msgListItemWidget = MsgListItemWidget(parent=ui.msgListWidget) # msgListItemWidget.setAllInfo("1.jpg", msg.sender.remark_name, msg.text) # msgListWidgetItem = QtWidgets.QListWidgetItem(ui.msgListWidget) # As a container # msgListWidgetItem.setSizeHint(msgListItemWidget.sizeHint()) # # ui.msgListWidget.addItem(msgListWidgetItem) # ui.msgListWidget.setItemWidget(msgListWidgetItem, msgListItemWidget) self.newMessage.emit(msg, msgHandler.bot.messages) msgHandler.botJoin()
def main(): import MessageHandler import Notifier import threading logger.setLevel(logging.INFO) logger.info("Instantiating the different components we need.") #Instantiating the different components we need. client = Client() monman = MonitorManager.MonitorManager() cexec = CommandInterface.CommandInterface() notifier = Notifier.Notifier(client.get_client_id()) messagehandler = MessageHandler.MessageHandler(client.get_client_id()) logger.info("Setting the outgoing message queue.") #Setting the outgoing message queue client.set_message_queue(messagehandler) monman.set_message_queue(messagehandler) ##TODO THIS SHIT IS TEMPORARY. MAKE A LOCK FACTORY CLASS OR SOMETHING. ##SETTING LOCKS FOR THE MONITORS SO WHEN THEY ARE BEING MODIFIED THEY CANT BE POLLED. lock = threading.RLock() monman.set_lock(lock) notifier._data_manager.set_lock(lock) logger.info("Giving client access to crucial components") #Giving client access to crucial components client.set_monitor_manager(monman) client.set_command_executor(cexec) client.set_notifier(notifier) #making the client visible on the nameserver client.register_to_name_server() #Sending a "Hey I"m here!" message to the server. client.send_discovery() #Starting the outgoing message queue messagehandler.start() #Beginning the monitoring cycle. client.begin_monitoring()
def __init__(self, ip): """ :param ip: Ip-address of RCM conected to computer. :return: """ self.nbr_of_measurements = 1 self.tol = [1e-6, 1e-6] # [abs_tol, rel_tol] self.msg_handler = MessageHandler.MessageHandler() self.msg_handler.set_ip(ip) self.nbr_of_anchors = 3 # same as len(self.anchors) self.anchors = [] for j in range(0, self.nbr_of_anchors): self.anchors += [Anchor.Anchor()] """ These are the instatioations of the Anchors (see Anchors.py) Change these whenever anchors are moved/replaced. """ self.__set_anchor__(0, 106, -1.0, -2.0) self.__set_anchor__(1, 114, -1.0, 2.0) self.__set_anchor__(2, 108, 2.0, 0.0)
def __init__(self,frameworkDir,verbosity='all',interactive=Interaction.No): """ Constructor @ In, frameworkDir, string, absolute path to framework directory @ In, verbosity, string, optional, general verbosity level @ In, interactive, Interaction, optional, toggles the ability to provide an interactive UI or to run to completion without human interaction @ Out, None """ self.FIXME = False #set the numpy print threshold to avoid ellipses in array truncation np.set_printoptions(threshold=np.inf) #establish message handling: the error, warning, message, and debug print handler self.messageHandler = MessageHandler.MessageHandler() self.verbosity = verbosity callerLength = 25 tagLength = 15 suppressErrs = False self.messageHandler.initialize({'verbosity':self.verbosity, 'callerLength':callerLength, 'tagLength':tagLength, 'suppressErrs':suppressErrs}) readtime = datetime.datetime.fromtimestamp(self.messageHandler.starttime).strftime('%Y-%m-%d %H:%M:%S') sys.path.append(os.getcwd()) #this dictionary contains the general info to run the simulation self.runInfoDict = {} self.runInfoDict['DefaultInputFile' ] = 'test.xml' #Default input file to use self.runInfoDict['SimulationFiles' ] = [] #the xml input file self.runInfoDict['ScriptDir' ] = os.path.join(os.path.dirname(frameworkDir),"scripts") # the location of the pbs script interfaces self.runInfoDict['FrameworkDir' ] = frameworkDir # the directory where the framework is located self.runInfoDict['RemoteRunCommand' ] = os.path.join(frameworkDir,'raven_qsub_command.sh') self.runInfoDict['NodeParameter' ] = '-f' # the parameter used to specify the files where the nodes are listed self.runInfoDict['MPIExec' ] = 'mpiexec' # the command used to run mpi commands self.runInfoDict['WorkingDir' ] = '' # the directory where the framework should be running self.runInfoDict['TempWorkingDir' ] = '' # the temporary directory where a simulation step is run self.runInfoDict['NumMPI' ] = 1 # the number of mpi process by run self.runInfoDict['NumThreads' ] = 1 # Number of Threads by run self.runInfoDict['numProcByRun' ] = 1 # Total number of core used by one run (number of threads by number of mpi) self.runInfoDict['batchSize' ] = 1 # number of contemporaneous runs self.runInfoDict['internalParallel' ] = False # activate internal parallel (parallel python). If True parallel python is used, otherwise multi-threading is used self.runInfoDict['ParallelCommand' ] = '' # the command that should be used to submit jobs in parallel (mpi) self.runInfoDict['ThreadingCommand' ] = '' # the command should be used to submit multi-threaded self.runInfoDict['totalNumCoresUsed' ] = 1 # total number of cores used by driver self.runInfoDict['queueingSoftware' ] = '' # queueing software name self.runInfoDict['stepName' ] = '' # the name of the step currently running self.runInfoDict['precommand' ] = '' # Add to the front of the command that is run self.runInfoDict['postcommand' ] = '' # Added after the command that is run. self.runInfoDict['delSucLogFiles' ] = False # If a simulation (code run) has not failed, delete the relative log file (if True) self.runInfoDict['deleteOutExtension'] = [] # If a simulation (code run) has not failed, delete the relative output files with the listed extension (comma separated list, for example: 'e,r,txt') self.runInfoDict['mode' ] = '' # Running mode. Curently the only mode supported is mpi but others can be added with custom modes. self.runInfoDict['Nodes' ] = [] # List of node IDs. Filled only in case RAVEN is run in a DMP machine self.runInfoDict['expectedTime' ] = '10:00:00' # How long the complete input is expected to run. self.runInfoDict['logfileBuffer' ] = int(io.DEFAULT_BUFFER_SIZE)*50 # logfile buffer size in bytes self.runInfoDict['clusterParameters' ] = [] # Extra parameters to use with the qsub command. self.runInfoDict['maxQueueSize' ] = None #Following a set of dictionaries that, in a manner consistent with their names, collect the instance of all objects needed in the simulation #Theirs keywords in the dictionaries are the the user given names of data, sampler, etc. #The value corresponding to a keyword is the instance of the corresponding class self.stepsDict = {} self.dataDict = {} self.samplersDict = {} self.modelsDict = {} self.distributionsDict = {} self.dataBasesDict = {} self.functionsDict = {} self.filesDict = {} # for each file returns an instance of a Files class self.metricsDict = {} self.OutStreamManagerPlotDict = {} self.OutStreamManagerPrintDict = {} self.stepSequenceList = [] #the list of step of the simulation #list of supported queue-ing software: self.knownQueueingSoftware = [] self.knownQueueingSoftware.append('None') self.knownQueueingSoftware.append('PBS Professional') #Dictionary of mode handlers for the self.__modeHandlerDict = CustomModes.modeHandlers #self.__modeHandlerDict['mpi'] = CustomModes.MPISimulationMode #self.__modeHandlerDict['mpilegacy'] = CustomModes.MPILegacySimulationMode #this dictionary contain the static factory that return the instance of one of the allowed entities in the simulation #the keywords are the name of the module that contains the specialization of that specific entity self.addWhatDict = {} self.addWhatDict['Steps' ] = Steps self.addWhatDict['DataObjects' ] = DataObjects self.addWhatDict['Samplers' ] = Samplers self.addWhatDict['Optimizers' ] = Optimizers self.addWhatDict['Models' ] = Models self.addWhatDict['Distributions' ] = Distributions self.addWhatDict['Databases' ] = Databases self.addWhatDict['Functions' ] = Functions self.addWhatDict['Files' ] = Files self.addWhatDict['Metrics' ] = Metrics self.addWhatDict['OutStreams' ] = {} self.addWhatDict['OutStreams' ]['Plot' ] = OutStreams self.addWhatDict['OutStreams' ]['Print'] = OutStreams #Mapping between an entity type and the dictionary containing the instances for the simulation self.whichDict = {} self.whichDict['Steps' ] = self.stepsDict self.whichDict['DataObjects' ] = self.dataDict self.whichDict['Samplers' ] = self.samplersDict self.whichDict['Optimizers' ] = self.samplersDict self.whichDict['Models' ] = self.modelsDict self.whichDict['RunInfo' ] = self.runInfoDict self.whichDict['Files' ] = self.filesDict self.whichDict['Distributions' ] = self.distributionsDict self.whichDict['Databases' ] = self.dataBasesDict self.whichDict['Functions' ] = self.functionsDict self.whichDict['Metrics' ] = self.metricsDict self.whichDict['OutStreams'] = {} self.whichDict['OutStreams']['Plot' ] = self.OutStreamManagerPlotDict self.whichDict['OutStreams']['Print'] = self.OutStreamManagerPrintDict # The QApplication ## The benefit of this enumerated type is that anything other than ## Interaction.No will evaluate to true here and correctly make the ## interactive app. if interactive: self.app = InteractiveApplication([],self.messageHandler, interactive) else: self.app = None #the handler of the runs within each step self.jobHandler = JobHandler() #handle the setting of how the jobHandler act self.__modeHandler = SimulationMode(self.messageHandler) self.printTag = 'SIMULATION' self.raiseAMessage('Simulation started at',readtime,verbosity='silent') self.pollingThread = threading.Thread(target=self.jobHandler.startLoop) ## This allows RAVEN to exit when the only thing left is the JobHandler ## This should no longer be necessary since the jobHandler now has an off ## switch that this object can flip when it is complete, however, if ## simulation fails before it is finished, we should probably still ensure ## that this thread is killed as well, so maybe it is best to keep it for ## now. self.pollingThread.daemon = True self.pollingThread.start()
import xarray as xr # find location of crow, message handler frameworkDir = os.path.abspath(os.path.join(*([os.path.dirname(__file__)]+[os.pardir]*4+['framework']))) sys.path.append(frameworkDir) from utils.utils import find_crow find_crow(frameworkDir) import MessageHandler # find location of data objects sys.path.append(os.path.join(frameworkDir,'DataObjects')) import HistorySet mh = MessageHandler.MessageHandler() mh.initialize({'verbosity':'debug', 'callerLength':10, 'tagLength':10}) print('Module undergoing testing:') print(HistorySet ) print('') def createElement(tag,attrib=None,text=None): """ Method to create a dummy xml element readable by the distribution classes @ In, tag, string, the node tag @ In, attrib, dict, optional, the attribute of the xml node @ In, text, str, optional, the dict containig what should be in the xml text """ if attrib is None: attrib = {}
import sys import os #establish required paths for importing MessageHandler frameworkDir = os.path.abspath( os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', '..', '..', 'framework')) sys.path.append(frameworkDir) sys.path.append(os.path.join(frameworkDir, 'utils')) import MessageHandler #establish a basic message user user = MessageHandler.MessageUser() user.printTag = 'MessageUser' user.messageHandler = MessageHandler.MessageHandler() user.messageHandler.initialize({'verbosity': 'all'}) #test that exceptions raised through raiseAnError can be caught try: user.raiseAnError(RuntimeError, 'An example error') except RuntimeError: user.raiseAMessage('Error catching works as expected.') """ <TestInfo> <name>framework.test_trycatch</name> <author>talbpaul</author> <created>2016-02-26</created> <classesTested>MessageHandler</classesTested> <description> This test is aimed to perform Unit test on the MessageHandler
class Test_MessageHandler(unittest.TestCase): MH = MessageHandler.MessageHandler() def test_1_PRIVMSG(self): event, message = self.MH.handleMessage( "@badge-info=;badges=global_mod/1,turbo/1;color=#0D4200;display-name=ronni;emotes=25:0-4,12-16/1902:6-10;id=b34ccfc7-4977-403a-8a94-33c6bac34fb8;mod=0;room-id=1337;subscriber=0;tmi-sent-ts=1507246572675;turbo=1;user-id=1337;user-type=global_mod :[email protected] PRIVMSG #ronni :Kappa Keepo Kappa" ) self.assertIsInstance(event, str) self.assertIsInstance(message, MessageHandler.Message) self.assertEqual(event, self.MH.COMMANDS.MESSAGE) self.assertEqual(len(message.tags), 13) self.assertEqual(len(message.tags.get("emotes")), 2) self.assertEqual(message.text, "Kappa Keepo Kappa") self.assertEqual(message.username, "ronni") self.assertEqual(message.channel, "#ronni") def test_2_CLEARCHAT(self): event, message = self.MH.handleMessage( ":tmi.twitch.tv CLEARCHAT #dallas :ronni") self.assertIsInstance(event, str) self.assertIsInstance(message, MessageHandler.Message) self.assertEqual(event, self.MH.COMMANDS.CLEARCHAT) def test_3_CLEARMSG(self): event, message = self.MH.handleMessage( "@login=ronni;target-msg-id=abc-123-def :tmi.twitch.tv CLEARMSG #dallas :HeyGuys" ) self.assertIsInstance(event, str) self.assertIsInstance(message, MessageHandler.Message) self.assertEqual(event, self.MH.COMMANDS.CLEARMSG) def test_4_GLOBALUSERSTATE(self): event, message = self.MH.handleMessage( "@badge-info=subscriber/8;badges=subscriber/6;color=#0D4200;display-name=dallas;emote-sets=0,33,50,237,793,2126,3517,4578,5569,9400,10337,12239;turbo=0;user-id=1337;user-type=admin :tmi.twitch.tv GLOBALUSERSTATE" ) self.assertIsInstance(event, str) self.assertIsInstance(message, MessageHandler.Message) self.assertEqual(event, self.MH.COMMANDS.GLOBALUSERSTATE) def test_5_ROOMSTATE(self): event, message = self.MH.handleMessage( "@emote-only=0;followers-only=0;r9k=0;slow=0;subs-only=0 :tmi.twitch.tv ROOMSTATE #dallas" ) self.assertIsInstance(event, str) self.assertIsInstance(message, MessageHandler.Message) self.assertEqual(event, self.MH.COMMANDS.ROOMSTATE) def test_6_USERNOTICE(self): event, message = self.MH.handleMessage( "@badge-info=;badges=staff/1,broadcaster/1,turbo/1;color=#008000;display-name=ronni;emotes=;id=db25007f-7a18-43eb-9379-80131e44d633;login=ronni;mod=0;msg-id=resub;msg-param-cumulative-months=6;msg-param-streak-months=2;msg-param-should-share-streak=1;msg-param-sub-plan=Prime;msg-param-sub-plan-name=Prime;room-id=1337;subscriber=1;system-msg=ronni\shas\ssubscribed\sfor\s6\smonths!;tmi-sent-ts=1507246572675;turbo=1;user-id=1337;user-type=staff :tmi.twitch.tv USERNOTICE #dallas :Great stream -- keep it up!" ) self.assertIsInstance(event, str) self.assertIsInstance(message, MessageHandler.Message) self.assertEqual(event, self.MH.COMMANDS.USERNOTICE) def test_7_USERSTATE(self): event, message = self.MH.handleMessage( "@badge-info=;badges=staff/1;color=#0D4200;display-name=ronni;emote-sets=0,33,50,237,793,2126,3517,4578,5569,9400,10337,12239;mod=1;subscriber=1;turbo=1;user-type=staff :tmi.twitch.tv USERSTATE #dallas" ) self.assertIsInstance(event, str) self.assertIsInstance(message, MessageHandler.Message) self.assertEqual(event, self.MH.COMMANDS.USERSTATE) def test_8_InvalidMessage(self): event, message = self.MH.handleMessage("3") self.assertIsNone(event) self.assertIsNone(message)
def __init__(self, inputFile): """ Constructor @ In, inputFile, string, input file name @ Out, None """ self.printTag = 'RAVEN_PARSER' # print tag self.inputFile = inputFile # input file name self.outStreamsNames = { } # {'outStreamName':[DataObjectName,DataObjectType]} self.varGroups = {} # variable groups, names and values if not os.path.exists(inputFile): raise IOError(self.printTag + ' ERROR: Not found RAVEN input file') try: tree = ET.parse(open(inputFile, 'r')) except IOError as e: raise IOError(self.printTag + ' ERROR: Input Parsing error!\n' + str(e) + '\n') self.tree = tree.getroot() # expand the ExteranlXML nodes cwd = os.path.dirname(inputFile) xmlUtils.expandExternalXML(self.tree, cwd) # get the NAMES of the variable groups variableGroupNode = self.tree.find('VariableGroups') if variableGroupNode is not None: # make a messageHandler and messageUsesr to handle variable group creation ## if made generally available to this parser, this can be relocated and used generally messageHandler = MessageHandler.MessageHandler() messageHandler.initialize({'verbosity': 'quiet'}) messageUser = MessageHandler.MessageUser() self.varGroups = xmlUtils.readVariableGroups( variableGroupNode, messageHandler, messageUser) # do some sanity checks sequence = [ step.strip() for step in self.tree.find('.//RunInfo/Sequence').text.split(",") ] # firstly no multiple sublevels of RAVEN can be handled now for code in self.tree.findall('.//Models/Code'): if 'subType' not in code.attrib: raise IOError( self.printTag + ' ERROR: Not found subType attribute in <Code> XML blocks!' ) if code.attrib['subType'].strip() == 'RAVEN': raise IOError( self.printTag + ' ERROR: Only one level of RAVEN runs are allowed (Not a chain of RAVEN runs). Found a <Code> of subType RAVEN!' ) # find steps and check if there are active outstreams (Print) foundOutStreams = False for step in self.tree.find('.//Steps'): if step.attrib['name'] in sequence: for role in step: if role.tag.strip() == 'Output': mainClass, subType = role.attrib['class'].strip( ), role.attrib['type'].strip() if mainClass == 'OutStreams' and subType == 'Print': outStream = self.tree.find( './/OutStreams/Print[@name="' + role.text.strip() + '"]' + '/source') if outStream is None: raise IOError( self.printTag + ' ERROR: The OutStream of type "Print" named "' + role.text.strip() + '" has not been found!') dataObjectType = None linkedDataObjectPointSet = self.tree.find( './/DataObjects/PointSet[@name="' + outStream.text.strip() + '"]') if linkedDataObjectPointSet is None: linkedDataObjectHistorySet = self.tree.find( './/DataObjects/HistorySet[@name="' + outStream.text.strip() + '"]') if linkedDataObjectHistorySet is None: # try dataset linkedDataObjectHistorySet = self.tree.find( './/DataObjects/DataSet[@name="' + outStream.text.strip() + '"]') if linkedDataObjectHistorySet is None: raise IOError( self.printTag + ' ERROR: The OutStream of type "Print" named "' + role.text.strip() + '" is linked to not existing DataObject!' ) dataObjectType, xmlNode = "HistorySet", linkedDataObjectHistorySet else: dataObjectType, xmlNode = "PointSet", linkedDataObjectPointSet self.outStreamsNames[role.text.strip()] = [ outStream.text.strip(), dataObjectType, xmlNode ] foundOutStreams = True if not foundOutStreams: raise IOError( self.printTag + ' ERROR: at least one <OutStreams> of type "Print" needs to be inputted in the active Steps!!' ) # Now we grep the paths of all the inputs the SLAVE RAVEN contains in the workind directory. self.workingDir = self.tree.find('.//RunInfo/WorkingDir').text.strip() # Find the Files self.slaveInputFiles = [] filesNode = self.tree.find('.//Files') if filesNode is not None: for child in self.tree.find('.//Files'): subDirectory = child.attrib.get('subDirectory', '') self.slaveInputFiles.append( os.path.expanduser( os.path.join(self.workingDir, subDirectory, child.text.strip()))) externalModels = self.tree.findall('.//Models/ExternalModel') if len(externalModels) > 0: for extModel in externalModels: if 'ModuleToLoad' in extModel.attrib: moduleToLoad = extModel.attrib['ModuleToLoad'] if not moduleToLoad.endswith("py"): moduleToLoad += ".py" if self.workingDir not in moduleToLoad: self.slaveInputFiles.append( os.path.expanduser( os.path.join(self.workingDir, moduleToLoad))) else: self.slaveInputFiles.append( os.path.expanduser(moduleToLoad)) else: if 'subType' not in extModel.attrib or len( extModel.attrib['subType']) == 0: raise IOError( self.printTag + ' ERROR: ExternalModel "' + extModel.attrib['name'] + '" does not have any attribute named "ModuleToLoad" or "subType" with an available plugin name!' ) externalFunctions = self.tree.findall('.//Functions/External') if len(externalFunctions) > 0: for extFunct in externalFunctions: if 'file' in extFunct.attrib: moduleToLoad = extFunct.attrib['file'] if not moduleToLoad.endswith("py"): moduleToLoad += ".py" if self.workingDir not in moduleToLoad: self.slaveInputFiles.append( os.path.expanduser( os.path.join(self.workingDir, moduleToLoad))) else: self.slaveInputFiles.append( os.path.expanduser(moduleToLoad)) else: raise IOError( self.printTag + ' ERROR: Functions/External ' + extFunct.attrib['name'] + ' does not have any attribute named "file"!!')
def setUp(self): self.handler = MessageHandler.MessageHandler("shizuka.client.Mulder", testing=True)
def register(self, handleID, handler=MessageHandler()): self.handlers[handleID] = handler
import GraphHandler as g import MessageHandler as m exit = False baudrate = 15500 timeout = None port_name = "COM4" Gui = g.GraphHandler() MsgHandler = m.MessageHandler(port_name, baudrate_=baudrate, timeout_=timeout) MsgHandler.StartCommunication() while (not Gui.exit): for i in range(3 * g.NUMBER_OF_KINETIS): msg = MsgHandler.ReadFrame() MsgHandler.ManageMessage(msg, len(msg)) list_of_positions = MsgHandler.GetPositions() Gui.UpdateBoards(list_of_positions) MsgHandler.EndCommunication()
def __init__(self, inputFile): """ Constructor @ In, inputFile, string, input file name @ Out, None """ self.printTag = 'RAVEN_PARSER' # print tag self.inputFile = inputFile # input file name self.outStreamsNames = {} # {'outStreamName':[DataObjectName,DataObjectType]} self.databases = {} # {name: full rel path to file with filename} self.varGroups = {} # variable groups, names and values if not os.path.exists(inputFile): raise IOError(self.printTag+' ERROR: Not found RAVEN input file') try: tree = ET.parse(open(inputFile,'r')) except IOError as e: raise IOError(self.printTag+' ERROR: Input Parsing error!\n' +str(e)+'\n') self.tree = tree.getroot() # expand the ExteranlXML nodes cwd = os.path.dirname(inputFile) xmlUtils.expandExternalXML(self.tree,cwd) # get the NAMES of the variable groups variableGroupNode = self.tree.find('VariableGroups') if variableGroupNode is not None: # make a messageHandler and messageUsesr to handle variable group creation ## if made generally available to this parser, this can be relocated and used generally messageHandler = MessageHandler.MessageHandler() messageHandler.initialize({'verbosity':'quiet'}) messageUser = MessageHandler.MessageUser() self.varGroups = mathUtils.readVariableGroups(variableGroupNode,messageHandler,messageUser) # do some sanity checks sequence = [step.strip() for step in self.tree.find('.//RunInfo/Sequence').text.split(",")] # firstly no multiple sublevels of RAVEN can be handled now for code in self.tree.findall('.//Models/Code'): if 'subType' not in code.attrib: raise IOError(self.printTag+' ERROR: Not found subType attribute in <Code> XML blocks!') if code.attrib['subType'].strip() == 'RAVEN': raise IOError(self.printTag+' ERROR: Only one level of RAVEN runs are allowed (Not a chain of RAVEN runs). Found a <Code> of subType RAVEN!') # find steps and check if there are active outstreams (Print) foundOutStreams = False foundDatabases = False for step in self.tree.find('.//Steps'): if step.attrib['name'] in sequence: for role in step: if role.tag.strip() == 'Output': mainClass, subType = role.attrib['class'].strip(), role.attrib['type'].strip() if mainClass == 'OutStreams' and subType == 'Print': outStream = self.tree.find('.//OutStreams/Print[@name="'+role.text.strip()+ '"]'+'/source') if outStream is None: continue # can have an outstream in inner but still use database return dataObjectType = None linkedDataObjectPointSet = self.tree.find('.//DataObjects/PointSet[@name="'+outStream.text.strip()+ '"]') if linkedDataObjectPointSet is None: linkedDataObjectHistorySet = self.tree.find('.//DataObjects/HistorySet[@name="'+outStream.text.strip()+ '"]') if linkedDataObjectHistorySet is None: # try dataset linkedDataObjectHistorySet = self.tree.find('.//DataObjects/DataSet[@name="'+outStream.text.strip()+ '"]') if linkedDataObjectHistorySet is None: raise IOError(self.printTag+' ERROR: The OutStream of type "Print" named "'+role.text.strip()+'" is linked to not existing DataObject!') dataObjectType, xmlNode = "HistorySet", linkedDataObjectHistorySet else: dataObjectType, xmlNode = "PointSet", linkedDataObjectPointSet self.outStreamsNames[role.text.strip()] = [outStream.text.strip(),dataObjectType,xmlNode] foundOutStreams = True elif mainClass == 'Databases' and subType == 'NetCDF': rName = role.text.strip() db = self.tree.find(f'.//Databases/NetCDF[@name="{rName}"]') if db is None: continue # can have a database in inner but still use outsream return if db.attrib['readMode'] == 'overwrite': dirs = db.attrib.get('directory', 'DatabaseStorage') name = db.attrib.get('filename', db.attrib['name']+'.nc') full = os.path.join(dirs, name) self.databases[rName] = full foundDatabases = True if not foundOutStreams and not foundDatabases: raise IOError(self.printTag+' ERROR: No <OutStreams><Print> or <Databases><NetCDF readMode="overwrite"> found in the active <Steps> of inner RAVEN!') # Now we grep the paths of all the inputs the SLAVE RAVEN contains in the workind directory. self.workingDir = self.tree.find('.//RunInfo/WorkingDir').text.strip() # Find the Files self.slaveInputFiles = self.findSlaveFiles(self.tree, self.workingDir)