diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2012-04-13 21:16:12 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2012-04-13 21:16:12 +0200 |
commit | eeb9927c89d6d2425a74c33ff8773bceba39af1c (patch) | |
tree | e5e770fc041fa27b6e13a78dc9c3dc3f75c7c213 | |
parent | 99561b834dbd9d52b83aa7b0fb980431fa1aa056 (diff) | |
download | pyevenja-master.zip pyevenja-master.tar.gz |
-rw-r--r-- | OSconfig.py | 2 | ||||
-rw-r--r-- | OSlinux.py | 2 | ||||
-rw-r--r-- | evenjastrings.py | 16 | ||||
-rw-r--r-- | fconfig.py | 1042 | ||||
-rw-r--r-- | fdoor_cout.py | 22 | ||||
-rw-r--r-- | fdoor_file.py | 102 | ||||
-rw-r--r-- | fevenboard.py | 60 | ||||
-rw-r--r-- | fevendata.py | 1166 | ||||
-rw-r--r-- | fevendoor.py | 136 | ||||
-rw-r--r-- | fevenprg.py | 68 | ||||
-rw-r--r-- | flist.py | 208 | ||||
-rw-r--r-- | flisthash.py | 180 | ||||
-rw-r--r-- | fport.py | 210 | ||||
-rw-r--r-- | fportbkpevendata.py | 54 | ||||
-rw-r--r-- | fportlist.py | 16 | ||||
-rw-r--r-- | fportlisthash.py | 20 | ||||
-rw-r--r-- | fposition.py | 398 | ||||
-rw-r--r-- | fprg_concat.py | 42 | ||||
-rw-r--r-- | frouter.py | 374 | ||||
-rw-r--r-- | fstarter.py | 188 | ||||
-rw-r--r-- | fstringhash.py | 192 | ||||
-rw-r--r-- | fviewer.py | 16 | ||||
-rw-r--r-- | globalvars.py | 82 | ||||
-rw-r--r-- | pyevenja.py | 166 | ||||
-rw-r--r-- | returncodes.py | 8 |
25 files changed, 2385 insertions, 2385 deletions
diff --git a/OSconfig.py b/OSconfig.py index f1d08fb..3b822b8 100644 --- a/OSconfig.py +++ b/OSconfig.py @@ -20,6 +20,6 @@ # """only the Linux version available""" - + from OSlinux import * @@ -24,7 +24,7 @@ __all__ = ["MAX_TREELEVEL","START_ELEMENTS","INC_ELEMENTS"] -MAX_TREELEVEL = 8 # not used yet +MAX_TREELEVEL = 8 # not used yet # only used in flisthash.py tests START_ELEMENTS = 100 #/* Start with a list of 100 elements */ diff --git a/evenjastrings.py b/evenjastrings.py index ef10bc6..fd30858 100644 --- a/evenjastrings.py +++ b/evenjastrings.py @@ -74,7 +74,7 @@ ACT_SYS_CONTINUE = "SYS_CONTINUE" #/** Continue the work inside the port (af 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. @@ -131,13 +131,13 @@ 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' +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 @@ -35,19 +35,19 @@ - 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. - + LDAP or others, without having to update the evenja kernel. + *@author Fabian Padilla */""" __all__ = ["Fconfig"] try: - import libxml2 + import libxml2 except: - print "libxml2 not available ... aborting !!" - import sys - sys.exit(1) + print "libxml2 not available ... aborting !!" + import sys + sys.exit(1) from flist import Flist from fstringhash import FstringHash @@ -55,532 +55,532 @@ 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 - + """ 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) - + 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 + 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 + 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 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() - 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() + 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 index 322596b..31507bc 100644 --- a/fdoor_cout.py +++ b/fdoor_cout.py @@ -20,7 +20,7 @@ # """ doc """ - + __all__ = ["Fdoor_cout"] @@ -30,13 +30,13 @@ 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 + 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 index d2819b6..0606bac 100644 --- a/fdoor_file.py +++ b/fdoor_file.py @@ -35,55 +35,55 @@ 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) + def __init__(self): + FevenDoor.__init__(self) # force constructor + self.file = None - # 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 + 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 index 6aecee2..10b314e 100644 --- a/fevenboard.py +++ b/fevenboard.py @@ -52,33 +52,33 @@ 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 - + 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 index 6cb7a05..c9869df 100644 --- a/fevendata.py +++ b/fevendata.py @@ -28,18 +28,18 @@ 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 + import libxml2 except: - print "libxml2 not available ... aborting !!" - import sys - sys.exit(1) + print "libxml2 not available ... aborting !!" + import sys + sys.exit(1) from time import time @@ -52,591 +52,591 @@ import evenjastrings as ES import returncodes as RC # TzurTcH - speed up ;)) -PREF = ES.XML_DESTINATION + ES.TREE_SEPARATOR_STR +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") + 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() + 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 index a378844..2e4d8a5 100644 --- a/fevendoor.py +++ b/fevendoor.py @@ -27,7 +27,7 @@ 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 */""" @@ -48,75 +48,75 @@ 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() + 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) + 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() + """ """ + 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 index caa7dac..158e458 100644 --- a/fevenprg.py +++ b/fevenprg.py @@ -26,7 +26,7 @@ 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 */""" @@ -38,36 +38,36 @@ 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) - + """ 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) + @@ -37,110 +37,110 @@ __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) - + """ 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() + 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 index 345cac4..5134931 100644 --- a/flisthash.py +++ b/flisthash.py @@ -38,96 +38,96 @@ 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 - + """ 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() + 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() @@ -35,7 +35,7 @@ */""" __all__ =["Fport"] - + from flist import Flist from fconfig import Fconfig from fevendata import FevenData @@ -46,108 +46,108 @@ 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 + """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 index 3533f82..cfaa39b 100644 --- a/fportbkpevendata.py +++ b/fportbkpevendata.py @@ -34,33 +34,33 @@ from fport import Fport from evenjastrings import ACT_ERROR class FportBkpEvenData(Fport): - """This class is a wrapper arounf Fport class for security purpose""" + """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 __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 __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) + 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 index 38da1aa..efa0b7c 100644 --- a/fportlist.py +++ b/fportlist.py @@ -22,7 +22,7 @@ """/** Inherited from Fport to add a listHash. function : maintain a list in - FevenDoor : + FevenDoor : description : work as Fport. @@ -36,12 +36,12 @@ from flist import Flist class FportList(Fport): - """This class is nothing but a fport with a flist as atribute""" + """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 __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" + def __str__(self): + return "\t"+Fport.__str__(self)+\ + "FportList - list : "+str(self.list)+"\n" diff --git a/fportlisthash.py b/fportlisthash.py index 1fffd3c..908c4d6 100644 --- a/fportlisthash.py +++ b/fportlisthash.py @@ -40,18 +40,18 @@ */""" __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" + """ 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 index 09cc62e..308ceb9 100644 --- a/fposition.py +++ b/fposition.py @@ -22,7 +22,7 @@ """/** 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 + Format example : www.revena.com/room1/room2/port:normal description : method "setPosition" set all position informations this mean - compute @@ -46,206 +46,206 @@ 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 + """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() + 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 index 8ce3556..dc3f308 100644 --- a/fprg_concat.py +++ b/fprg_concat.py @@ -30,24 +30,24 @@ 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 + 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 @@ -32,7 +32,7 @@ __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 @@ -50,193 +50,193 @@ 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) + 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() + 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 index 28567e7..88dd7c0 100644 --- a/fstarter.py +++ b/fstarter.py @@ -19,7 +19,7 @@ # from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> # -"""/** First class of evenja and evendoor to be created. +"""/** 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 @@ -37,102 +37,102 @@ 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) + """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() + 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 index dbde39c..bd36618 100644 --- a/fstringhash.py +++ b/fstringhash.py @@ -22,15 +22,15 @@ # 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() +# ob_sval == char* +# ob_size == strlen() # # int # _PyString_Eq(PyObject *o1, PyObject *o2) # { -# PyStringObject *a, *b; -# a = (PyStringObject*)o1; -# b = (PyStringObject*)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; @@ -40,21 +40,21 @@ # string_hash(PyStringObject *a) # { # register int len; -# register unsigned char *p; -# register long x; +# 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; +# 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; # } @@ -62,11 +62,11 @@ """/** 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). + + 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 */""" @@ -74,83 +74,83 @@ __all__ =["FstringHash"] try: - import hashlib + import hashlib except: - print "no MD5 capabilities ... aborting" - import sys - sys.exit(1) + 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 + """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() + 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() @@ -30,9 +30,9 @@ access the head information : - source - destination - and access the data information. + and access the data information. WITHOUT HAVING TO DO A VERSIONNING. - + *@author Fabian Padilla */""" @@ -42,10 +42,10 @@ 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 + """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" + def __str__(self): + return "\t"+Fport.__str__(self)+\ + "Fviewer - (null)\n" diff --git a/globalvars.py b/globalvars.py index dcd397d..ed2284a 100644 --- a/globalvars.py +++ b/globalvars.py @@ -46,22 +46,22 @@ import evenjastrings as ES #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 -# +# +# 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) @@ -106,29 +106,29 @@ 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() +# 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/pyevenja.py b/pyevenja.py index 9fcc574..1a2b6b4 100644 --- a/pyevenja.py +++ b/pyevenja.py @@ -41,97 +41,97 @@ 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' + 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 ...' + 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) - + 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() + main() diff --git a/returncodes.py b/returncodes.py index 2d8b50a..b89b6fa 100644 --- a/returncodes.py +++ b/returncodes.py @@ -30,11 +30,11 @@ RET_KO = -1 RET_MEMORYSPACE = -10 #// developpement errors -RET_NOTIMPLEMENTED = -1001 #/* Method not already implmented*/ -RET_NOTIMPLEMENTED_TXT = "NOT IMPLEMENTED" #/* Text version */ +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 +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 @@ -54,5 +54,5 @@ RET_NOTEXIST = RET_TREE - 5 #/* {Next,Prev,Children or Parent} Node not RET_NOTFOUND = RET_TREE - 6 #/* Nothing found, in the search */ RET_CANNOTSAVE = RET_TREE - 7 #/* Cannot save the file */ -#RET_ = "" +#RET_ = "" |