diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2012-04-13 21:07:42 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2012-04-13 21:07:42 +0200 |
commit | a62cb4e37d008d47480cdd6c25d928044b8afe31 (patch) | |
tree | f16e0109caf00d8989d56e2e5392851117db8814 | |
download | pyevenja-a62cb4e37d008d47480cdd6c25d928044b8afe31.zip pyevenja-a62cb4e37d008d47480cdd6c25d928044b8afe31.tar.gz |
initial commit, old code from ~2007
-rw-r--r-- | OSconfig.py | 25 | ||||
-rw-r--r-- | OSlinux.py | 31 | ||||
-rw-r--r-- | README | 6 | ||||
-rw-r--r-- | evenjastrings.py | 157 | ||||
-rw-r--r-- | fconfig.py | 586 | ||||
-rw-r--r-- | fdoor_cout.py | 42 | ||||
-rw-r--r-- | fdoor_file.py | 89 | ||||
-rw-r--r-- | fevenboard.py | 84 | ||||
-rw-r--r-- | fevendata.py | 642 | ||||
-rw-r--r-- | fevendoor.py | 122 | ||||
-rw-r--r-- | fevenprg.py | 73 | ||||
-rw-r--r-- | flist.py | 146 | ||||
-rw-r--r-- | flisthash.py | 133 | ||||
-rw-r--r-- | fport.py | 153 | ||||
-rw-r--r-- | fportbkpevendata.py | 66 | ||||
-rw-r--r-- | fportlist.py | 47 | ||||
-rw-r--r-- | fportlisthash.py | 57 | ||||
-rw-r--r-- | fposition.py | 251 | ||||
-rw-r--r-- | fprg_concat.py | 53 | ||||
-rw-r--r-- | frouter.py | 242 | ||||
-rw-r--r-- | fstarter.py | 138 | ||||
-rw-r--r-- | fstringhash.py | 156 | ||||
-rw-r--r-- | fviewer.py | 51 | ||||
-rw-r--r-- | globalvars.py | 134 | ||||
-rwxr-xr-x | launch_evenja | 6 | ||||
-rw-r--r-- | pyevenja.py | 137 | ||||
-rw-r--r-- | returncodes.py | 58 |
27 files changed, 3685 insertions, 0 deletions
diff --git a/OSconfig.py b/OSconfig.py new file mode 100644 index 0000000..f1d08fb --- /dev/null +++ b/OSconfig.py @@ -0,0 +1,25 @@ +#/*************************************************************************** +# OSconfig.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +"""only the Linux version available""" + +from OSlinux import * + diff --git a/OSlinux.py b/OSlinux.py new file mode 100644 index 0000000..0a7ce9a --- /dev/null +++ b/OSlinux.py @@ -0,0 +1,31 @@ +#/*************************************************************************** +# OSlinux.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +""" OS specifications """ + +__all__ = ["MAX_TREELEVEL","START_ELEMENTS","INC_ELEMENTS"] + + +MAX_TREELEVEL = 8 # not used yet + +# only used in flisthash.py tests +START_ELEMENTS = 100 #/* Start with a list of 100 elements */ +INC_ELEMENTS = 50 #/* If list is full increment the size of 50 elements */ @@ -0,0 +1,6 @@ +this is a translation from C++ to python, with some small changes an optimisations. + +the coding style isn't pure python. + +Zurcher Jeremy <jeremy@asynk.ch> + diff --git a/evenjastrings.py b/evenjastrings.py new file mode 100644 index 0000000..ef10bc6 --- /dev/null +++ b/evenjastrings.py @@ -0,0 +1,157 @@ +#/*************************************************************************** +# evenjastrings.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +"""strings of the evenja kernel""" + +#/** xml strings (names of xml tags) for config files*/ +XML_XML = "XML" #/** XML tag to define XML definition */ + +#/** Tags for the first level of the XML config tree */ +XML_SERVER = "evenja_server" #/** XML tag to define if the software is a server (wait until an end signal) */ +XML_ROOM = "evenja_room" #/** XML tag to define a room */ +XML_DOOR = "evenja_door" #/** XML tag to define a door */ +XML_BOARD = "evenja_board" #/** XML tag to define a board */ +XML_PRG = "evenja_prg" #/** XML tag to define a prg */ +XML_INIT = "evenja_init" #/** XML tag to start a evenPrg that initialise something + # for some enduser functionnalities */ +#/** Tags for the second level of the XML config tree */ +XML_NAME = "evenja_name" #/** XML tag containing the Name of a room, door, board and prg */ +XML_DOC = "evenja_doc" #/** XML tag to contain documentation about room, door, board and prg */ +XML_CLASS = "evenja_class" #/** XML tag to have the name of the class */ +XML_CONF = "evenja_conf" #/** XML tag to have the name of the physical configuration file (ex: "hello.xml" */ +XML_LIB = "evenja_lib" #/** XML tag to have the name of the physical library (ex: "hello.so" or "hello.dll") */ +XML_DEBUG = "evenja_debug" #/** XML tag to enable the viewer to be connected to the port */ +XML_LNK = "evenja_link" #/** XML tag Parameters to link an evenData to port */ + +#/** Tags for the third level of the XML config tree */ +XML_LNKSOURCE = "evenja_linksource" #/** XML tag Source of the evenDtata to link with ??? */ +XML_LNKTYPE = "evenja_linktype" #/** XML tag Name of the fields that determine the type */ +XML_LNKVALUE = "evenja_linkvalue" #/** XML tag Value corresponding to the type */ +XML_LNKFIELDS = "evenja_linkfields" #/** XML tag to contain the list of the fields names to make the right link */ +XML_LNKDEST = "evenja_linkdest" #/** XML tag Destination of the evenData after link checked ok */ + +#/** xml strings ( names of xml tags) for evendatas files */ +XML_DATAS = "evendata_datas" #/** XML tag to define a datas */ +XML_SOURCE = "evendata_source" #/** Source of the data */ +XML_STARTTIME = "evendata_starttime" #/** Time when the data as start */ +XML_DESTINATION = "evendata_destination" #/** List of all destinations */ +XML_DESTCOUNT = "evendata_destcount" #/** Number of destinations */ +XML_CURRENTDEST = "evendata_currentdest" #/** Actual destination number */ +XML_DESTNUMBER = "evendata_dest%d" #/** Destination number (completed by software */ +XML_LINKFIELDS = "evendata_linkfields" #/** List of all fields to do the right link */ + +#// ------------------------------------------------------------------------- +#// ------------------------------------------------------------------------- +#// ACTIONS strings +#// --------------- + +#// ------------------------------------------------------------------------- +#/** evenja SYSTEM ACTIONS +# evenDoor, evenBoard and evenPrg actions */ +ACT_SYS_START = "SYS_START" #/** Start a port, after creation */ +ACT_SYS_UPDATE = "SYS_UPDATE" #/** Update a port */ +ACT_SYS_END = "SYS_END" #/** End a port, before deletion */ +ACT_SYS_STOP = "SYS_STOP" #/** Stop the work inside the port */ +ACT_SYS_CONTINUE = "SYS_CONTINUE" #/** Continue the work inside the port (after a stop) */ +ACT_SYS_ADDDEST = "SYS_ADDDEST" #/** Add a special destination to an evenDoor */ +ACT_SYS_REMDEST = "SYS_REMDEST" #/** Remove a special destination to an evenDoor */ +ACT_SYS_TESTMODE = "SYS_TESTMODE" #/** Enable the check of a port with the configuration of them, at runtime */ + +#// ------------------------------------------------------------------------- +#/** SOFTWARE ACTIONS. +# Standard actions implemented in the evenja kernel. +# Actions for evenPorts */ +ACT_NORMAL = "normal" #/** No specific action, each Fport have is own "normal" action */ + + +# /** Action for evenBoard */ + +#/** no special action, no link with another evenData (with the linkValue). Used in the evenPrg. */ +ACT_DESTINATION1DATA = "destination1Data" + +#/** it waits until another evenData arrives in the same evenBoard (with the same linkValue) and +#follows the Destination of them. */ +ACT_DESTINATION2DATA = "destination2Data" + +#/** if another evenData with the same linkValue is waiting in the evenBoard, then follows the destination of that evenData. +#If no evenData with the same linkValue isn't waiting, then it wait inside the evenBoard for another evenData. */ +ACT_FOLLOWDESTINATION = "followDestination" + +#/** it works like "destination2Data" if another evenData with the same linkValue is already inside the evenBoard. +#If no evenData with the same linkValue is inside the evenBoard, +#then it waits a time defined after the Action (ex: wait,100s). */ +ACT_WAIT = "wait" + + +#/** Actions for evenDoor */ + +#/** Add the evenData to Fport ( ex.: if it is an evenDoor of a DB then Add the datas to the Database) */ +ACT_ADD = "add" + +#/** Update the evenData to Fport ( ex.: if it is an evenDoor of a DB then Update the record of the Database) */ +ACT_UPDATE = "update" + +#/** Delete the evenData to Fport ( ex.: if it is an evenDoor of a DB then Delete the record of the Database) */ +ACT_DELETE = "delete" + +#/** Get an evenData from a Port ( ex.: if is is an evenDoor of a file, get the next line) */ +ACT_GET = "get" + +#/** Find the evenData to Fport (ex.: if it is a evenDoor of a DB then Find the record of the Database) */ +ACT_FIND = "find" + +#/** special Action for some evenDoors that will receive informations in the evenData. +#The evenDoor does the request corresponding to this information and sends the evenData to the next point of the list +#of destinations. Ex. : evenDoor does a" SELECT" in a SQL database and puts the result inside the evenData. */ +ACT_CALLBACK = "callback" + +#/** The evenData goes to a list of freeEvenDatas inside the nearest router, to be used as soon as possible */ +ACT_END = "end" + +#/** The evenData goes to a specific evenPort where all errors are sents. Like a log, but it can be each evenPort inherited. */ +ACT_ERROR = "error" + +#/** Format of the wait time when ACT_WAIT is used */ +ACT_WAIT_NOTHING = ' ' #/** In fact, don't wait */ +ACT_WAIT_YEAR = 'y' +ACT_WAIT_MONTH = 'n' +ACT_WAIT_DAY = 'd' +ACT_WAIT_HOUR = 'h' +ACT_WAIT_MINUTE = 'm' +ACT_WAIT_SECOND = 's' +ACT_WAIT_MILLISEC = 'x' + +#// ------------------------------------------------------------------------- +#/** Internal Names +# Just for fun and coherence */ +XML_VERSION = "1.0" #/** Version of XML (compatible) */ +TXT_NEW = "NEW" #/** Name of a new tree */ +TXT_NULL = "" #/** Null string */ +FIELD_SEPARATOR = ',' #/** Separator of fields */ +FIELD_SEPARATOR_STR = "," #/** Separator of fields */ +TREE_SEPARATOR = '/' #/** Separator of the XML TREE TAG NAME */ +TREE_SEPARATOR_STR = "/" #/** Separator of the XML TREE TAG NAME */ +DESTINATION_SEPARATOR = ';' #/** Separator of destination */ +DESTINATION_SEPARATOR_STR = ";" #/** Separator of destination */ +TXT_NOVALUES = "NOVALUES" #/** Value that tke an evenData when no values are alreadyin the data tree */ + +#// ------------------------------------------------------------------------- + diff --git a/fconfig.py b/fconfig.py new file mode 100644 index 0000000..d3c3e50 --- /dev/null +++ b/fconfig.py @@ -0,0 +1,586 @@ +#/*************************************************************************** +# fconfig.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + + +"""/** Class done to open or load and close or save the config in tree files + (XML now, but nobody what's would be in the future, ex: LDAP). + function : It is the access to a tree of information needed by the class which inheritate from Fconfig. + This class can be modified if the datas are stored in another system than a file. + The file can be a stream or every other input stream data (better in a tree like XML or LDAP). + + description : + - Methods start and startNew will connect Fconfig to a tree (XML in this example, but can be a + LDAP or other tree style). + - Method end will enable to save the tree (not always needed). + - Method resetCurrent will reset the current pointer to the node when last method start as been called. + - Methods gotoNext, gotoPrev, gotoChildren, gotoParent enable to move inside the tree. + - Methods Find and FindNext enable to search by name an tree Node. + + Fconfig is a generic caller for a tree access. This enable to change the type of supported tree XML, + LDAP or others, without having to update the evenja kernel. + + *@author Fabian Padilla + */""" + +__all__ = ["Fconfig"] + +try: + import libxml2 +except: + print "libxml2 not available ... aborting !!" + import sys + sys.exit(1) + +from flist import Flist +from fstringhash import FstringHash +import returncodes as RC +import evenjastrings as ES + +class Fconfig(FstringHash): + """ This class gives you the ability to walk around and through an XML document. + This document can be created from sratch, read from a file, completed and modified, and so on. + You can also execute some research queries... Everything seems to be safe /~\/~\.""" + + def __init__(self): + FstringHash.__init__(self) # force contrustor + self.fileName = None # yeah, this is it ! + self.doc = None # the document + self.root = None # the root node + self.firstCurrent = None # the first node of the tree + self.current = None # the current node + self.stackCurrent = Flist() # a stack used to push and pop self.current + + def __str__(self): + return "\t"+FstringHash.__str__(self) +\ + " Fconfig - File : "+str(self.fileName)+\ + " - Current_Name : "+str(self.getName())+\ + " - Current_Content : "+str(self.getContent())+"\n" + + def startXml(self, param): + """/** Read an XML tree, param may be a file name or an xmlNode. */""" + if isinstance(param,str): + # a filename is given, parse this file + self.fileName = param + try: + self.doc = libxml2.parseFile(param) + except: + return RC.RET_CANNOTACCESS + param = self.doc.children + # a node is given or we have one now + if not isinstance(param,libxml2.xmlNode): + return RC.RET_CANNOTACCESS + self.root = param.doc.children + self.firstCurrent = param + self.current = param + if self.gotoChildren() != RC.RET_OK: + return RC.RET_NOTEXIST + # find <evenja_name> tag and put it's content in our FstringHash + if self.Find(ES.XML_NAME, False) != RC.RET_OK: + return RC.RET_NONAME + string = self.getContent() + if string == RC.RET_NONODESELECTED: # don't need this ... + return RC.RET_NONAME + self.setString(string) + self.resetCurrent() + return RC.RET_OK + + def startNewXml(self, fileName = None): + """/** Create a new XML tree. */""" + if fileName: + self.fileName = fileName + else: + self.fileName = None + try: + self.doc = libxml2.newDoc(ES.XML_VERSION) + self.doc.newChild(None, ES.XML_XML, None) + except: + return RC.RET_CANNOTCREATE + self.root = self.doc.children + self.firstCurrent = self.root + self.current = self.root + self.setString(ES.TXT_NEW) + return RC.RET_OK + + def endXml(self): + """/** Close the XML tree. Save it if a file name exists. */""" + if self.doc and self.fileName: + if self.doc.saveFile(self.fileName) == -1: + return RC.RET_CANNOTEND + if self.doc: + self.doc.freeDoc() + self.doc = None + self.root = None + self.firstCurrent = None + self.current = None + self.fileName = None + return RC.RET_OK + + def getCurrent(self): + """/** Get the current node. */""" + return self.current + +# WALKING METHODS + + def resetCurrent(self, fromRoot = False): + """/** Set current node to the root one if fromRoot, otherwise to the first one. */""" + if fromRoot: + self.current = self.root + else: + self.current = self.firstCurrent + + def gotoFirst(self): + """/** Go to the first node of the current branch. */""" + if not self.current: + return RC.RET_NONODESELECTED + self.current = self.current.parent.children + if self.current.type != "element": + return self.gotoNext() + return RC.RET_OK + + def gotoLast(self): + """/** Go to the last node of the current branch. */""" + if not self.current: + return RC.RET_NONODESELECTED + self.current = self.current.parent.last + if self.current.type != "element": + return self.gotoPrev() + return RC.RET_OK + + def gotoNext(self): + """/** Go to the next node of the current branch. */""" + if not self.current: + return RC.RET_NONODESELECTED + if not self.current.next: + return RC.RET_NOTEXIST + node = self.current.next + while node.type != "element" and node.next: # walk 'till you find + node = node.next + if node.type == "element": + self.current = node + return RC.RET_OK + return RC.RET_NOTEXIST + + def gotoPrev(self): + """/** Go to the previous node of the current branch. */""" + if not self.current: + return RC.RET_NONODESELECTED + if not self.current.prev: + return RC.RET_NOTEXIST + node = self.current.prev + while node.type != "element" and node.prev: # walk 'till you find + node = node.prev + if node.type == "element": + self.current = node + return RC.RET_OK + return RC.RET_NOTEXIST + + def gotoChildren(self): + """/** Go to the children node of the current node. */""" + if not self.current: + return RC.RET_NONODESELECTED + if not self.current.children: + return RC.RET_NOTEXIST + tmp = self.current + self.current = self.current.children + if self.current.type == "element": + return RC.RET_OK + ret = self.gotoNext() + if ret == RC.RET_NOTEXIST: + self.current = tmp + return ret + + def gotoParent(self): + """/** Go to the parent node of the current node. */""" + if not self.current: + return RC.RET_NONODESELECTED + if not self.current.parent: + return RC.RET_NOTEXIST + tmp = self.current + self.current = self.current.parent + if self.current.type == "element": + return RC.RET_OK + ret = self.gotoPrev() + if ret == RC.RET_NOTEXIST: + self.current = tmp + return ret + + def Search(self, name, subTree = True): + """/** Find a name, with or without tree recusivity, using preorder path. + self.current is saved from not_found case */""" + if not self.current: + return RC.RET_NONODESELECTED + bkp = self.current # save self.current + while True: + if self.getName() == name: + return RC.RET_OK + if subTree and self.current.children: # maybe deeper ?? + if self.gotoChildren() == RC.RET_OK: + if self.Search(name,subTree) == RC.RET_OK: + return RC.RET_OK + else: + self.gotoParent() + if RC.RET_OK !=self.gotoNext(): # maybe further ?? + self.current = bkp # recover self.current + return RC.RET_NOTFOUND + + def Find(self, name, subTree = True): + """/** Find a name from th etop of the tree, with or without tree recusivity. */""" + ret = self.gotoFirst() + if ret != RC.RET_OK: + return ret + return self.Search(name,subTree) + + def FindNext(self, name, subTree = True): + """/** Find next name, with or without tree recusivity. */""" + ret = self.gotoNext() + if ret != RC.RET_OK: + return ret + return self.Search(name,subTree) + + +# RETRIEVE INFORMATIONS + + def getName(self): + """/** Get the Name of the current Node. */""" + if self.current: + return self.current.name + return RC.RET_NONODESELECTED + + def setName(self, name): + """/** Set the Name of the current Node. */""" + if not self.current: + return RC.RET_NONODESELECTED + self.current.setName(name) + return RC.RET_OK + + def getContent(self): + """/** Get the Content of the current Node. */""" + if not self.current: + return RC.RET_NONODESELECTED + currentA = self.current.children + if currentA: + return currentA.content + return ES.TXT_NULL + + def setContent(self, content): + """/** Set the Content of the current Node. */""" + if not self.current: + return RC.RET_NONODESELECTED + if content <> None: + self.current.setContent(content) + else: + self.current.setContent(ES.TXT_NULL) + return RC.RET_OK + +# CREATE ADN DELETE NODES + + def addChildren(self, name, content = None): + """/** Create a new node (the current node is the parent). */""" + if not self.current: + return RC.RET_NONODESELECTED + self.current.newChild(None,name,content) + if self.doc and not self.root: + self.root = self.doc.children + self.firstCurrent = self.root + self.current = self.root + return RC.RET_OK + + def removeCurrent(self): + """/** Remove the current node (recursively). + After remove operation, goto the previous node if exists or to the next, or the parent*/""" + str = self.getName() + if str == RC.RET_NONODESELECTED or str is None: + return RC.RET_NONODESELECTED + if str.upper() == ES.XML_XML.upper(): # TzurTcH - case insensitive should be ok + return RC.RET_OK + toRemove = self.current + if self.current.prev: + self.gotoPrev() + elif self.current.next: + self.gotoNext() + elif self.current.parent: + self.gotoParent() + # maybe it will empty this tree ... + if self.root == toRemove or self.firstCurrent == toRemove or self.root.doc.children == toRemove: + self.root = None + self.firstCurrent = None + self.current = None + toRemove.unlinkNode() + toRemove.freeNode() + return RC.RET_OK + +# STACK MEMORY CAPABILITIES + + def pushCurrent(self): + """/** Push the Current position to the stack. */""" + self.stackCurrent.add(self.current) + + def popCurrent(self): + """/** Pop the Current position from the stack. */""" + if self.stackCurrent.getCount(): + self.current = self.stackCurrent.removeStack() + +if __name__ == '__main__': + + import unittest + from evenjastrings import * + + conf = Fconfig() + + class FconfigTestCase(unittest.TestCase): + + def test1FileName(self): + self.assertEquals(conf.startXml( "testezlog.xml"),RC.RET_OK) + self.assertEquals(conf.endXml(),RC.RET_OK) + + def test2NewTree(self): + self.assertEquals(conf.startNewXml(),RC.RET_OK) + self.assertEquals(conf.endXml(),RC.RET_OK) + self.assertEquals(conf.startNewXml( "testezlog_addnode.xml"),RC.RET_OK) + self.assertEquals(conf.endXml(),RC.RET_OK) + + def test3StartNode(self): + self.assertEquals(conf.startXml( "testezlog.xml"),RC.RET_OK) + conf1 = Fconfig() + conf1.startXml( conf.getCurrent()) + conf1.gotoChildren() + self.assertEquals(ES.XML_NAME.upper(),conf1.getName().upper()) + conf1.endXml() + self.assertEquals(conf.endXml(),RC.RET_OK) + + def test4Node(self): + self.assertEquals(conf.startXml( "testezlog.xml"),RC.RET_OK) + conf.gotoChildren() + self.assertEquals(ES.XML_NAME, conf.getName()) + self.assertEquals("TEST00", conf.getContent()) + conf.gotoNext() + self.assertEquals(ES.XML_ROOM, conf.getName()) + conf.gotoChildren() + self.assertEquals(ES.XML_NAME, conf.getName()) + self.assertEquals("Room1", conf.getContent()) + conf.gotoNext() + self.assertEquals(ES.XML_DOC, conf.getName()) + self.assertEquals("FirstRoom", conf.getContent()) + conf.gotoNext() + conf.gotoPrev() + self.assertEquals(ES.XML_DOC, conf.getName()) + self.assertEquals("FirstRoom", conf.getContent()) + conf.gotoPrev() + conf.gotoNext() + self.assertEquals(ES.XML_DOC, conf.getName()) + self.assertEquals("FirstRoom", conf.getContent()) + self.assertEquals(conf.endXml(),RC.RET_OK) + + def test5ParentChildren(self): + self.assertEquals(conf.startXml( "testezlog.xml"),RC.RET_OK) + self.assertEquals(ES.XML_XML.upper(), conf.getName().upper()) + self.assertEquals(conf.gotoChildren(),RC.RET_OK) + + self.assertEquals(ES.XML_NAME, conf.getName()) + self.assertEquals("TEST00", conf.getContent()) + self.assertEquals(conf.gotoChildren(),RC.RET_NOTEXIST) + self.assertEquals(ES.XML_NAME, conf.getName()) + self.assertEquals("TEST00", conf.getContent()) + + self.assertEquals(conf.gotoParent(),RC.RET_OK) + self.assertEquals(ES.XML_XML.upper(), conf.getName().upper()) + self.assertEquals(conf.gotoParent(),RC.RET_NOTEXIST) + + conf.resetCurrent() + self.assertEquals(conf.gotoChildren(),RC.RET_OK) + self.assertEquals(ES.XML_NAME, conf.getName()) + self.assertEquals(conf.endXml(),RC.RET_OK) + + def test6FirstLast(self): + self.assertEquals(conf.startXml( "testezlog.xml"),RC.RET_OK) + conf.gotoChildren() + conf.gotoNext() + conf.gotoChildren() + conf.gotoLast() + self.assertEquals(ES.XML_CONF, conf.getName()) + self.assertEquals(conf.gotoNext(),RC.RET_NOTEXIST) + conf.gotoFirst() + self.assertEquals(ES.XML_NAME, conf.getName()) + self.assertEquals(conf.gotoPrev(),RC.RET_NOTEXIST) + conf.gotoNext() + self.assertEquals(ES.XML_DOC, conf.getName()) + self.assertEquals(conf.endXml(),RC.RET_OK) + + def test7Find(self): + self.assertEquals(conf.startXml( "testezlog.xml"),RC.RET_OK) + if conf.Find(ES.XML_NAME): + self.assertEquals(ES.XML_NAME, conf.getName()) + self.assertEquals("Room1", conf.getContent()) + conf.pushCurrent() + conf.FindNext(ES.XML_DOC) + self.assertEquals(ES.XML_DOC, conf.getName()) + self.assertEquals("FirstRoom", conf.getContent()) + conf.popCurrent() + conf.FindNext(ES.XML_DOC, false) + self.assertEquals(conf.Find(ES.TXT_NULL),RC.RET_NOTFOUND) + self.assertEquals(conf.endXml(),RC.RET_OK) + + def test8NewNode(self): + self.assertEquals(conf.startNewXml( "testezlog_addnode.xml"),RC.RET_OK) + conf.addChildren( ES.XML_NAME, "Room1") + conf.addChildren( ES.XML_DOC, "FirstRoom") + conf.addChildren( ES.XML_CONF, "REMOVETEST") + + conf.gotoChildren() + conf.gotoLast() + self.assertEquals(ES.XML_CONF, conf.getName()) + conf.removeCurrent() + self.assertEquals(ES.XML_DOC, conf.getName()) + self.assertEquals("FirstRoom", conf.getContent()) + + conf.gotoParent() # XML + self.assertEquals(ES.XML_XML, conf.getName()) + conf.addChildren(ES.XML_CONF, "REMOVETEST") + conf.gotoChildren() + conf.gotoLast() + conf.gotoPrev() + self.assertEquals(ES.XML_DOC, conf.getName()) + self.assertEquals("FirstRoom", conf.getContent()) + conf.removeCurrent() + self.assertEquals(ES.XML_NAME, conf.getName()) + self.assertEquals("Room1", conf.getContent()) + + conf.gotoParent() + conf.addChildren(ES.XML_DOC, "FirstRoom") + conf.gotoChildren() + conf.removeCurrent() + self.assertEquals(ES.XML_CONF, conf.getName()) + self.assertEquals("REMOVETEST", conf.getContent()) + + self.assertEquals(conf.endXml(),RC.RET_OK) + + def testBigBuild(self): + """TzurTcH's test suite""" + self.assertEquals(conf.startNewXml( "DEEP.xml"),RC.RET_OK) + self.assertEquals(conf.getName(),XML_XML) + self.assertEquals(conf.addChildren( ES.XML_NAME, "Room1"),RC.RET_OK) + self.assertEquals(conf.addChildren( ES.XML_NAME, "Room2"),RC.RET_OK) + self.assertEquals(conf.addChildren( ES.XML_NAME, "Room3"),RC.RET_OK) + self.assertEquals(conf.addChildren( ES.XML_NAME, "Room4"),RC.RET_OK) + self.assertEquals(conf.addChildren( ES.XML_NAME, "Room5"),RC.RET_OK) + self.assertEquals(conf.gotoChildren(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room1") + + self.assertEquals(conf.gotoLast(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room5") + self.assertEquals(conf.gotoLast(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room5") + + self.assertEquals(conf.addChildren( ES.XML_DOC, "child_of_5"),RC.RET_OK) + self.assertEquals(conf.gotoNext(),RC.RET_NOTEXIST) + self.assertEquals(conf.getContent(),"Room5") + + self.assertEquals(conf.addChildren( ES.XML_DOC, "child_of_5_two"),RC.RET_OK) + self.assertEquals(conf.addChildren( ES.XML_DOC, "child_of_5_three"),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room5") + + self.assertEquals(conf.gotoFirst(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room1") + self.assertEquals(conf.gotoFirst(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room1") + self.assertEquals(conf.addChildren( ES.XML_DOC, "child_of_1"),RC.RET_OK) + self.assertEquals(conf.gotoPrev(),RC.RET_NOTEXIST) + self.assertEquals(conf.getContent(),"Room1") + + self.assertEquals(conf.addChildren( ES.XML_DOC, "child_of_1_two"),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room1") + self.assertEquals(conf.addChildren( ES.XML_DOC, "child_of_1_three"),RC.RET_OK) + + self.assertEquals(conf.gotoNext(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room2") + self.assertEquals(conf.gotoNext(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room3") + self.assertEquals(conf.gotoNext(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room4") + self.assertEquals(conf.addChildren( ES.XML_DOC, "child_of_4"),RC.RET_OK) + self.assertEquals(conf.gotoPrev(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room3") + self.assertEquals(conf.gotoPrev(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room2") + self.assertEquals(conf.addChildren( ES.XML_DOC, "child_of_2"),RC.RET_OK) + self.assertEquals(conf.gotoNext(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room3") + + self.assertEquals(conf.addChildren( ES.XML_DOC, "child_of_3"),RC.RET_OK) + self.assertEquals(conf.addChildren( "SEARCH", "child_of_3_two"),RC.RET_OK) + + conf.pushCurrent() + self.assertEquals(conf.getContent(),"Room3") + conf.resetCurrent(False) + self.assertEquals(conf.getName(),XML_XML) + self.assertEquals(conf.Find("SEARCH"),RC.RET_OK) + conf.popCurrent() + + self.assertEquals(conf.addChildren( ES.XML_DOC, "child_of_3_three"),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room3") + self.assertEquals(conf.gotoChildren(),RC.RET_OK) + self.assertEquals(conf.getContent(),"child_of_3") + self.assertEquals(conf.gotoLast(),RC.RET_OK) + self.assertEquals(conf.getContent(),"child_of_3_three") + self.assertEquals(conf.gotoChildren(),RC.RET_NOTEXIST) + self.assertEquals(conf.getContent(),"child_of_3_three") + + self.assertEquals(conf.gotoParent(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room3") + self.assertEquals(conf.gotoParent(),RC.RET_OK) + self.assertEquals(conf.gotoChildren(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room1") + + self.assertEquals(conf.gotoParent(),RC.RET_OK) + self.assertEquals(conf.getName(),ES.XML_XML) + self.assertEquals(conf.gotoParent(),RC.RET_NOTEXIST) + self.assertEquals(conf.gotoParent(),RC.RET_NOTEXIST) + self.assertEquals(conf.getName(),ES.XML_XML) + self.assertEquals(conf.removeCurrent(),RC.RET_OK) + + self.assertEquals(conf.gotoChildren(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room1") + self.assertEquals(conf.gotoChildren(),RC.RET_OK) + self.assertEquals(conf.getContent(),"child_of_1") + self.assertEquals(conf.gotoParent(),RC.RET_OK) + self.assertEquals(conf.removeCurrent(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room2") + self.assertEquals(conf.Find("NOTHING"),RC.RET_NOTFOUND) + self.assertEquals(conf.getContent(),"Room2") + self.assertEquals(conf.FindNext("NOTHING"),RC.RET_NOTFOUND) + self.assertEquals(conf.getContent(),"Room3") + + self.assertEquals(conf.gotoPrev(),RC.RET_OK) + self.assertEquals(conf.FindNext("SEARCH"),RC.RET_OK) + self.assertEquals(conf.getContent(),"child_of_3_two") + self.assertEquals(conf.gotoParent(),RC.RET_OK) + self.assertEquals(conf.FindNext("SEARCH"),RC.RET_NOTFOUND) + self.assertEquals(conf.getContent(),"Room4") + self.assertEquals(conf.getName(),ES.XML_NAME) + self.assertEquals(conf.gotoNext(),RC.RET_OK) + self.assertEquals(conf.getContent(),"Room5") + + self.assertEquals(conf.gotoParent(),RC.RET_OK) + self.assertEquals(conf.getName(),XML_XML) + self.assertEquals(conf.endXml(),RC.RET_OK) + + + unittest.main() diff --git a/fdoor_cout.py b/fdoor_cout.py new file mode 100644 index 0000000..322596b --- /dev/null +++ b/fdoor_cout.py @@ -0,0 +1,42 @@ +#/*************************************************************************** +# fdoor_cout.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +""" doc """ + +__all__ = ["Fdoor_cout"] + + +from fevendoor import FevenDoor +from returncodes import RET_OK +from sys import stdout + +class Fdoor_cout(FevenDoor): + + def __init__(self): + FevenDoor.__init__(self) # force constructor + + def __str__(self): + return "\t"+FevenDoor.__str__(self)+\ + "Fdoor_cout - (null)\n" + + def receive_evenData(self,evenData): + stdout.write("%s"%evenData.getData("TXT")) + return RET_OK diff --git a/fdoor_file.py b/fdoor_file.py new file mode 100644 index 0000000..d2819b6 --- /dev/null +++ b/fdoor_file.py @@ -0,0 +1,89 @@ +#/*************************************************************************** +# fdoor_file.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +""" doc """ + +__all__ = ["Fdoor_file"] + +from fport import Fport +from fevendoor import FevenDoor + +from globalvars import gvActionGet + +from evenjastrings import ACT_GET +from returncodes import RET_OK +from returncodes import RET_CANNOTACCESS +from returncodes import RET_CANNOTSAVE + +class Fdoor_file(FevenDoor): + + def __init__(self): + FevenDoor.__init__(self) # force constructor + self.file = None + + def __str__(self): + return "\t"+FevenDoor.__str__(self)+\ + "Fdoor_file - file : "+str(self.file)+"\n" + + def start(self,port,node): + ret = Fport.start(self,port,node) + if ret == RET_OK: + self.gotoChildren() + if self.Find("filename",False) == RET_OK: + str = self.getContent() + try: + self.file = file(str,"rw") + except: + return RET_CANNOTACCESS + self.filename = str + if file <> None: + data = self.getFreeEvenData() + data.definePortAction(ACT_GET,self.getString()) + self.sendEvenData(data) + else: + return RET_CANNOTACCESS + return ret + + def receive_evenData(self,evenData): + if evenData.getCurrentDestination().getAction().equals(gvActionGet): + line = self.file.readline() + if line: + # send line + evenData.reset() + evenData.setData("filename",self.filename) + evenData.setData("TXT",line) + self.sendEvenData(evenData) + + # say "I got more" + data = self.getFreeEvenData() + data.definePortAction(ACT_GET, self.getString()) + self.sendEvenData(data) + return RET_OK + + + def end(self): + ret = Fport.end(self) + if ret == RET_OK and self.file <> None: + try: + self.file.close() + except: + return RET_CANNOTSAVE + return ret diff --git a/fevenboard.py b/fevenboard.py new file mode 100644 index 0000000..6aecee2 --- /dev/null +++ b/fevenboard.py @@ -0,0 +1,84 @@ +#/*************************************************************************** +# fevenboard.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ +# /*************************************************************************** +# +# fevenboard.py +# ------------------- +# begin : wed mar 10 2004 +# copyright : (C) 2004 by Jeremy Zurcher +# email : tzurtch@bluemail.ch +# +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +"""/** evenData will wait for another evenData in this evenBoard. + + function : merge informations having the same linkValue. + + description : receive an evenData and check if another evenData with the same linkValue + is already in the list. Then Apply the ACTION to marge them together + and send to somewhere. + + *@author Fabian Padilla + */""" + +__all__ = ["FevenBoard"] + +from fportlisthash import FportListHash + +from returncodes import RET_OK +from evenjastrings import ACT_ERROR + +from globalvars import gvActionWait +from globalvars import gvActionDestination1Data +from globalvars import gvActionFollowDestination + +class FevenBoard(FportListHash): + + def __init__(self): + FportListHash.__init__(self) # force contrustor + + def __str__(self): + return "\t"+FportListHash.__str__(self)+\ + "FevenBoard - (null)\n" + + def receive_evenData(self,evenData): + """/** Receive the evenData and apply the action to know what to do with */""" + action = evenData.getCurrentDestination().getAction() + + if action.equals(gvActionDestination1Data): + if evenData.selectNextDestination() != RET_OK: + evenData.definePortAction(ACT_ERROR) + else: + dataPresent = self.listHash.addOrRemove(evenData) + if dataPresent <> None: + if action.equals(gvActionFollowDestination): + provData = dataPresent + dataPresent = evenData + evenData = provData + evenData.setEvenDataB(dataPresent) + if evenData.selectNextDestination() != RET_OK: + evenData.definePortAction(ACT_ERROR) + self.sendEvenData(evenData) + else: + if action.equals(gvActionWait): + print "NOT IMPLEMENTED YET" + return RET_OK + diff --git a/fevendata.py b/fevendata.py new file mode 100644 index 0000000..6cb7a05 --- /dev/null +++ b/fevendata.py @@ -0,0 +1,642 @@ +#/*************************************************************************** +# fevendata.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + + +# TODO check int() and float() cast +# TODO tmp file usage for dumping xml in memory is really ugly !!! + +"""/** Kernel of the evenja and evendoor technology => the DATA. + Data is the only that know where they want to go. They can go to an + evenDoor or evenBoard. + THIS SCENARIO OF USE IS COVERED BY THE FPL Foundaion Public Licence. + COPYRIGHT 1992-2004 Fabian Padilla. + + *@author Fabian Padilla + */""" + +__all__ = ["FevenData"] + +try: + import libxml2 +except: + print "libxml2 not available ... aborting !!" + import sys + sys.exit(1) + +from time import time + +from flist import Flist +from fconfig import Fconfig +from fposition import Fposition +from fstringhash import FstringHash + +import evenjastrings as ES +import returncodes as RC + +# TzurTcH - speed up ;)) +PREF = ES.XML_DESTINATION + ES.TREE_SEPARATOR_STR +PREF_DESTCOUNT = PREF + ES.XML_DESTCOUNT +PREF_CURRENTDEST = PREF + ES.XML_CURRENTDEST +PREF_DESTNUMBER = PREF + ES.XML_DESTNUMBER + + +class FevenData(Fconfig): + + def __init__(self): + Fconfig.__init__(self) # force constructor + self.source = Fposition() # Where the evenData as been created + self.startToUse = 0 # Date and time when this evenData as been sent from the evenDoor + self.destination = Flist() # Where the evenData want to go + self.currentDestination = 0 # this is it + self.activePort = None # The Active actual port where the data will be sent + self.linkFieldsNames = Flist() # Name of the fields that link two evenData + self.datas = None # Pointer of the start of datas + self.splitBuffer = None # Used for string splitting actions + self.xmlBuffer = None # Pointersof the xmlBuffer when methods + # setDatasFromString and getDatasFromString are called + self.evenDataB = None # When a merge is done in the evenBoards it contains the other evenData + self.initDatas() + + def __str__(self): + """you want a trace of all processed messages : print data in fstarter.execute""" + level = 0 + buff = self.getDatasToString() + ret = "" + for I in range(len(buff)): + ret += buff[I] + if buff[I] == '>': + if buff[I-1] == '?': # start + pass + elif buff[-1] == '/' or buff[I:I+3] == '></': # end of an empty attribute + ret += '\n'+level*'\t' + elif buff[I+1] != '<': # attribute + ret += '\n'+(level+1)*'\t' + else: # new level + level += 1 + ret += '\n'+level*'\t' + if buff[I] =='<': + if buff[I-1] == '\n': # start + pass + if buff[I-1] != '>' and buff[I-1] != '\n': # end of an attribute + ret = ret[:-1] + ret += '\n'+level*'\t'+'<' + if buff[I+1] == '/': # end of a level + level -=1 + return "\t"+Fconfig.__str__(self)+ret + + def __del__(self): + """/** I beleive this is for no use. */""" + self.xmlBuffer = None # should be ok like this + self.reset() + self.endXml() + + def initDatas(self): + """/** Init the Datas Structure. */""" + self.startNewXml() + self.addChildren(ES.XML_DATAS,None) + self.gotoChildren() + self.Find(ES.XML_DATAS,False) + self.datas = self.current + self.setString(ES.TXT_NOVALUES) + + def getSplitted(self,separator,string = ES.TXT_NULL): + """/** Split string using separator, returns first part, keeps the rest in splitBuffer. */""" + if string: + self.splitBuffer = string.split(separator) + if self.splitBuffer: + if len(self.splitBuffer) >=2: + ret, self.splitBuffer = self.splitBuffer[0], self.splitBuffer[1:] + else: + ret, self.splitBuffer = self.splitBuffer[0], None + return ret + return None + + def gotoTagName(self,name,create = True,onlyDatas = True): + """/** Access the right TAG name in the Tree, or create it */""" + str = self.getSplitted(ES.TREE_SEPARATOR, name) + if onlyDatas: + self.current = self.datas + else: + self.current = self.root + while str: + ret = self.gotoChildren() + if ret == RC.RET_NOTEXIST and create: # no children, but can create + self.addChildren(str,None) + self.gotoChildren() + + elif ret == RC.RET_NOTEXIST and not create: # no children and can't create, sorry + return RC.RET_NOTFOUND + + ret = self.Find(str,False) # search for str no deep search !! + if ret == RC.RET_NOTFOUND and create: # not found, but can create + self.gotoParent() + self.addChildren(str,None) + self.gotoChildren() + self.Find(str,False) # go to this new node + + elif ret == RC.RET_NOTFOUND and not create: # not found and can't create, sorry + return RC.RET_NOTFOUND + str = self.getSplitted(ES.TREE_SEPARATOR) # next... + return RC.RET_OK + + def setMetaEvenDatasToXml(self): + """/** put META evenData => Source, Destination, startTime, etc... */""" + + def SETMETADATA(A,B): + self.gotoTagName(A,True,False) + self.setContent(str(B)) + + SETMETADATA(ES.XML_SOURCE,self.source.getString()) # set source + SETMETADATA(ES.XML_STARTTIME,self.startToUse) # set startToUse + self.gotoTagName(ES.XML_DESTINATION,True,False) + SETMETADATA(PREF_DESTCOUNT,self.destination.getCount()) # nbDest + SETMETADATA(PREF_CURRENTDEST,self.currentDestination) # set currentDestination + + for I in range(self.destination.getCount()): # set destinations + SETMETADATA(PREF_DESTNUMBER%I,self.destination.get(I).getString()) + + S = "" + for I in range(self.linkFieldsNames.getCount()): # set linkFieldsNames + S += self.linkFieldsNames.get(I).getString() + ES.FIELD_SEPARATOR_STR + if S: + S = S[:-1] + SETMETADATA(ES.XML_LINKFIELDS,S) + + def getMetaEvenDatasFromXml(self): + """/** get META evenData => Source, Destination, startTime, etc... */""" + nbDest = 0 + + def GETMETADATA(A,B=None): + ret = self.gotoTagName(A,False,False) + if ret == RC.RET_OK: + if B: + B(self.getContent()) + else: + return self.getContent() + else: # TzurTcH - I hope never beeing there + from sys import exit + from sys import stderr + stderr.write("ERRRROOORRRR\n") + exit(1) + + GETMETADATA(ES.XML_SOURCE,self.setSource) # get source + self.startToUse = float(GETMETADATA(ES.XML_STARTTIME)) # get startToUse + nbDest = int(GETMETADATA(PREF_DESTCOUNT)) # get nbDest + self.currentDestination = int(GETMETADATA(PREF_CURRENTDEST)) # get currentDestination + + for I in range(nbDest): + GETMETADATA(PREF_DESTNUMBER%I,self.addDestination) # get destinations + GETMETADATA(ES.XML_LINKFIELDS,self.setLinkFieldsNames) # get linkFieldsNames + + def setDatasFromXXX(self,newDoc): + """/** end the sequence of importing datas to the tree */""" + ret = RC.RET_OK + if newDoc: + self.endXml() + self.doc = newDoc + ret = self.startXml(self.doc.children) + self.resetCurrent() + self.gotoChildren() + self.Find(ES.XML_DATAS,False) + self.datas = self.current + self.getMetaEvenDatasFromXml() + self.updateHashValue() + return ret + return RC.RET_CONNATACCESS + + def updateHashValue(self,fieldName = None): + """/** Update the hashValue. Take Data in the tree and update HashValue of the evenData + fieldname : name of the field (in the data tree updated) */""" + update = False + count = self.linkFieldsNames.getCount() + if fieldName: + for I in range(count): + if self.linkFieldsNames.get(I).getString()==fieldName: + update = True + break + else: + update = True + if update: + bkpCurrent = self.current + nbExists = 0 + str ="" + for I in range(count): + value = self.getData(self.linkFieldsNames.get(I).getString()) + if value != RC.RET_NOTFOUND: + nbExists += 1 + str += value + if nbExists == count: + self.setString(str) + else: + self.setString(ES.TXT_NULL) + self.current = bkpCurrent + + def setSource(self,source): + """/** Set the source position => from where the evenData comes. */""" + return self.source.setPosition(source) + + def getSource(self): + """/** Get the source position => from where the evenData comes. */""" + return self.source + + def addDestination(self,destinationA): + """/** Set the destination position => to where the evenData goes. */""" + ret = RC.RET_OK + str = self.getSplitted(ES.DESTINATION_SEPARATOR, destinationA) + while str: + pos = Fposition() + pos.setPosition(str) + ret = self.destination.add(pos) + str = self.getSplitted(ES.TREE_SEPARATOR) + return ret + + def getCurrentDestination(self): + """/** Get the destination position => to where the evenData goes. */""" + return self.destination.get(self.currentDestination) + + def selectNextDestination(self): + """/** Select next destination, ex.: after a evenBoard this can be a evenPrg */""" + if self.currentDestination+1 < self.destination.getCount(): + self.currentDestination += 1 + self.activePort = 0 + return RC.RET_OK + else: + return RC.RET_NOTEXIST + + def resetDestination(self): + """/** Remove all the destinations from the list */""" + for I in range(self.destination.getCount()): + self.destination.remove(0) + self.currentDestination = 0 + + def setLinkFieldsNames(self,linkFieldsNamesString): + """/** Name of the fields that represent the link between two evenDatas. */""" + str = self.getSplitted(ES.FIELD_SEPARATOR, linkFieldsNamesString) + if self.linkFieldsNames.getCount(): + self.resetLinkFieldsNames() + while str: + s = FstringHash() + s.setString(str) + self.linkFieldsNames.add(s) + str = self.getSplitted(ES.TREE_SEPARATOR) + self.updateHashValue() + if self.evenDataB: + evenDataB = None + return RC.RET_OK + + def resetLinkFieldsNames(self): + """/** Remove all the destinations from the list */""" + for I in range(self.linkFieldsNames.getCount()): + self.linkFieldsNames.remove(0) + + + def reset(self): + """/** Reset the datas ( erase all informations) */""" + self.source.setString(ES.TXT_NULL) + self.startToUse = time() + self.resetDestination() + self.resetLinkFieldsNames() + self.endXml() + self.initDatas() + + def getStartToUse(self): + """/** When the evenData as entered for the first time into a room. */""" + return self.startToUse + + def setEvenDataB(self,evenData): + """/** Set the other evenData merged with this */""" + self.evenDataB = evenData + + def getEvenDataB(self): + """/** Get the other evenData merged with this ( and remove the pointer) */""" + tmp = self.evenDataB + self.evenDataB = None + return tmp + + def setData(self,nodeName,value): + """/** Set a "Value" in the datastree. */""" + ret = self.gotoTagName(nodeName) + if ret == RC.RET_OK: + ret = self.setContent(value) + self.updateHashValue(nodeName) + return ret + + def getData(self,nodeName): + """/** Get the "Value" of the nodeName in the datastree. */""" + ret = self.gotoTagName(nodeName, False) + if ret == RC.RET_OK: + return self.getContent() + return ret + + def setDataInt(self,nodeName,value): + """/** Set a int "Value" in the datastree. */""" + ret = self.gotoTagName(nodeName) + if ret == RC.RET_OK: + ret = self.setContent(str(value)) + self.updateHashValue(nodeName) + return ret + + def getDataInt(self,nodeName): + """/** Get the int "Value" of the nodeName in the datastree. */""" + ret = self.gotoTagName(nodeName, False) + if ret == RC.RET_OK: + return int(self.getContent()) + return ret + + def setDatasFromString(self,string): + """/** Set ALL the datas of the datastree. All this new datas replace the old datas. */""" + return self.setDatasFromXXX(libxml2.parseMemory(string, len(string))) + + def setDatasFromFile(self,fileName): + """/** Set ALL the datas of the datastree. From a File or a stream. */""" + return self.setDatasFromXXX(libxml2.parseFile(fileName)) + + def getDatasToString(self,): + """/** Get ALL the datas to a string (ex.: XML format). */""" + if self.xmlBuffer: + self.xmlFree(self.xmlBuffer) + self.setMetaEvenDatasToXml() + # no xmlDocDumpMemory !! # TzurTcH !!!!! Achtung !!!!! + f=file(".__temp__XML","w") + self.doc.dump(f) + f.close() + f=file(".__temp__XML","r") + S = f.read() + f.close() + return S + + def getDatasToFile(self,fileName): + """/** Get ALL the datas To a File or a stream. */""" + self.setMetaEvenDatasToXml() + if self.doc.saveFile(fileName): + return RC.RET_OK + return RC.RET_CANNOTSAVE + + def copyFrom(self,data): + """/** Copy all information from another evenData. */""" + return self.setDatasFromString(data.getDatasToString()) + + def setActivePort(self,port): + """/** Set the active port */""" + self.activePort = port + + def getActivePort(self): + """/** Get the active port */""" + return self.activePort + + def definePortAction(self,action,portName = None): + """/** Do an action */""" + str="" + if portName: + str += portName + str += ":" + action + self.addDestination(str) + if self.destination.getCount(): + self.currentDestination = self.destination.getCount()-1 + else: + self.currentDestination = 0 + return RC.RET_OK + + + def DUMP(self): + return self.doc.saveFile("dump.xml") + + +if __name__ == '__main__': + + import unittest + + def getLinkFieldsNames(self): + return self.linkFieldsNames + + FILE = "testezlog_save.xml" + + class FevendataTestCase(unittest.TestCase): + + + def test1Source(self): + data1 = FevenData() + data1.setSource( "MySQL") + self.assertEquals("MySQL",data1.getSource().getString()) + + def test2Destination(self): + data1 = FevenData() + data1.addDestination( "gateUI") + self.assertEquals(data1.getCurrentDestination().getPort().getString(),"gateUI") + self.assertEquals(data1.selectNextDestination(),RC.RET_NOTEXIST) + + data1.resetDestination() + + data1.addDestination( "boardUI1") + data1.addDestination( "prgUI1") + data1.addDestination( "boardUI2") + data1.addDestination( "prgUI2") + + self.assertEquals( data1.getCurrentDestination().getPort().getString(),"boardUI1") + self.assertEquals( data1.selectNextDestination(),RC.RET_OK) + self.assertEquals( data1.getCurrentDestination().getPort().getString(),"prgUI1") + self.assertEquals( data1.selectNextDestination(),RC.RET_OK) + self.assertEquals( data1.getCurrentDestination().getPort().getString(),"boardUI2") + self.assertEquals( data1.selectNextDestination(),RC.RET_OK) + self.assertEquals( data1.getCurrentDestination().getPort().getString(),"prgUI2") + self.assertEquals( data1.selectNextDestination(),RC.RET_NOTEXIST) + + data1.resetDestination() + + data1.addDestination( "boardUI1;prgUI1;boardUI2;prgUI2"); + + self.assertEquals( data1.getCurrentDestination().getPort().getString(),"boardUI1") + self.assertEquals( data1.selectNextDestination(),RC.RET_OK) + self.assertEquals( data1.getCurrentDestination().getPort().getString(),"prgUI1") + self.assertEquals( data1.selectNextDestination(),RC.RET_OK) + self.assertEquals( data1.getCurrentDestination().getPort().getString(),"boardUI2") + self.assertEquals( data1.selectNextDestination(),RC.RET_OK) + self.assertEquals( data1.getCurrentDestination().getPort().getString(),"prgUI2") + self.assertEquals( data1.selectNextDestination(),RC.RET_NOTEXIST) + + def test3LnkFieldsname(self): + data2 = FevenData() + data2.setLinkFieldsNames( "Client/Address/Name,Client/AccountNumber") + LINK2=data2.__dict__['linkFieldsNames'] + + self.assertEquals( "Client/Address/Name",LINK2.get(0).getString()) + self.assertEquals( "Client/AccountNumber", LINK2.get(1).getString()) + + #// Check a change of the linkFieldsNames directly without creating a new evenData + data2.setLinkFieldsNames( "Ref1/Ref2/Ref3,Val1/Val2,Data1") + + self.assertEquals( "Ref1/Ref2/Ref3",LINK2.get( 0).getString()) + self.assertEquals( "Val1/Val2",LINK2.get(1).getString()) + self.assertEquals( "Data1", LINK2.get(2).getString()) + + def test4Timer(self): + data1 = FevenData() + T = time() + data1.reset() + T1 = data1.getStartToUse() + self.assertEquals( abs(T - T1) < 2,True) + + def test5SetAndGetDatas(self): + data1 = FevenData() + data1.setData( "Name", "Dupont") + self.assertEquals( data1.getData( "Name"),"Dupont") + data1.setData( "Account/Number", "012345678901234567") + data1.setData( "Account/Name", "BANK Dupond") + data1.setData( "Account/Devises/Rate/CHF", "1,234") + data1.setData( "Account/Devises/Rate/DM", "1,2") + self.assertEquals( data1.getData( "Account/Number"),"012345678901234567") + self.assertEquals( data1.getData( "Account/Name"),"BANK Dupond") + self.assertEquals( data1.getData( "Account/Devises/Rate/CHF"),"1,234") + self.assertEquals( data1.getData( "Account/Devises/Rate/DM"),"1,2") + + def test6SetAndGetDatasInt(self): + data1 = FevenData() + data1.setDataInt( "Name", 10) + self.assertEquals( data1.getDataInt( "Name"),10) + data1.setDataInt( "Account/Number", 123) + data1.setDataInt( "Account/Name", 200) + data1.setDataInt( "Account/Devises/Rate/CHF", -176) + data1.setDataInt( "Account/Devises/Rate/DM", 182) + self.assertEquals( data1.getDataInt( "Account/Number"),123) + self.assertEquals( data1.getDataInt( "Account/Name") ,200) + self.assertEquals( data1.getDataInt( "Account/Devises/Rate/CHF"), -176) + self.assertEquals( data1.getDataInt( "Account/Devises/Rate/DM"), 182) + + def test7SaveDatasFile(self): + data1 = FevenData() + data1 = FevenData() + data1.setSource( "MySQL") + + data1.addDestination( "boardUI1") + data1.addDestination( "prgUI1") + data1.addDestination( "boardUI2") + data1.addDestination( "prgUI2") + data1.setLinkFieldsNames( "Client/Address/Name,Client/AccountNumber") + + data1.setData( "Account/Number", "123") + data1.setData( "Account/Name", "200") + data1.setDataInt( "Account/Devises/Rate/CHF", 176) + data1.setDataInt( "Account/Devises/Rate/DM", 182) + + data1.getDatasToFile(FILE) + + S = "<?xml version=\"1.0\"?>\n<XML><evendata_datas><Account><Number>123</Number><Name>200</Name><Devises><Rate><CHF>176</CHF><DM>182</DM></Rate></Devises></Account></evendata_datas><evendata_source>MySQL</evendata_source><evendata_starttime>0</evendata_starttime><evendata_destination><evendata_destcount>4</evendata_destcount><evendata_currentdest>0</evendata_currentdest><evendata_dest0>boardUI1</evendata_dest0><evendata_dest1>prgUI1</evendata_dest1><evendata_dest2>boardUI2</evendata_dest2><evendata_dest3>prgUI2</evendata_dest3></evendata_destination><evendata_linkfields>Client/Address/Name,Client/AccountNumber</evendata_linkfields></XML>\n" + self.assertEquals(S,file(FILE, "r").read()) + + def test8LoadDatasFile(self): + data2 = FevenData() + LINK2=data2.__dict__['linkFieldsNames'] + data2.setDatasFromFile(FILE) + self.assertEquals( data2.getSource().getString(),"MySQL") + self.assertEquals( data2.getCurrentDestination().getString(),"boardUI1") + data2.selectNextDestination() + self.assertEquals( data2.getCurrentDestination().getString(),"prgUI1") + data2.selectNextDestination() + self.assertEquals( data2.getCurrentDestination().getString(),"boardUI2") + data2.selectNextDestination() + self.assertEquals( data2.getCurrentDestination().getString(),"prgUI2") + self.assertEquals(data2.selectNextDestination(), RC.RET_NOTEXIST) + + self.assertEquals( "Client/Address/Name", LINK2.get(0).getString()) + self.assertEquals( "Client/AccountNumber", LINK2.get(1).getString()) + + self.assertEquals( data2.getData( "Account/Number"),"123") + self.assertEquals( data2.getData( "Account/Name"),"200") + self.assertEquals( data2.getDataInt( "Account/Devises/Rate/CHF"), 176) + self.assertEquals( data2.getDataInt( "Account/Devises/Rate/DM"), 182) + + def test9SaveDatasMemory(self): + data1 = FevenData() + data1.setSource( "MySQL") + data1.addDestination( "boardUI1") + data1.addDestination( "prgUI1") + data1.addDestination( "boardUI2") + data1.addDestination( "prgUI2") + data1.setLinkFieldsNames( "Client/Address/Name,Client/AccountNumber") + + + data1.setData( "Account/Number", "123") + data1.setData( "Account/Name", "200") + data1.setDataInt( "Account/Devises/Rate/CHF", 176) + data1.setDataInt( "Account/Devises/Rate/DM", 182) + + global buff + buff = data1.getDatasToString() + + S = "<?xml version=\"1.0\"?>\n<XML><evendata_datas><Account><Number>123</Number><Name>200</Name><Devises><Rate><CHF>176</CHF><DM>182</DM></Rate></Devises></Account></evendata_datas><evendata_source>MySQL</evendata_source><evendata_starttime>0</evendata_starttime><evendata_destination><evendata_destcount>4</evendata_destcount><evendata_currentdest>0</evendata_currentdest><evendata_dest0>boardUI1</evendata_dest0><evendata_dest1>prgUI1</evendata_dest1><evendata_dest2>boardUI2</evendata_dest2><evendata_dest3>prgUI2</evendata_dest3></evendata_destination><evendata_linkfields>Client/Address/Name,Client/AccountNumber</evendata_linkfields></XML>\n" + + self.assertEquals(S,buff) + + def test10LoadDatasMemory(self): + data2 = FevenData() + self.test9SaveDatasMemory() + data2.setDatasFromString( buff) + LINK2=data2.__dict__['linkFieldsNames'] + + self.assertEquals(data2.getSource().getString(),"MySQL") + self.assertEquals( data2.getCurrentDestination().getString(),"boardUI1") + data2.selectNextDestination() + self.assertEquals( data2.getCurrentDestination().getString(),"prgUI1") + data2.selectNextDestination() + self.assertEquals( data2.getCurrentDestination().getString(),"boardUI2") + data2.selectNextDestination() + self.assertEquals( data2.getCurrentDestination().getString(),"prgUI2") + self.assertEquals( data2.selectNextDestination(), RC.RET_NOTEXIST) + + self.assertEquals( "Client/Address/Name", LINK2.get(0).getString()) + self.assertEquals( "Client/AccountNumber", LINK2.get(1).getString()) + + self.assertEquals( data2.getData( "Account/Number"), "123") + self.assertEquals( data2.getData( "Account/Name"), "200") + self.assertEquals( data2.getDataInt( "Account/Devises/Rate/CHF"), 176) + self.assertEquals( data2.getDataInt( "Account/Devises/Rate/DM"), 182) + + def test11HashValue(self): + return + data1.setLinkFieldsNames( "Client/Address/Name,Client/AccountNumber") + data1.setData( "Client/Address/Name", "Dupont") + data1.setData( "Client/AccountNumber", "200") + + strH = FstringHash() + strH.setString( "Dupont200") + self.assertEquals(strH.equals( data1),True) + + strH.setString( "Dupont201") + self.assertEquals(strH.equals( data1),False) + + def test12CopyFrom(self): + return + data1.setDatasFromFile("testezlog_save.xml") + data1.setLinkFieldsNames( "Client/Address/Name,Client/AccountNumber") + data1.setData( "Client/Address/Name", "Dupont") + data1.setData( "Client/AccountNumber", "200") + + data2.copyFrom( data1) + + self.assertEquals(data1.equals( data2),True) + + buff1 = data1.getDatasToString() + buff2 = data2.getDatasToString() + self.asserEquals(len(buff1),len(buff2)) + self.asserEquals(buff1,buff2) + + + unittest.main() diff --git a/fevendoor.py b/fevendoor.py new file mode 100644 index 0000000..a378844 --- /dev/null +++ b/fevendoor.py @@ -0,0 +1,122 @@ +#/*************************************************************************** +# fevendata.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + + +"""/** Door of the room. + + function : evenDoor of the room. Connect the room to external world. + To a specific prototcol and data format. + + description : evenDoor would convert a specific data format to the internal + evenData format and the evenData format to the external data format. + + *@author Fabian Padilla + */""" + +__all__ = ["FevenDoor"] + +from flist import Flist +from fstringhash import FstringHash +from globalvars import gvActionSysAddDest +from fportbkpevendata import FportBkpEvenData + +from returncodes import RET_OK +from returncodes import RET_NOTEXIST + +from evenjastrings import XML_LNKTYPE +from evenjastrings import XML_LNKVALUE +from evenjastrings import XML_LNKFIELDS +from evenjastrings import XML_LNKDEST +from evenjastrings import TXT_NULL + +class FspecialDestination: + """ """ + + def __init__(self, linkTypesNames, valueA, linkFieldsNames, linkDest): + self.type = FstringHash() + self.value = FstringHash() + self.fields = FstringHash() + self.dest = FstringHash() + + self.type.setString(linkTypesNames) + self.value.setString(valueA) + self.fields.setString(linkFieldsNames) + self.dest.setString(linkDest) + + +class FevenDoor(FportBkpEvenData): + """ """ + def __init__(self): + FportBkpEvenData.__init__(self) # force constructor + self.list = Flist() #/** List of special destination */a + + def __del__(self): + """I believe this is for no use.""" + while self.list.getCount(): + self.list.remove(0) + + def __str__(self): + return "\t"+FportBkpEvenData.__str__(self)+\ + "FevenDoor - list : "+str(self.list)+"\n" + + def justDoItSys(self,evenData): + """/** Methods called by Fstarter. */""" + ret = RET_OK + if evenData.getCurrentDestination().getAction().equals(gvActionSysAddDest): + ret = self.list.add( FspecialDestination(evenData.getData(XML_LNKTYPE),\ + evenData.getData(XML_LNKVALUE),\ + evenData.getData(XML_LNKFIELDS),\ + evenData.getData(XML_LNKDEST))) + self.setFreeEvenData(evenData) + return ret + + def sendEvenData(self,evenData): + """/** Methods to enable all ports to sends evenDatas to a port. */""" + spDestToDo = None + if evenData.getCurrentDestination() != RET_NOTEXIST: + return FportBkpEvenData.sendEvenData(self,evenData) + for I in range(self.list.getCount()): + spDest = self.list.get(I) + spDestString = spDest.type.getString() + if spDestString != TXT_NULL: # if we got a destination + evenData.setLinkFieldsNames(spDestString) + if spDestString == TXT_NULL or evenData.equals(spDest.value): + if spDestToDo <> None: + evenDataToDo = getFreeEvenData() + evenDataToDo = copyFrom(evenData) + evenDataToDo.setSource(self.getString()) + evenDataToDo.setLinkFieldsNames(spDestToDo.fields.getString()) + evenDataToDo.resetDestination() + evenDataToDo.addDestinatio(spDestToDo.dest.getString()) + FportBkpEvenData.sendEvenData(self,evenDataToDo) + spDestToDo = spDest + if spDestToDo: # something to send + evenData.setSource(self.getString()) + evenData.setLinkFieldsNames(spDestToDo.fields.getString()) + evenData.resetDestination() + evenData.addDestination(spDestToDo.dest.getString()) + FportBkpEvenData.sendEvenData(self,evenData) + else: + self.parent.setFreeEvenData(evenData) + + def getFreeEvenData(self): + """/** Get a new evenData. */""" + return self.parent.getFreeEvenData() diff --git a/fevenprg.py b/fevenprg.py new file mode 100644 index 0000000..caa7dac --- /dev/null +++ b/fevenprg.py @@ -0,0 +1,73 @@ +#/*************************************************************************** +# fevenprg.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +"""/** evenPrg do the modification on the evenData or many evenDatas. + + function : Interface for all evenPrg. + + description : Must contain only the behavior to modify datas and "if" concerning the + modification of datas. Do not implement in a evenPrg "if" about end user + functionnalities. See the withepaper.pdf at www.evenja.org. + + *@author Fabian Padilla + */""" + + +__all__ = ["FevenPrg"] + + +from fportbkpevendata import FportBkpEvenData +from evenjastrings import ACT_ERROR + +class FevenPrg(FportBkpEvenData): + """ This class is the interface for all evenPrg""" + + def __init__(self): + FportBkpEvenData.__init__(self) # force constructor + self.evenDataB = None #/** Backup of the evenDatas that need to be sends by sendEvenData */ + + def __str__(self): + return "\t"+FportBkpEvenData.__str__(self)+\ + "FevenPrg - evenDataB : "+str(self.evenDataB)+"\n" + + def justDoIt(self,evenData): + """/** Methods called by Fstarter */""" + self.evenDataB = evenData.getEvenDataB() + if self.evenDataB <> None: + evenData.setEvenDataB(self.evenDataB) + ret = FportBkpEvenData.justDoIt(self,evenData) + if self.evenDataB <> None: + self.evenDataB.definePortAction(ACT_ERROR) + self.sendEvenData(self.evenDataB) + return ret + + def sendEvenData(self,evenData): + """/** Methods to enable all ports to sends evenDatas to a port */""" + if self.evenDataB == evenData: + self.evenDataB = None + FportBkpEvenData.sendEvenData(self,evenData) + + def sendEvenDataSys(self,evenData): + """/** Methods to enable all ports to sends evenDatas to a port */""" + if self.evenDataB == evenData: + self.evenDataB = None + FportBkpEvenData.sendEvenDataSys(self,evenData) + diff --git a/flist.py b/flist.py new file mode 100644 index 0000000..292112e --- /dev/null +++ b/flist.py @@ -0,0 +1,146 @@ +#/*************************************************************************** +# flist.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +"""/** List that manage a table of pointer. + + function : maintain a list of pointer. + + description : pointers (or other 32bit values) can be + - added + - returned by giving the idx in the list + - returned by giving the idx in the list and removed from them + - older returned and removed from the list, by FisrtInfirstOut order + + *@author Fabian Padilla + */""" + +__all__ = ["Flist"] + +from returncodes import RET_NOTEXIST + +class Flist: + """ This class is just an other wrapper around the python builtin list. + It dosen't use exceptions 'cause exceptions suck ! """ + def __init__(self): + self.L = [] + + def __str__(self): + ret = '' + for I in self.L: + ret += str(I.__class__)+' : '+I.getString()+' - ' + return 'Flist - '+ret + + def add(self, el): + self.L.append(el) + #return RET_OK # TzurTcH - no need + + def get(self, idx): + if idx<0 or idx>=len(self.L): + return RET_NOTEXIST + return self.L[idx] + + def remove(self, idx): + if idx<0 or idx>=len(self.L): + return RET_NOTEXIST + tmp,self.L = self.L[idx], self.L[:idx]+self.L[idx+1:] + return tmp + + def removeFifo(self): + if len(self.L) == 0: + return RET_NOTEXIST + tmp, self.L = self.L[0], self.L[1:] + return tmp + + def removeStack(self): + if len(self.L) == 0: + return RET_NOTEXIST + return self.L.pop() + + def getCount(self): + return len(self.L) + + +if __name__ == '__main__': + + import unittest + + + class FlistTestCase(unittest.TestCase): + + def test1AddGetRemove(self): + list = Flist() + list.add("A") + list.add("B") + list.add("C") + list.add("D") + list.add("E") + self.assertEquals(list.get(0),"A") + self.assertEquals(list.get(1),"B") + self.assertEquals(list.get(2),"C") + self.assertEquals(list.get(3),"D") + self.assertEquals(list.get(4),"E") + self.assertEquals(list.remove(5),RET_NOTEXIST) + self.assertEquals(list.remove(0),"A") + self.assertEquals(list.remove(1),"C") + self.assertEquals(list.remove(2),"E") + self.assertEquals(list.remove(2),RET_NOTEXIST) + self.assertEquals(list.remove(1),"D") + self.assertEquals(list.remove(0),"B") + self.assertEquals(list.remove(0),RET_NOTEXIST) + + def test2RemoveFifo(self): + list = Flist() + list.add("A") + list.add("B") + list.add("C") + list.add("D") + list.add("E") + self.assertEquals(list.removeFifo(),"A") + self.assertEquals(list.removeFifo(),"B") + self.assertEquals(list.removeFifo(),"C") + self.assertEquals(list.removeFifo(),"D") + self.assertEquals(list.removeFifo(),"E") + self.assertEquals(list.removeFifo(),RET_NOTEXIST) + + def test3RemoveStack(self): + list = Flist() + list.add("A") + list.add("B") + list.add("C") + list.add("D") + list.add("E") + self.assertEquals(list.removeStack(),"E") + self.assertEquals(list.removeStack(),"D") + self.assertEquals(list.removeStack(),"C") + self.assertEquals(list.removeStack(),"B") + self.assertEquals(list.removeStack(),"A") + self.assertEquals(list.removeStack(),RET_NOTEXIST) + + def test4GetCount(self): + list = Flist() + list.add("A") + list.add("B") + list.add("C") + list.add("D") + list.add("E") + self.assertEquals(list.getCount(),5) + + unittest.main() diff --git a/flisthash.py b/flisthash.py new file mode 100644 index 0000000..345cac4 --- /dev/null +++ b/flisthash.py @@ -0,0 +1,133 @@ +#/*************************************************************************** +# flisthash.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +# TODO it could maybe be a D={}, sounds faster and easier.... + +"""/** Special list that manage the link between Hash value and the evenData pointer. + + function : maintain a list of SINGLE FstringHash ( single is define by HashValue) + + description : + - search : search for an existing FstringHash with the same hashValue + - addOrGet and addOrRemove only add methods available. Then only single hashValue exist. + + *@author Fabian Padilla + */""" + +__all__ = ["FlistHash"] + +from flist import Flist +from fstringhash import FstringHash + +class FlistHash(Flist): + """ This class is a wrapper arounf the flist class, providing some search capabilities""" + + def __init__(self): + Flist.__init__(self) # force constructor + + def __str__(self): + return "\t"+Flist.__str__(self)+\ + "FlistHash - (null)\n" + + #def SearchPos(self,fstringHash): + # """/** Search the position of the stringhash name. + # Return the position in the list or None if not found. */""" + # ret = None + # print self.L + # for I in self.L: + # if I.equals(fstringHash): + # return self.L.index(I) + # return ret + + + def Search(self,fstringHash): + """/** Search if same name (stringhash) exist */""" + for I in self.L: + if I.equals(fstringHash): + return I + return None + + def addOrGet(self,fstringHash): + """/** If the same name exist in the list then get it from the list. + If not, add stringhash in the list then return None. */""" + pos = self.Search(fstringHash) + if pos <> None: + return pos + self.add(fstringHash) + return None + + def addOrRemove(self,fstringHash): + """/** If the same name exist in the list, then removes and return it. + If not, then add to the list and return None. */""" + pos = self.Search(fstringHash) + if pos <> None: + self.L.remove(pos) + return pos + self.add(fstringHash) + return None + + +if __name__ == '__main__': + + import unittest + from OSconfig import START_ELEMENTS + + List = FlistHash() + + str=[FstringHash(),FstringHash(),FstringHash(),FstringHash(),FstringHash()] + STR=["TEST", "TEST1", "TEST", "TEST1", "TEST2"] + str[0].setString(STR[0]) + str[1].setString(STR[1]) + str[2].setString(STR[2]) + str[3].setString(STR[3]) + str[4].setString(STR[4]) + + class FlistHashTestCase(unittest.TestCase): + + def test1HashAddOrGet(self): + self.assertEquals(List.addOrGet(str[0]),None) + self.assertEquals(List.addOrGet(str[1]),None) + self.assertEquals(List.addOrGet(str[2]).equals(str[2]),True) + self.assertEquals(List.addOrGet(str[3]).equals(str[3]),True) + self.assertEquals(List.addOrGet(str[4]),None) + + def test2HashAddOrRemove(self): + self.assertEquals(List.addOrRemove(str[0]).equals(str[0]),True) + self.assertEquals(List.addOrRemove(str[1]).equals(str[1]),True) + self.assertEquals(List.addOrRemove(str[2]),None) + self.assertEquals(List.addOrRemove(str[3]),None) + self.assertEquals(List.addOrRemove(str[4]).equals(str[4]),True) + self.assertEquals(List.addOrRemove(str[2]).equals(str[2]),True) + self.assertEquals(List.addOrRemove(str[3]).equals(str[3]),True) + + def test3HashSearch(self): + for I in range (START_ELEMENTS+10): + buffer = "TEST%d"%I + str1 = FstringHash() + str1.setString(buffer) + self.assertEquals(List.addOrGet( str1),None) + buffer = "TEST%d"%(START_ELEMENTS-10) + str1 = FstringHash() + str1.setString(buffer) + self.assertEquals(List.Search(str1).getString(),"TEST%d"%(START_ELEMENTS-10)) + + + unittest.main() diff --git a/fport.py b/fport.py new file mode 100644 index 0000000..e12f28d --- /dev/null +++ b/fport.py @@ -0,0 +1,153 @@ +#/*************************************************************************** +# fport.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +"""/**Origin class for all part of the software that receive data in evenja concept. + + function: Abstract class for ALL ports : FevenPrg, FevenDoor, FevenBoard, Frouter. + + description : Implement only the behavior with the viewer. + + *********** + IMPORTANT : + *********** + In the method receive_evenData each inherited class need to call the parent + method first , with : Fport::receive_evenData( evenData); + + *@author Fabian Padilla + */""" + +__all__ =["Fport"] + +from flist import Flist +from fconfig import Fconfig +from fevendata import FevenData +from flisthash import FlistHash +from returncodes import RET_OK +from returncodes import RET_NOTIMPLEMENTED +from evenjastrings import XML_NAME + + +class Fport(Fconfig): + """This is the abstract class for all kind of port. + It manages viewer and got some generic and high level data manipulation methods""" + + # class attribute + listMsg = Flist() #/** List of all waiting envenData to be send to a port */ + listMsgSys = Flist() #/** List of all wainting envenData with system datas to be send to a port */ + + def __init__(self): + Fconfig.__init__(self) # force constructor + self.parent = None #/** Router this port is connected to and receives from */ + self.viewer = None #/** Enable to view the datas inside the port (evenDoor or evenBoard). */ + self.freeEvenData = FlistHash() #/** List of Free and Available evenDatas (faster than new and delete ;) */ + + def __str__(self): + return "\t"+Fconfig.__str__(self)+\ + " Fport - parent : "+str(self.parent)+\ + " - Viewer : "+str(self.viewer)+\ + " - freeEvenData : "+str(self.freeEvenData.getCount())+"\n" + + def start(self,port,config): + """/** Starts import the config file ( or other stream), and sets the parent + router. If the port (evenDoor and evenBoard) need to send an evenData. */""" + self.parent = port + return self.startXml(config) # TzurTcH ?? + #if ret == RET_OK: # we found the <evenja_name> tag and get it's content + # self.pushCurrent() # so why look for it another time and expect not to find it ??? + # self.gotoChildren() + # ret = self.Find(XML_NAME,False) + # if ret != RET_OK: + # self.setString(self.getContent()) + # self.popCurrent() + #return ret + + def receive_evenData(self,evenData): + """/** Work in all ports => router, evenPrg, evenDoor or evenBoard are only + done inside this overload method. + If it is a evenDoor the surcharged method will receive an evenData + that needs to be exported from the room to the external format of the evenDoor. + If it is a evenBoard the surcharged method will receive an evenData + and modify or wait for another evenData. */""" + print "This method MUST be overriden !!" + from sys import exit + exit(1) + + def end(self): + """/** To force futur developer to implement the right behavior for evenDoor and evenBoard */""" + return self.endXml() + + def setViewer(self,viewer): + """/** Set the debug viewer. Where all incoming evenDatas are displayed with the config of the port. */""" + self.viewer = viewer + #return RET_OK # TzurTcH - no need + + def justDoIt(self,evenData): + """/** Methods called by Fstarter */""" + ret = RET_OK + if self.viewer: + ret = self.viewer.receive_evenData(evenData) + if ret == RET_OK: + ret = self.receive_evenData(evenData) + return ret + + def justDoItSys(self,evenData): + """/** Methods called by Fstarter */""" + self.setFreeEvenData(evenData) + #return RET_OK # TzurTcH - ne need + + def sendEvenData(self,evenData,portDestination = None): + """/** Methods to enable all ports to sends evenDatas to a port */""" + if portDestination: + evenData.setActivePort(portDestination) + elif self.parent: + evenData.setActivePort(self.parent) + else: + evenData.setActivePort(self) + self.listMsg.add(evenData) + + def sendEvenDataSys(self,evenData,portDestination = None): + """/** Methods to enable all ports to sends evenDatas to a port */""" + if portDestination: + evenData.setActivePort(portDestination) + elif self.parent: + evenData.setActivePort(self.parent) + else: + evenData.setActivePort(self) + self.listMsgSys.add(evenData) + + + def setFreeEvenData(self, evenData): + """/** set an evenData free */""" + self.freeEvenData.add(evenData) + + def getFreeEvenData(self): + """/** Get an evenData free */""" + if self.freeEvenData.getCount(): + data = self.freeEvenData.remove(0) + else: + data = FevenData() + data.reset() + return data + + def evendoor_condition(self,evenData,port): + """/** USED BY THE EVENDOOR LIBRARY. FUTUR IMPLEMENTATION. */""" + return RET_NOTIMPLEMENTED + diff --git a/fportbkpevendata.py b/fportbkpevendata.py new file mode 100644 index 0000000..3533f82 --- /dev/null +++ b/fportbkpevendata.py @@ -0,0 +1,66 @@ +#/*************************************************************************** +# fportbkpevendata.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +"""/** Inherited from Fport to add a listHash. + + function : secure the use of evenData send to evenPrg or evebDoor. + + description : work as Fport. + + *@author Fabian Padilla + */""" + +__all__ = ["FportBkpEvenData"] + +from fport import Fport +from evenjastrings import ACT_ERROR + +class FportBkpEvenData(Fport): + """This class is a wrapper arounf Fport class for security purpose""" + + def __init__(self): + Fport.__init__(self) # force constructor + self.evenDataA = None #/** Backup of the evenDatas that need to be sends by sendEvenData */ + + def __str__(self): + return "\t"+Fport.__str__(self)+\ + "FportBkpEvenData - evenDataA : "+str(self.evenDataA)+"\n" + + def justDoIt(self,evenData): + """/** Methods called by Fstarter */""" + self.evenDataA = evenData + ret = Fport.justDoIt(self,evenData) + if self.evenDataA: + self.evenDataA.definePortAction(ACT_ERROR) + self.sendEvenData(self.evenDataA) + return ret + + def sendEvenData(self,evenData,portDestination = None): + """/** Methods to enable all ports to sends evenDatas to a port */""" + if (self.evenDataA == evenData): + self.evenDataA = None + Fport.sendEvenData(self,evenData,portDestination) + + def sendEvenDataSys(self,evenData,portDestination = None): + """/** Methods to enable all ports to sends evenDatas to a port */""" + if (self.evenDataA == evenData): + self.evenDataA = None + Fport.sendEvenDataSys(self,evenData,portDestination) diff --git a/fportlist.py b/fportlist.py new file mode 100644 index 0000000..38da1aa --- /dev/null +++ b/fportlist.py @@ -0,0 +1,47 @@ +#/*************************************************************************** +# fportlist.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +"""/** Inherited from Fport to add a listHash. + + function : maintain a list in + FevenDoor : + + description : work as Fport. + + *@author Fabian Padilla + */""" + +__all__ = ["FportList"] + +from fport import Fport +from flist import Flist + + +class FportList(Fport): + """This class is nothing but a fport with a flist as atribute""" + + def __init__(self): + Fport.__init__(self) # force constructor + self.list = Flist #/** List of inherited class from FstringHash ( found them faster). */ + + def __str__(self): + return "\t"+Fport.__str__(self)+\ + "FportList - list : "+str(self.list)+"\n" diff --git a/fportlisthash.py b/fportlisthash.py new file mode 100644 index 0000000..1fffd3c --- /dev/null +++ b/fportlisthash.py @@ -0,0 +1,57 @@ +#/*************************************************************************** +# fevendata.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ +# /*************************************************************************** +# +# fportlisthash.py +# ------------------- +# begin : tue mar 09 2004 +# copyright : (C) 2004 by Jeremy Zurcher +# email : tzurtch@bluemail.ch +# +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +"""/** Inherited from Fport to add a listHash. + + function : maintain a list of single evenDatas ( single by the linkValue) in + FevenBoard : to merge and or maintain a list of evenDatas + Frouter : to send the evenDatas to the right destinations + + description : work as Fport. + + *@author Fabian Padilla + */""" + +__all__ = ["FportListHash"] + +from fport import Fport +from flisthash import FlistHash + + +class FportListHash(Fport): + """ This is a Fport with Flist attribute""" + + def __init__(self): + Fport.__init__(self) # force constructor + self.listHash = FlistHash() #/** List of inherited class from FstringHash ( found them faster). */ + + def __str__(self): + return "\t"+Fport.__str__(self)+\ + "FportListHash - list : "+str(self.listHash)+"\n" diff --git a/fposition.py b/fposition.py new file mode 100644 index 0000000..09cc62e --- /dev/null +++ b/fposition.py @@ -0,0 +1,251 @@ +#/*************************************************************************** +# fposition.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + + +"""/** Define the position ( source OR destination) of the evenData. + function : maintain the stringHashs for the computer, rooms, port, action. + Format example : www.revena.com/room1/room2/port:normal + + description : method "setPosition" set all position informations this mean + - compute + - room tree + - port + - action. + Then these informations are retrieved with getComputer, getRoom, getPort, + getAction methods. + + *@author Fabian Padilla + */""" + +__all__ =["Fposition"] + +from flist import Flist +from fstringhash import FstringHash + +from returncodes import RET_OK +from evenjastrings import ACT_WAIT_NOTHING +from evenjastrings import ACT_NORMAL +from evenjastrings import TXT_NULL + +class Fposition(FstringHash): + """This class keeps informations on the computer / a list of rooms / a port /an action / and time""" + + def __init__(self): + FstringHash.__init__(self) # force constructor + self.computer = FstringHash() # /** computer destination or source. */ + self.rooms = Flist() # /** room destination or source. */ + self.nbLevel = 0 + self.port = FstringHash() # /** port destination or source. */ + self.action = FstringHash() # /** action to do at the position (source or destination). */ + self.waitTime = 0 # /** wait time in the action */ + #/** waitTime unit (ex.: y(year), n(month), d(day), h(hour), m(minute), s(seconde) or x(milliseconde))*/ + self.unitWaitTime = ACT_WAIT_NOTHING + self.positionActived = False + + def __del__(self): + """I belive this is for no use""" + self.resetPosition() + + def __str__(self): + return "\t"+FstringHash.__str__(self)+\ + "Fposition - computer : "+str(self.computer)+\ + " - rooms : "+str(self.rooms)+\ + " - nbLevel : "+str(self.nbLevel)+\ + " - port : "+str(self.port)+\ + " - action : "+str(self.action)+\ + " - waitTime : "+str(self.waitTime)+\ + " - unitWaitTime : "+str(self.unitWaitTime)+\ + " - positionAtived : "+str(self.positionActived)+"\n" + + def resetPosition(self): + """/** reset position (erase datas) */""" + if self.positionActived: + self.computer.setString(TXT_NULL) + # delete rooms + for I in range(self.nbLevel): + self.rooms.remove(0) # TzurTcH - no self.getRoom() + self.nbLevel = 0 + self.port.setString(TXT_NULL) + self.action.setString(TXT_NULL) + self.waitTime = 0 + self.unitWaitTime = ACT_WAIT_NOTHING + self.positionActived = False + + def setPosition(self, position): + """/** Set the source or the destination of an evenData. */""" + self.resetPosition() + self.nbLevel = 0 + self.setString(position) + + # search for - computer/rooms<F2> + buffer = position.split("/") + if len(buffer) > 1: + # computer name ? + ret = None + try: + ret = buffer[0].index(".") + except: + None + if ret: + self.computer.setString(buffer[0]) + buffer = buffer[1:] + # import rooms + bufferRooms="" + for I in buffer[:-1]: + self.rooms.add( FstringHash()) + if self.nbLevel: + bufferRooms += "/" + bufferRooms += I + self.rooms.get(self.nbLevel).setString(bufferRooms) + self.nbLevel += 1 + # search for - port:action + buffer = buffer[-1].split(":") + self.port.setString(buffer[0]) + if len(buffer) > 1: + # search for - action,time + buffer = buffer[1].split(",") + self.action.setString(buffer[0]) + if len(buffer) > 1: + self.waitTime = int(buffer[1][:-1]) + self.unitWaitTime = buffer[1][-1] + else: + self.waitTime = 0 + self.unitWaitTime = ACT_WAIT_NOTHING + else: + self.action.setString(ACT_NORMAL) + self.waitTime = 0 + self.unitWaitTime = ACT_WAIT_NOTHING + self.positionActived = True + return RET_OK + + def getComputer(self): + """/** Get the computer name. If the evenData needs to go to another computer. */""" + return self.computer + + def getRoom(self, level = 0): + """/** Get the room for destination or source. */""" + if level < self.nbLevel: + return self.rooms.get(level) + else: + return None + + def getNbLevel(self): + """/** Number of levels in the rooms routing tree. */""" + return self.nbLevel + + def getPort(self): + """/** Get the port of the position (source or destination). This means an evenDoor or a evenBoard. */""" + return self.port + + def getAction(self): + """/** Get the action of the position (source or destination). */""" + return self.action + + def getWaitTime(self): + """/** Get the amount of waiting time (unity is another get function) */""" + return self.waitTime + + def getUnitWaitTime(self): + """/** Get the unity time y,n,d,h,m,s or x */""" + return self.unitWaitTime + + def copyFrom(self, pos): + """/** Copy a position From another Fposition class */""" + self.resetPosition() + self.computer.copyFrom(pos.getComputer()) + + for I in range(pos.getNbLevel()): + new = FstringHash() + new.copyFrom(pos.getRoom(I)) + self.rooms.add(new) + self.nbLevel = pos.getNbLevel() + self.port.copyFrom(pos.getPort()) + self.action.copyFrom(pos.getAction()) + self.waitTime = pos.getWaitTime() + self.unitWaitTime = pos.getUnitWaitTime() + self.positionActived = True + + + +if __name__ == '__main__': + + import unittest + from evenjastrings import * + + pos1 = Fposition() + pos2 = Fposition() + + class FpositionTestCase(unittest.TestCase): + + def test1Splitting(self): + pos1.setPosition( "WWW.TEST.ORG/room1/room2/port") + self.assertEquals(pos1.getNbLevel(),2) + self.assertEquals("WWW.TEST.ORG",pos1.getComputer().getString()) + self.assertEquals("room1",pos1.getRoom(0).getString()) + self.assertEquals("room1/room2",pos1.getRoom(1).getString()) + self.assertEquals("port",pos1.getPort().getString()) + self.assertEquals(ACT_NORMAL,pos1.getAction().getString()) + + pos1.setPosition("room1/room2/port:destination1Data") + self.assertEquals(pos1.getNbLevel(),2) + self.assertEquals(TXT_NULL,pos1.getComputer().getString()) + self.assertEquals("room1",pos1.getRoom(0).getString()) + self.assertEquals("room1/room2",pos1.getRoom(1).getString()) + self.assertEquals("port",pos1.getPort().getString()) + self.assertEquals(ACT_DESTINATION1DATA,pos1.getAction().getString()) + + pos1.setPosition( "port:wait,5s") + self.assertEquals(pos1.getNbLevel(),0) + self.assertEquals(TXT_NULL,pos1.getComputer().getString()) + self.assertEquals(pos1.getRoom(0),None) + self.assertEquals("port",pos1.getPort().getString()) + self.assertEquals(ACT_WAIT,pos1.getAction().getString()) + self.assertEquals(pos1.getWaitTime(),5) + self.assertEquals( pos1.getUnitWaitTime(),ACT_WAIT_SECOND) + + pos1.setPosition( ":wait,5d") + self.assertEquals(pos1.getNbLevel(),0) + self.assertEquals(TXT_NULL,pos1.getComputer().getString()) + self.assertEquals(pos1.getRoom(0),None) + self.assertEquals(TXT_NULL,pos1.getPort().getString()) + self.assertEquals(ACT_WAIT,pos1.getAction().getString()) + self.assertEquals(pos1.getWaitTime(),5) + self.assertEquals(pos1.getUnitWaitTime(),ACT_WAIT_DAY) + + pos1.setPosition( ":end") + self.assertEquals(pos1.getNbLevel(),0) + self.assertEquals(TXT_NULL,pos1.getComputer().getString()) + self.assertEquals(pos1.getRoom(0),None) + self.assertEquals(TXT_NULL,pos1.getPort().getString()) + self.assertEquals(ACT_END,pos1.getAction().getString()) + + def test2Copy(self): + pos1.setPosition( "WWW.TEST.ORG/room1/room2/port:wait,1d") + pos2.copyFrom( pos1) + self.assertEquals(pos1.getComputer().equals( pos2.getComputer()),True) + self.assertEquals(pos1.getRoom(0).equals(pos2.getRoom(0)),True) + self.assertEquals(pos1.getRoom( 1).equals( pos2.getRoom( 1)),True) + self.assertEquals(pos1.getPort().equals( pos2.getPort()),True) + self.assertEquals(pos1.getAction().equals( pos2.getAction()),True) + self.assertEquals(pos1.getWaitTime(),pos2.getWaitTime()) + self.assertEquals(pos1.getUnitWaitTime(),pos2.getUnitWaitTime()) + + unittest.main() diff --git a/fprg_concat.py b/fprg_concat.py new file mode 100644 index 0000000..8ce3556 --- /dev/null +++ b/fprg_concat.py @@ -0,0 +1,53 @@ +#/*************************************************************************** +# fprg_concat.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +""" doc """ + +__all__ = ["Fdoor_concat"] + +from fevenprg import FevenPrg + +from returncodes import RET_OK +from evenjastrings import ACT_END + +class Fdoor_concat(FevenPrg): + + def __init__(self): + FevenPrg.__init__(self) # force construstor + + def __str__(self): + return "\t"+FevenPrg.__str__(self)+\ + "Fdoor_concat - (null)\n" + + def receive_evenData(self,evenData): + evenDataB = evenData.getEvenDataB() + + str = evenData.getData("TXT") + str += evenDataB.getData("TXT") + evenData.setData("TXT",str) + evenData.resetDestination() + evenData.addDestination("printf") + self.sendEvenData(evenData) + + evenDataB.definePortAction(ACT_END) + self.sendEvenData(evenDataB) + + return RET_OK diff --git a/frouter.py b/frouter.py new file mode 100644 index 0000000..186ac02 --- /dev/null +++ b/frouter.py @@ -0,0 +1,242 @@ +#/*************************************************************************** +# frouter.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +"""/** function : Manage the entire routing of evenDatas between routers, + evenDoor, evenBoard and evenPrg. + + description : + + *@author Fabian Padilla + */""" + +__all__ = ["Frouter"] + +from fdoor_file import Fdoor_file +from fdoor_cout import Fdoor_cout +from fprg_concat import Fdoor_concat + +from fport import Fport +from fconfig import Fconfig +from fevenboard import FevenBoard +from fevendata import FevenData +from fstringhash import FstringHash +from fportlisthash import FportListHash + +from globalvars import gvActionEnd +from globalvars import gvActionError + +import evenjastrings as ES +from returncodes import RET_OK +from returncodes import RET_NOINFOS +from returncodes import RET_NOTEXIST + +class Frouter(FportListHash): + + def __init__(self): + FportListHash.__init__(self) + + def __str__(self): + return "\t"+FportListHash.__str__(self)+\ + "Frouter - (null)\n" + + def start(self,port,param): + """/** Starts import the config file ( or other stream), and sets the parentrouter. + If the port (evenDoor and evenBoard) need to send an evenData. */""" + ret = Fport.start(self,port,param) + if ret == RET_OK: + return self.createRoom() + return ret + + def getClassInfos(self,classInfo): + """/** Get the informations concerning the creation of a port (room, evenprg, etc...) */""" + ret = RET_OK + self.pushCurrent() + if self.gotoChildren() != RET_OK: + return RET_NOTEXIST + + def search(string): + if self.Find(string) == RET_OK: + return self.getContent() + return None + + classInfo['type'] = search(ES.XML_CLASS) + classInfo['conf'] = search(ES.XML_CONF) + classInfo['lib'] = search(ES.XML_LIB) + classInfo['debug'] = search(ES.XML_DEBUG) + + self.popCurrent() + return ret + + def getLinkInfos(self,linkInfo): + """/** Get the informations concerning the cration of a port (room, evenprg, etc...) */""" + ret = RET_OK + self.pushCurrent() + if self.gotoChildren() != RET_OK: + return RET_NOTEXIST + + def search(string): + if self.Find(string) == RET_OK: + return self.getContent() + return None + + linkInfo['source'] = search(ES.XML_LNKSOURCE) + linkInfo['type'] = search(ES.XML_LNKTYPE) + linkInfo['value'] = search(ES.XML_LNKVALUE) + linkInfo['fields'] = search(ES.XML_LNKFIELDS) + linkInfo['dest'] = search(ES.XML_LNKDEST) + + self.popCurrent() + return ret + + def createRoom(self): + """/** Create a room with a structure defined by the config or node in start method */""" + classInfos = { 'type':None,\ + 'conf':None,\ + 'lib':None,\ + 'debug':None} + + linkInfos = { 'source':None,\ + 'type':None,\ + 'value':None,\ + 'fields':None,\ + 'dest':None} + strH = FstringHash() + port = Fport + + # search for rooms, boards, doors and programms + def IMPORT_PORTS(A,B,CLASS): + if self.Find(A,False) == RET_OK: + while True: + self.pushCurrent() + # read informations + self.getClassInfos(classInfos) + # let's build and start this + # if both are None or strcasecmp + # TODO ugliest code in this library + if ((classInfos['type']==None and B==None) or \ + (B <> None and classInfos['type'] <> None\ + and (classInfos['type'].upper() == B.upper()))): + childRoom = CLASS() + if classInfos['conf'] <> None: + childRoom.start(self,classInfos['conf']) + else: + childRoom.start(self,self.current) + ptr = self.listHash.addOrGet(childRoom) + if ptr <> None: + ptr = None + return RET_PORTEXIST + self.popCurrent() + # search for a next one + if self.FindNext(A,False) != RET_OK: + break + + self.resetCurrent() + if self.gotoChildren() != RET_OK: + return RET_NOINFOS + # search and build + IMPORT_PORTS( ES.XML_ROOM,None,Frouter) + IMPORT_PORTS( ES.XML_ROOM,"ROOM",Frouter) + IMPORT_PORTS( ES.XML_BOARD,None,FevenBoard) + IMPORT_PORTS( ES.XML_BOARD,"BOARD",FevenBoard) + + IMPORT_PORTS( ES.XML_DOOR, "file", Fdoor_file) + IMPORT_PORTS( ES.XML_DOOR, "cout", Fdoor_cout) + IMPORT_PORTS( ES.XML_PRG, "concat", Fdoor_concat) + + # seach for <envenja_link>, if dosen't exists, create an evendata and send it + if self.Find(ES.XML_LNK, False) != RET_OK: + return RET_OK + while True: + self.pushCurrent() + self.getLinkInfos(linkInfos) + if linkInfos['source'] <> None: + strH.setString(linkInfos['source']) + port = self.listHash.Search(strH) + # if this source has been built, send a ACT_SYS_ADDDEST msg + if port <> None: + data = self.getFreeEvenData() + data.setData( ES.XML_LNKTYPE, linkInfos['type']) + data.setData( ES.XML_LNKVALUE, linkInfos['value']) + data.setData( ES.XML_LNKFIELDS, linkInfos['fields']) + data.setData( ES.XML_LNKDEST, linkInfos['dest']) + + data.definePortAction( ES.ACT_SYS_ADDDEST, linkInfos['source']) + self.sendEvenDataSys(data,port) + self.popCurrent() + if self.FindNext( ES.XML_LNK,False) != RET_OK: + break + return RET_OK + + def receive_evenData(self,evenData): + """/** Receive the evenData to be routed to the right router or port. */""" + port = self.listHash.Search(evenData.getCurrentDestination().getPort()) + if port <> None: + #// ... then send to it the evenData + #// Now it send the evenData by sndMsg, but normally this will change after the realeas of V3.0 + #// sendEvenData( evenData, port); + #// return RET_OK; + #// ...this will work well too, but it is another principle + return port.justDoIt(evenData) + evenData.definePortAction(ES.ACT_ERROR) + return RET_OK + + def justDoIt(self,evenData): + """/** Methods called by Fstarter */""" + tmp = evenData.getCurrentDestination().getAction() + if tmp.equals(gvActionEnd) or tmp.equals(gvActionError): + self.setFreeEvenData(evenData) + return RET_OK + return Fport.justDoIt(self,evenData) + + def end(self): + """/** Deploy the end() until the port. */""" + for I in range(self.listHash.getCount()): + self.listHash.get(I).end() + return Fconfig.endXml(self) + + +if __name__ == '__main__': + + import unittest + + router1 = Frouter() + router2 = Frouter() + + class FrouterTestCase(unittest.TestCase): + + def test1Name(self): + self.assertEquals(router1.start( None, "testezlog.xml"),RET_OK) + strH = FstringHash() + strH.setString( "TEST00") + + #// TEST Name from file + self.assertEquals(router1.equals( strH),True) + + #// TEST from node config + conf = Fconfig() + conf.startXml( "testezlog.xml") + router2.start( None, conf.getCurrent()) + self.assertEquals(router2.equals( strH),True) + router1.end() + router2.end() + + + unittest.main() diff --git a/fstarter.py b/fstarter.py new file mode 100644 index 0000000..28567e7 --- /dev/null +++ b/fstarter.py @@ -0,0 +1,138 @@ +#/*************************************************************************** +# fstarter.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +"""/** First class of evenja and evendoor to be created. + This class will ask the firstRouter to create the first level of classes. + + *@author Fabian Padilla + */""" + + +__all__ = ["Fstarter"] + + +from frouter import Frouter +from fevendata import FevenData +from fstringhash import FstringHash + +from returncodes import RET_OK +from evenjastrings import XML_SERVER + +class Fstarter(Frouter): + """This is the main dispather, it receives all messages""" + + def __init__(self): + Frouter.__init__(self) # force constructor + #/** Is the software a server (deamon) or a normal software. + # A Server or deamon software wait until a signal ask for the end + # A normal software wil end when nothing is to do (at the end) */ + self.server = False + self.exit = False + + def __str__(self): + return "\t"+Frouter.__str__(self)+\ + "Fstarter - (null)\n" + + def setExit(self): + """/** Kill the application */""" + self.exit = True + + def start(self,FileName): + """/** Open the config file and transmit the first level of the rooms to the firstRouter. */""" + ret = Frouter.start(self,None,FileName) # set None as parent router + if ret == RET_OK: + self.pushCurrent() + self.server = not self.Find(XML_SERVER) + self.popCurrent() + return ret + + def execute(self,trace): + """/** Method called by the "main" of the application. + It send an evenData to all evenBoard and then to all evenDoor to really start the work of the rooms. + And wait until a TERM signal arrives from theself.__class__. OS. */""" + + if trace: + while True: + while self.listMsgSys.getCount() or self.listMsg.getCount(): + if self.listMsgSys.getCount(): + data = self.listMsgSys.removeFifo() + print '<?xml version="1.0"?>' + print '< *** SYS MSG *** />' + print data + data.getActivePort().justDoItSys(data) + else: + data = self.listMsg.removeFifo() + print '<?xml version="1.0"?>' + print '< *** MSG *** />' + print data + data.getActivePort().justDoIt(data) + if self.exit: + break + if not self.server or self.exit: + break + # TODO a small time out maybe ??? + + else: + while True: + while self.listMsgSys.getCount() or self.listMsg.getCount(): + if self.listMsgSys.getCount(): + data = self.listMsgSys.removeFifo() + data.getActivePort().justDoItSys(data) + else: + data = self.listMsg.removeFifo() + data.getActivePort().justDoIt(data) + if self.exit: + break + if not self.server or self.exit: + break + # TODO a small time out maybe ??? + + return RET_OK + + def end(self): + """/** Manage if Fstarter saves the config file ( in a dinamyc configuration of rooms). + Or if it is not needed because it is a static configuration. */""" + return Frouter.end(self) + + + + +if __name__ == '__main__': + + import unittest + + starter1 = Fstarter(); + starter2 = Fstarter(); + + class FstarterTestCase(unittest.TestCase): + + def test1Name(self): + self.assertEquals(starter1.start( "testezlog.xml"),RET_OK) + + strH = FstringHash() + strH.setString( "TEST00") + + #// TEST Name from file + self.assertEquals(starter1.equals( strH),True) + + starter1.end() + + unittest.main() diff --git a/fstringhash.py b/fstringhash.py new file mode 100644 index 0000000..dbde39c --- /dev/null +++ b/fstringhash.py @@ -0,0 +1,156 @@ +#/*************************************************************************** +# fstringhash.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +# TODO method equals should be __eq__ for the beauty ... +# TODO do we really need this, as python allready provides it's hash value technology in PyObject [ obj.__hash__() ] +# +# ob_sval == char* +# ob_size == strlen() +# +# int +# _PyString_Eq(PyObject *o1, PyObject *o2) +# { +# PyStringObject *a, *b; +# a = (PyStringObject*)o1; +# b = (PyStringObject*)o2; +# return a->ob_size == b->ob_size +# && *a->ob_sval == *b->ob_sval +# && memcmp(a->ob_sval, b->ob_sval, a->ob_size) == 0; +# } +# +# static long +# string_hash(PyStringObject *a) +# { +# register int len; +# register unsigned char *p; +# register long x; +# +# if (a->ob_shash != -1) +# return a->ob_shash; +# len = a->ob_size; +# p = (unsigned char *) a->ob_sval; +# x = *p << 7; +# while (--len >= 0) +# x = (1000003*x) ^ *p++; +# x ^= a->ob_size; +# if (x == -1) +# x = -2; +# a->ob_shash = x; +# return x; +# } + + + + +"""/** To speed up the process of comparaison between values, we use a hash technology. + function : hash a string and show hashvalue and string. + + description : the method "setString" is used to set the the value of the stringhash. + Then the hash value is available. + This will speedup the comparaison between the different "string" in evenja rooms. + ( it is faster to compare two int than complete string). + + *@author Fabian Padilla + */""" + +__all__ =["FstringHash"] + +try: + import hashlib +except: + print "no MD5 capabilities ... aborting" + import sys + sys.exit(1) + + +class FstringHash: + """This class is wrapper around the python builtin string providing an extra (virtual) hash function""" + def __init__(self): + self.string = None + self.hashValue = None + + def __str__(self): + return "FstringHash : "+str(self.string)+"\n" + + def __hash(self): + """ default hash function, may be overriden """ + return hashlib.md5(self.string).hexdigest() + + def setString(self,string): + self.string = string + if string is None: + self.hashValue = None + else: + self.hashValue = self.__hash() + + def getString(self): + return self.string + + def getHashValue(self): + return self.hashValue + + def copyFrom(self,other): + """copy my attributes from other""" + self.string = other.string + self.hashValue = other.hashValue + + #def __eq__(self,other): + def equals(self,other): + return self.string == other.string and self.hashValue == other.hashValue + + +if __name__ == '__main__': + + import unittest + + str1 = FstringHash() + str2 = FstringHash() + + class FstringHashTestCase(unittest.TestCase): + + def test1Equal(self): + str1.setString("WWW.TEST.ORG") + str2.setString("WWW.TEST.ORG") + self.assertEquals(str1.equals(str2),1) + + def test2NotEqual(self): + str1.setString("WWW.TEST.ORG") + str2.setString("WWW.NOTEST.ORG") + self.assertEquals(str1.equals(str2),0) + + def test3Copy(self): + str1.setString("WWW.TEST.ORG") + str2.copyFrom(str1) + self.assertEquals(str1.equals(str2),1) + + def test4Hash(self): + str1.setString("WWW.TEST.ORG") + self.assertEquals(hashlib.md5("WWW.TEST.ORG").hexdigest(),str1.getHashValue()) + + def test5None(self): + str1.setString("WWW.TEST.ORG") + str1.setString(None) + self.assertEquals(str1.getHashValue(),None) + self.assertEquals(str1.getString(),None) + + + + unittest.main() diff --git a/fviewer.py b/fviewer.py new file mode 100644 index 0000000..fb03225 --- /dev/null +++ b/fviewer.py @@ -0,0 +1,51 @@ +#/*************************************************************************** +# fviewer.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +"""/** Debugger class. + function : receive information about : + - Configuration of a port (evenDoor or evenBoard) + - Data waiting inside the port (evenDoor or evenBoard) + + description : This class cannot be different inside the same room, + because all ports (evenDoor and evenBoard) + need to be able to + access the head information : + - source + - destination + and access the data information. + WITHOUT HAVING TO DO A VERSIONNING. + + *@author Fabian Padilla + */""" + +__all__ = ["Fviewer"] + +from fport import Fport +from fevendata import FevenData + +class Fviewer(Fport): + """This class is form debugging purpose """ + def __init__(self): + Fport.__init__(self) # force constructor + + def __str__(self): + return "\t"+Fport.__str__(self)+\ + "Fviewer - (null)\n" diff --git a/globalvars.py b/globalvars.py new file mode 100644 index 0000000..dcd397d --- /dev/null +++ b/globalvars.py @@ -0,0 +1,134 @@ +#/*************************************************************************** +# globalvars.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +""" doc """ + +from fstringhash import FstringHash +import evenjastrings as ES + +#gvActionNormal = None +#gvActionDestination1Data = None +#gvActionDestination2Data = None +#gvActionFollowDestination = None +#gvActionWait = None + +#gvActionAdd = None +#gvActionUpdate = None +#gvActionDelete = None +#gvActionGet = None +#gvActionFind = None + +#gvActionEnd = None +#gvActionError = None + +#// SYSTEM ACTIONS +#gvActionSysAddDest = None + +#// PARAMETERS +#gvNoValues = None + +#def initGlobalVars(): +# +# global gvActionNormal +# global gvActionDestination1Data +# global gvActionDestination2Data +# global gvActionFollowDestination +# global gvActionWait +# global gvActionAdd +# global gvActionUpdate +# global gvActionDelete +# global gvActionGet +# global gvActionFind +# global gvActionEnd +# global gvActionError +# global gvActionSysAddDest +# global gvNoValues +# +gvActionNormal = FstringHash() +gvActionNormal.setString(ES.ACT_NORMAL) + +gvActionDestination1Data = FstringHash() +gvActionDestination1Data.setString(ES.ACT_DESTINATION1DATA) + +gvActionDestination2Data = FstringHash() +gvActionDestination2Data.setString(ES.ACT_DESTINATION2DATA) + +gvActionFollowDestination = FstringHash() +gvActionFollowDestination.setString(ES.ACT_FOLLOWDESTINATION) + +gvActionWait = FstringHash() +gvActionWait.setString(ES.ACT_WAIT) + +gvActionAdd = FstringHash() +gvActionAdd.setString(ES.ACT_ADD) + +gvActionUpdate = FstringHash() +gvActionUpdate.setString(ES.ACT_UPDATE) + +gvActionDelete = FstringHash() +gvActionDelete.setString(ES.ACT_DELETE) + +gvActionGet = FstringHash() +gvActionGet.setString(ES.ACT_GET) + +gvActionFind = FstringHash() +gvActionFind.setString(ES.ACT_FIND) + +gvActionEnd = FstringHash() +gvActionEnd.setString(ES.ACT_END) + +gvActionError = FstringHash() +gvActionError.setString(ES.ACT_ERROR) + +gvActionSysAddDest = FstringHash() +gvActionSysAddDest.setString(ES.ACT_SYS_ADDDEST) + +gvNoValues = FstringHash() +gvNoValues.setString(ES.TXT_NOVALUES) + + +#if __name__ == '__main__': +# +# import unittest +# D = dir() +# L=[ ES.ACT_ADD,\ +# ES.ACT_DELETE,\ +# ES.ACT_DESTINATION1DATA,\ +# ES.ACT_DESTINATION2DATA,\ +# ES.ACT_END,\ +# ES.ACT_ERROR,\ +# ES.ACT_FIND,\ +# ES.ACT_FOLLOWDESTINATION,\ +# ES.ACT_GET,\ +# ES.ACT_NORMAL,\ +# ES.ACT_SYS_ADDDEST,\ +# ES.ACT_UPDATE,\ +# ES.ACT_WAIT,\ +# ES.TXT_NOVALUES] +# +# class globalvarsTestCase(unittest.TestCase): +# +# def testInit(self): +# initGlobalVars() +# for I in D: +# if I[:2]=="gv": +# self.assertNotEquals(eval(D[D.index(I)]).getString(),D.index(I)) +# unittest.main() diff --git a/launch_evenja b/launch_evenja new file mode 100755 index 0000000..4e82f38 --- /dev/null +++ b/launch_evenja @@ -0,0 +1,6 @@ +#! /bin/sh + +EVENJA_PATH=${EVENJA_PATH:='.'} +START_FILE=pyevenja.py + +python -O $EVENJA_PATH/$START_FILE $* diff --git a/pyevenja.py b/pyevenja.py new file mode 100644 index 0000000..9fcc574 --- /dev/null +++ b/pyevenja.py @@ -0,0 +1,137 @@ +#! /bin/env python + +#/*************************************************************************** +# fevendata.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +"""This is the main entry point for all evenja applications""" + +from fstarter import Fstarter + +from returncodes import RET_OK +from returncodes import RET_MEMORYSPACE +from returncodes import RET_NOPARAMS + +#---------------------------------------------------------------------------- + +import sys, getopt, os.path, string + + +shorts = 'hvtc' +longs = ['help','version','trace','compile'] +vers = '0.0.9' + + +#---------------------------------------------------------------------------- +def usage(name): + print 'usage :'+name+' ['+shorts+'] xml_file' + print ' h - help' + print ' v - version' + print ' t - trace\tfstarter.execute() will print all received messages' + print ' c - compile\tclean and rebuild files' + + +#---------------------------------------------------------------------------- +def version(name): + print(name+', version '+str(vers)) + print 'written by jeremy zurcher tzurtch@bluemail.ch' + print 'stolen from evenja-2.9.72-beta1, written by Fabian Padilla fp@bridgethink.com' + print '''\nthis version should be ok, but isn't written in "pure" python style ;))''' + print 'the work is in progress ...' + + +#---------------------------------------------------------------------------- +def main(): + path,name=os.path.split(sys.argv[0]) + trace = False + try: + opts,args = getopt.getopt(sys.argv[1:],shorts,longs) + except getopt.GetoptError: + print('try '+name+' --help') + sys.exit(0) + + for opt,arg in opts: + if opt in ('-'+shorts[0],'--'+longs[0]): + usage(name) + sys.exit(0) + if opt in ('-'+shorts[1],'--'+longs[1]): + version(name) + sys.exit(0) + if opt in ('-'+shorts[2],'--'+longs[2]): + trace = True + if opt in ('-'+shorts[3],'--'+longs[3]): + L=[ 'OSconfig.py',\ + 'OSlinux.py',\ + 'evenjastrings.py',\ + 'fconfig.py',\ + 'fdoor_cout.py',\ + 'fdoor_file.py',\ + 'fevendoor.py',\ + 'fevenboard.py',\ + 'fevendata.py',\ + 'fevenprg.py',\ + 'flist.py',\ + 'flisthash.py',\ + 'fport.py',\ + 'fportbkpevendata.py',\ + 'fportlist.py',\ + 'fportlisthash.py',\ + 'fposition.py',\ + 'fprg_concat.py',\ + 'frouter.py',\ + 'fstarter.py',\ + 'fstringhash.py',\ + 'fviewer.py',\ + 'globalvars.py',\ + 'returncodes.py'] + if sys.platform != 'linux2': + print "Would you please install an acceptable OS, thanks." + os.system('rm *.pyc *.pyo 2>/dev/null') + for I in L: + print 'python -O -W all '+I + os.system('python -O -W all '+I) + sys.exit(0) + + if not args: + usage(name) + sys.exit(1) + + # here we go ... with this buggy verion ... + + starter = Fstarter() + + if starter: + ret = starter.start(args[0]) + if ret == RET_OK: + starter.execute(trace) # launch the stuff + ret = starter.end() # for dynamc configuration + else: + print "can't start the starter *sigh*" + sys.exit(-1) + else: + print "can't instanciate the starter ... really bad !!!!" + sys.exit(-1) + sys.exit(0) + + +#---------------------------------------------------------------------------- +if __name__=='__main__': + main() + diff --git a/returncodes.py b/returncodes.py new file mode 100644 index 0000000..2d8b50a --- /dev/null +++ b/returncodes.py @@ -0,0 +1,58 @@ +#/*************************************************************************** +# fevendata.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +"""/** This header includes the retrurn codes for the evenja, evendoor, starter and evenRouter packages. */""" + + +#// If all is OK ( most of the time ?? ;) ) +RET_OK = 0 +RET_KO = -1 + +#// Standard return problems (memory, timeout, etc...) +RET_MEMORYSPACE = -10 + +#// developpement errors +RET_NOTIMPLEMENTED = -1001 #/* Method not already implmented*/ +RET_NOTIMPLEMENTED_TXT = "NOT IMPLEMENTED" #/* Text version */ + +#// Erros which can be generated at start of the application (before the rooms are working) +RET_NOPARAMS = -2001 #// The parameter is not available + +#// Returns in normal usage of the evenja and evendoor technology need to be managed by the class +RET_INTERNAL = -10000 +#RET_FILENAME2LONG = RET_INTERNAL - 1 #/* The FileName is too long > MAX_PATH */ +#RET_STRING2LONG = RET_INTERNAL - 2 #/* String is too long */ +RET_PORTEXIST = RET_INTERNAL - 3 #/* A router exist with the same name */ +RET_NONAME = RET_INTERNAL - 4 #/* No name exist for this port */ +RET_NOINFOS = RET_INTERNAL - 5 #/* No informations */ + +#// Returns in normal usage of the tree or ldap used for configuration or data storage +RET_TREE = -11000 +RET_CANNOTACCESS = RET_TREE - 1 #/* Cannot access the stream (file or other) */ +RET_CANNOTCREATE = RET_TREE - 2 #/* The creation of the document is not possible */ +RET_CANNOTEND = RET_TREE - 3 #/* Cannot end the stream (save file or other save datas) */ +RET_NONODESELECTED = RET_TREE - 4 #/* Current = 0 */ +RET_NOTEXIST = RET_TREE - 5 #/* {Next,Prev,Children or Parent} Node not exist and cannot be set as the current */ +RET_NOTFOUND = RET_TREE - 6 #/* Nothing found, in the search */ + +RET_CANNOTSAVE = RET_TREE - 7 #/* Cannot save the file */ +#RET_ = "" + |