예제 #1
0
파일: Config.py 프로젝트: dxiao/SmootLight
def resolveInheritance(el):
    """In place resolution of inheritence.  Doesn't return anything."""
    parentClass = el.find('InheritsFrom')
    if parentClass != None:
        parentTree = loadConfigFile(parentClass.text)
        if parentTree == None:
            main_log.warn('Inheritance Failed.  ' + parentClass.text + 'does not exist')
            main_log.error('Inheritance Failed.  ' + parentClass.text + 'does not exist')
            return el
        el = compositeXMLTrees(parentTree, el) 
        el.remove(parentClass) #get rid of the inheritance flag
예제 #2
0
 def processResponse(self, sensorInputs, recursiveInputs):
     ret = []
     for data in sensorInputs:
         print data
         data = dict(data)
         if self.mappingkey in data:
             try:
                 data['Location'], data['Color'] =\
                     self.mapping[data[self.mappingkey]] 
                 ret.append(data)
             except:
                 main_log.warn('Bad mapping key.  Expanding Color Zones.')
     return (ret,[])
예제 #3
0
 def processResponse(self, sensorInputs, recursiveInputs):
     ret = []
     for data in sensorInputs:
         print data
         data = dict(data)
         if self.mappingkey in data:
             try:
                 data['Location'], data['Color'] =\
                     self.mapping[data[self.mappingkey]]
                 ret.append(data)
             except:
                 main_log.warn('Bad mapping key.  Expanding Color Zones.')
     return (ret, [])
예제 #4
0
def resolveInheritance(el):
    """In place resolution of inheritence.  Doesn't return anything."""
    parentClass = el.find('InheritsFrom')
    if parentClass != None:
        parentTree = loadConfigFile(parentClass.text)
        if parentTree == None:
            main_log.warn('Inheritance Failed.  ' + parentClass.text +
                          'does not exist')
            main_log.error('Inheritance Failed.  ' + parentClass.text +
                           'does not exist')
            return el
        el = compositeXMLTrees(parentTree, el)
        el.remove(parentClass)  #get rid of the inheritance flag
예제 #5
0
def registerComponent(component, cid=None):
    global Registry
    if cid != None:
        Registry[cid] = component
    else:
        cid = component['Id']
        if cid == None:
            cid = getNewId() 
            component['Id'] = cid 
            main_log.debug(cid + 'automatically assigned')
        if cid in Registry:
            main_log.warn(cid + 'overwritten.')
        Registry[cid] = component
    return cid
예제 #6
0
def compositeXMLTrees(parentTree, overridingTree):
    """XML tree composition.  Returns the resulting tree, but happens in-place in the overriding
    tree."""
    #TODO: break up into sub-methods, change it to use .find()
    if parentTree == None:
        return overridingTree
    if overridingTree == None:
        return parentTree  #TODO: this will probably cause a bug since it isn't in-place on
        #overridingTree
    parentTree = getElement(parentTree)
    overridingTree = getElement(overridingTree)
    parentItems = parentTree.getchildren()
    overrideItems = overridingTree.getchildren()
    #first, lets figure out what tags we have in the override tree:
    tagCollection = [el.tag for el in overrideItems
                     ]  #we can speed this up with a dict if necessary
    for item in parentItems:
        if not item.tag in tagCollection or 'Append' in item.attrib:  #no override
            overridingTree.insert(-1, item)  #insert the new item at the end
        else:
            #do we merge or replace?
            intersectingElements = findElementsByTag(item.tag, overrideItems)
            if len(intersectingElements) > 1:
                main_log.warn(
                    'ABUSE!  Override of multiple items isn\'t well defined.  Don\'t do\
                it!')
            interEl = intersectingElements[0]
            mode = DEFAULT_OVERRIDE_MODE
            if Strings.OVERRIDE_BEHAVIOR in interEl.attrib:
                mode = interEl.attrib[Strings.OVERRIDE_BEHAVIOR]
            if mode != 'Replace' and mode != 'Merge':
                main_log.warn('Bad Override Mode.  Choosing to replace.')
                mode = 'Replace'
            if mode == 'Replace':
                pass  #we don't need to do anything
            if mode == 'Merge':
                interEl = compositeXMLTrees(item, interEl)
    for item in overrideItems:  #resolve appendages
        if item.tag == 'APPEND':
            children = item.getchildren()
            for child in children:
                overrideItems.insert(-1, child)
            overrideItems.remove(item)
    return overridingTree
예제 #7
0
파일: Config.py 프로젝트: dxiao/SmootLight
def compositeXMLTrees(parentTree, overridingTree): 
    """XML tree composition.  Returns the resulting tree, but happens in-place in the overriding
    tree."""
    #TODO: break up into sub-methods, change it to use .find()
    if parentTree == None:
        return overridingTree
    if overridingTree == None:
        return parentTree #TODO: this will probably cause a bug since it isn't in-place on
        #overridingTree
    parentTree = getElement(parentTree)
    overridingTree = getElement(overridingTree)
    parentItems = parentTree.getchildren()
    overrideItems = overridingTree.getchildren()
    #first, lets figure out what tags we have in the override tree:
    tagCollection = [el.tag for el in overrideItems] #we can speed this up with a dict if necessary
    for item in parentItems:
        if not item.tag in tagCollection: #no override 
            overridingTree.insert(-1, item) #insert the new item at the end
        else:
            #do we merge or replace?
            intersectingElements = findElementsByTag(item.tag, overrideItems)
            if len(intersectingElements) > 1:
                main_log.warn('ABUSE!  Override of multiple items isn\'t well defined.  Don\'t do\
                it!')
            interEl = intersectingElements[0]
            mode = DEFAULT_OVERRIDE_MODE
            if Strings.OVERRIDE_BEHAVIOR in interEl.attrib:
                mode = interEl.attrib[Strings.OVERRIDE_BEHAVIOR] 
            if mode != 'Replace' and mode != 'Merge':
                main_log.warn('Bad Override Mode.  Choosing to replace.')
                mode = 'Replace'
            if mode == 'Replace':
                pass #we don't need to do anything
            if mode == 'Merge': 
                interEl = compositeXMLTrees(item, interEl)
    for item in overrideItems: #resolve appendages
        if item.tag == 'APPEND':
            children = item.getchildren()
            for child in children:
                overrideItems.insert(-1, child)
            overrideItems.remove(item)
    return overridingTree
예제 #8
0
    def processResponse(self, sensorInputs, recursiveInputs):
        response = sensorInputs
        for behaviorId in self['ChainedBehaviors']:
            behavior = compReg.getComponent(behaviorId)
            if behaviorId in self.feedback:
                recurrence = self.feedback[behaviorId]
            else:
                recurrence = []
            (response,recurrence) = behavior.immediateProcessInput(response,\
                    recurrence)

            if behaviorId in self.hooks: #process recursive hook if there is one
                hookBehavior = compReg.getComponent(self.hooks[behaviorId])
                #we feed its recurrence in as input to the behavior.  
                (recurrence, hookRecurrence) = \
                hookBehavior.immediateProcessInput(recurrence, \
                        [])
                if hookRecurrence != []:
                    main_log.warn('Hook recurrences are not currently supported.') 
            self.feedback[behaviorId] = recurrence 
        return (response, [])
예제 #9
0
    def processResponse(self, sensorInputs, recursiveInputs):
        response = sensorInputs
        for behaviorId in self['ChainedBehaviors']:
            behavior = compReg.getComponent(behaviorId)
            if behaviorId in self.feedback:
                recurrence = self.feedback[behaviorId]
            else:
                recurrence = []
            (response,recurrence) = behavior.immediateProcessInput(response,\
                    recurrence)

            if behaviorId in self.hooks:  #process recursive hook if there is one
                hookBehavior = compReg.getComponent(self.hooks[behaviorId])
                #we feed its recurrence in as input to the behavior.
                (recurrence, hookRecurrence) = \
                hookBehavior.immediateProcessInput(recurrence, \
                        [])
                if hookRecurrence != []:
                    main_log.warn(
                        'Hook recurrences are not currently supported.')
            self.feedback[behaviorId] = recurrence
        return (response, [])