Ejemplo n.º 1
0
    def handleTaskOutput(self, sourceTag, seqNr, output, subnetOutput,
                         warnMsg):
        """Handle the output of a finished task that is generated from
           this active instance.

           NOTE: assumes that the ai is locked with self.outputLock!!!"""
        #log.debug("Handling task %s output"%self.getCanonicalName())
        # first set things locally
        changedInstances=set()
        # Round 1: set the new output values
        if output is not None:
            for out in output:
                outItems=vtype.parseItemList(out.name)
                # now get the actual entry in the output value tree
                oval=self.outputVal.getCreateSubValue(outItems,
                                                setCreateSourceTag=sourceTag)
                #log.debug("Handling output for %s"%(oval.getFullName()))
                # remember it
                out.item=oval
                if oval is None:
                    raise ActiveError(
                              "output '%s' not found in instance %s of %s"%
                              (out.name, self.getCanonicalName(),
                               self.function.getName()))
                #log.debug("Updated value name=%s"%(oval.getFullName()))
                oval.update(out.val, seqNr, sourceTag)
                #log.debug("1 - Marking update for %s"%oval.getFullName())
                oval.markUpdated(True)
                # now stage all the inputs
                oval.propagate(sourceTag, seqNr)
        if subnetOutput is not None:
            for out in subnetOutput:
                outItems=vtype.parseItemList(out.name)
                oval=self.subnetOutputVal.getCreateSubValue(outItems,
                                                   setCreateSourceTag=sourceTag)
                #log.debug("Handling output for %s"%(oval.getFullName()))
                # remember it
                out.item=oval
                if oval is None:
                    raise ActiveError(
                        "subnet output '%s' not found in instance %s of %s"%
                        (out.name, self.getCanonicalName(),
                         self.function.getName()))
                #log.debug("Updated value name=%s"%(oval.getFullName()))
                oval.update(out.val, seqNr, sourceTag)
                #log.debug("2 - Marking update for %s"%oval.getFullName())
                oval.markUpdated(True)
                # now stage all the inputs
                oval.propagate(sourceTag, seqNr)
        # Round 2: now alert the receiving active instances
        if output is not None:
            for out in output:
                out.item.notifyListeners(sourceTag, seqNr)
        if subnetOutput is not None:
            for out in subnetOutput:
                out.item.notifyListeners(sourceTag, seqNr)
        self.outputVal.setUpdated(False)
        self.subnetOutputVal.setUpdated(False)
        self.msg.setWarning(warnMsg)
Ejemplo n.º 2
0
 def isSubnetOutputUpdated(self, itemname):
     """Check whether a particular subnet output has been updated."""
     items=vtype.parseItemList(itemname)
     retv=self.subnetOutputs.getSubValue(items)
     if retv is None:
         return False
     return retv.isUpdated()
Ejemplo n.º 3
0
 def __init__(
         self,
         project,
         itemName,
         #activeInstance, direction, ioItemList,
         literal,
         sourceType,
         printName):
     """Object to hold an set value for an arbitrary active instance."""
     self.itemName = itemName
     self.project = project
     #instanceName,direction,ioItemList=connection.splitIOName(itemName,
     #                                                         None)
     #instance=self.activeNetwork.getNamedActiveInstance(instanceName)
     self.itemList = vtype.parseItemList(itemName)
     item = project.getClosestSubValue(self.itemList)
     if not isinstance(item, active_value.ActiveValue):
         raise SetError("Value of '%s' cannot be set" % itemName)
     #self.activeInstance=item.owner
     self.closestVal = item
     #self.activeInstance=activeInstance
     #self.direction=direction
     #self.ioItemList=ioItemList
     self.literal = literal
     self.sourceType = sourceType
     if printName is not None:
         self.printName = printName
     else:
         self.printName = literal
Ejemplo n.º 4
0
 def getNamedValue(self, itemname):
     """Get a value for a specific name according to the rule
        [instance]:[instance].[ioitem]."""
     with self.updateLock:
         itemlist=vtype.parseItemList(itemname)
         item=self.getSubValue(itemlist)
         return item
Ejemplo n.º 5
0
 def isSubnetOutputUpdated(self, itemname):
     """Check whether a particular subnet output has been updated."""
     items = vtype.parseItemList(itemname)
     retv = self.subnetOutputs.getSubValue(items)
     if retv is None:
         return False
     return retv.isUpdated()
Ejemplo n.º 6
0
 def getNamedValue(self, itemname):
     """Get a value for a specific name according to the rule
        [instance]:[instance].[ioitem]."""
     with self.updateLock:
         itemlist = vtype.parseItemList(itemname)
         item = self.getSubValue(itemlist)
         return item
Ejemplo n.º 7
0
 def getNamedInstance(self, instname):
     pathname = keywords.fixID(instname)
     with self.updateLock:
         itemlist = vtype.parseItemList(pathname)
         item = self.getSubValue(itemlist)
     if not isinstance(item, active_inst.ActiveInstance):
         raise ProjectError("%s is not an active instance" % instname)
     return item
Ejemplo n.º 8
0
 def getNamedInstance(self, instname):
     pathname=keywords.fixID(instname)
     with self.updateLock:
         itemlist=vtype.parseItemList(pathname)
         item=self.getSubValue(itemlist)
     if not isinstance(item, active_inst.ActiveInstance):
         raise ProjectError("%s is not an active instance"%instname)
     return item
Ejemplo n.º 9
0
 def getSubnetOutput(self, itemname):
     """Get the actual value associated with a subnet output."""
     items = vtype.parseItemList(itemname)
     retv = self.subnetOutputs.getSubValue(items)
     if retv is None:
         return None
     if retv.fileValue is not None:
         return retv.fileValue.getAbsoluteName()
     else:
         # if we're running in an external function, the current directory
         # is the base dir, so we don't need to distinguish between them
         return retv.value
Ejemplo n.º 10
0
 def getSubnetOutput(self, itemname):
     """Get the actual value associated with a subnet output."""
     items=vtype.parseItemList(itemname)
     retv=self.subnetOutputs.getSubValue(items)
     if retv is None:
         return None
     if retv.fileValue is not None:
         return retv.fileValue.getAbsoluteName()
     else:
         # if we're running in an external function, the current directory
         # is the base dir, so we don't need to distinguish between them
         return retv.value
Ejemplo n.º 11
0
 def activate(self, pathname):
     """Activate all active instances."""
     pathname = keywords.fixID(pathname)
     with self.updateLock:
         itemlist = vtype.parseItemList(pathname)
         item = self.getSubValue(itemlist)
         ret = dict()
         if isinstance(item, active_inst.ActiveInstance):
             item.activate()
         elif isinstance(item, Project):
             item.network.activateAll()
         else:
             raise ProjectError("%s is not an instance" % pathname)
Ejemplo n.º 12
0
 def activate(self, pathname):
     """Activate all active instances."""
     pathname=keywords.fixID(pathname)
     with self.updateLock:
         itemlist=vtype.parseItemList(pathname)
         item=self.getSubValue(itemlist)
         ret=dict()
         if isinstance(item, active_inst.ActiveInstance):
             item.activate()
         elif isinstance(item, Project):
             item.network.activateAll()
         else:
             raise ProjectError("%s is not an instance"%pathname)
Ejemplo n.º 13
0
 def rerun(self, pathname, recursive, clearError, outf):
     """Re-run and optionally clear an error on an item."""
     pathname = keywords.fixID(pathname)
     with self.updateLock:
         itemlist = vtype.parseItemList(pathname)
         item = self.getSubValue(itemlist)
         if isinstance(item, active_inst.ActiveInstance):
             ret = item.rerun(recursive, clearError, outf)
             if ret == 0:
                 if clearError:
                     outf.write("No errors cleared.")
                 else:
                     outf.write("No reruns performed.")
         else:
             raise ProjectError("%s is not an instance" % pathname)
Ejemplo n.º 14
0
 def deactivate(self, pathname):
     """De-activate all active instances contained in pathname (or
        everything if pathname is empty)."""
     pathname = keywords.fixID(pathname)
     with self.updateLock:
         itemlist = vtype.parseItemList(pathname)
         item = self.getSubValue(itemlist)
         ret = dict()
         log.debug("%s" % str(item))
         if isinstance(item, active_inst.ActiveInstance):
             item.deactivate()
         elif isinstance(item, Project):
             item.network.deactivateAll()
         else:
             raise ProjectError("%s is not an instance" % pathname)
Ejemplo n.º 15
0
 def rerun(self, pathname, recursive, clearError, outf):
     """Re-run and optionally clear an error on an item."""
     pathname=keywords.fixID(pathname)
     with self.updateLock:
         itemlist=vtype.parseItemList(pathname)
         item=self.getSubValue(itemlist)
         if isinstance(item, active_inst.ActiveInstance):
             ret=item.rerun(recursive, clearError, outf)
             if ret==0:
                 if clearError:
                     outf.write("No errors cleared.")
                 else:
                     outf.write("No reruns performed.")
         else:
             raise ProjectError("%s is not an instance"%pathname)
Ejemplo n.º 16
0
 def getInput(self, itemname):
     """Get the actual value associated with an input."""
     items=vtype.parseItemList(itemname)
     retv=self.inputs.getSubValue(items)
     if retv is None:
         return None
     if retv is not None and retv.fileValue is not None:
         return retv.fileValue.getAbsoluteName()
     else:
         # if we're running in an external function, the current directory
         # is the base dir, so we don't need to distinguish between them
         if retv.value is not None and retv.type.isSubtype(vtype.fileType):
             return os.path.join(self.baseDir, retv.value)
         else:
             return retv.value
Ejemplo n.º 17
0
 def getInput(self, itemname):
     """Get the actual value associated with an input."""
     items = vtype.parseItemList(itemname)
     retv = self.inputs.getSubValue(items)
     if retv is None:
         return None
     if retv is not None and retv.fileValue is not None:
         return retv.fileValue.getAbsoluteName()
     else:
         # if we're running in an external function, the current directory
         # is the base dir, so we don't need to distinguish between them
         if retv.value is not None and retv.type.isSubtype(vtype.fileType):
             return os.path.join(self.baseDir, retv.value)
         else:
             return retv.value
Ejemplo n.º 18
0
 def deactivate(self, pathname):
     """De-activate all active instances contained in pathname (or
        everything if pathname is empty)."""
     pathname=keywords.fixID(pathname)
     with self.updateLock:
         itemlist=vtype.parseItemList(pathname)
         item=self.getSubValue(itemlist)
         ret=dict()
         log.debug("%s"%str(item))
         if isinstance(item, active_inst.ActiveInstance):
             item.deactivate()
         elif isinstance(item, Project):
             item.network.deactivateAll()
         else:
             raise ProjectError("%s is not an instance"%pathname)
Ejemplo n.º 19
0
 def getDebugInfo(self, itemname):
     """Give debug info about a particular item."""
     global profile
     outf = StringIO()
     if itemname == "":
         outf.write("the item was empty")
         if profile:
             all_objects = muppy.get_objects()
             sum1 = summary.summarize(all_objects)
             summary.print_(sum1, 100)
             ib = refbrowser.InteractiveBrowser(self)
             ib.main()
         return outf.getvalue()
     itemname = keywords.fixID(itemname)
     itemlist = vtype.parseItemList(itemname)
     item = self.getSubValue(itemlist)
     item.writeDebug(outf)
     return outf.getvalue()
Ejemplo n.º 20
0
 def getDebugInfo(self, itemname):
     """Give debug info about a particular item."""
     global profile
     outf=StringIO()
     if itemname == "":
         outf.write("the item was empty")
         if profile:
             all_objects = muppy.get_objects()
             sum1 = summary.summarize(all_objects)
             summary.print_(sum1, 100)
             ib = refbrowser.InteractiveBrowser(self)
             ib.main()
         return outf.getvalue()
     itemname=keywords.fixID(itemname)
     itemlist=vtype.parseItemList(itemname)
     item=self.getSubValue(itemlist)
     item.writeDebug(outf)
     return outf.getvalue()
Ejemplo n.º 21
0
 def __init__(self, project, itemName, 
              #activeInstance, direction, ioItemList, 
              literal, sourceType, printName):
     """Object to hold an set value for an arbitrary active instance."""
     self.itemName=itemName
     self.project=project
     #instanceName,direction,ioItemList=connection.splitIOName(itemName,
     #                                                         None)
     #instance=self.activeNetwork.getNamedActiveInstance(instanceName)
     self.itemList=vtype.parseItemList(itemName)
     item=project.getClosestSubValue(self.itemList)
     if not isinstance(item, active_value.ActiveValue):
         raise SetError("Value of '%s' cannot be set"%itemName)
     #self.activeInstance=item.owner
     self.closestVal=item
     #self.activeInstance=activeInstance
     #self.direction=direction
     #self.ioItemList=ioItemList
     self.literal=literal
     self.sourceType=sourceType
     if printName is not None:
         self.printName=printName
     else:
         self.printName=literal
Ejemplo n.º 22
0
 def getGraph(self, pathname):
     """Get an graph description based on a path name according to the rule
        [instance]:[instance]."""
     pathname = keywords.fixID(pathname)
     with self.updateLock:
         itemlist = vtype.parseItemList(pathname)
         item = self.getSubValue(itemlist)
         ret = dict()
         if item is not None:
             if isinstance(item, active_inst.ActiveInstance):
                 net = item.network
                 ret["name"] = pathname
                 ret["instances"] = net.getActiveInstanceList(True, True)
                 ret["connections"] = net.getConnectionList()
             elif isinstance(item, Project):
                 net = item.network
                 ret["name"] = pathname
                 ret["instances"] = net.getActiveInstanceList(True, True)
                 ret["connections"] = net.getConnectionList()
             else:
                 ret["name"] = pathname
                 ret["instances"] = []
                 ret["connections"] = []
         return ret
Ejemplo n.º 23
0
 def getGraph(self, pathname):
     """Get an graph description based on a path name according to the rule
        [instance]:[instance]."""
     pathname=keywords.fixID(pathname)
     with self.updateLock:
         itemlist=vtype.parseItemList(pathname)
         item=self.getSubValue(itemlist)
         ret=dict()
         if item is not None:
             if isinstance(item, active_inst.ActiveInstance):
                 net=item.network
                 ret["name"]=pathname
                 ret["instances"]=net.getActiveInstanceList(True, True)
                 ret["connections"]=net.getConnectionList()
             elif isinstance(item, Project):
                 net=item.network
                 ret["name"]=pathname
                 ret["instances"]=net.getActiveInstanceList(True, True)
                 ret["connections"]=net.getConnectionList()
             else:
                 ret["name"]=pathname
                 ret["instances"]=[]
                 ret["connections"]=[]
         return ret
Ejemplo n.º 24
0
 def getSubnetOutputValue(self, itemname):
     """Get the Value object associated with an input."""
     items = vtype.parseItemList(itemname)
     retv = self.subnetOutputs.getSubValue(items)
     return retv
Ejemplo n.º 25
0
 def getNamedItemList(self, pathname):
     """Get an list based on a path name according to the rule
        [instance]:[instance]"""
     pathname=keywords.fixID(pathname)
     with self.updateLock:
         itemlist=vtype.parseItemList(pathname)
         item=self.getSubValue(itemlist)
         ret=dict()
         if item is None:
             ret["type"]="Not found: "
             ret["name"]=pathname
         elif isinstance(item, value.Value):
             # it is an active I/O item
             tp=item.getType()
             ret["type"]="input/output value"
             ret["name"]=pathname
             if tp is not None:
                 ret["typename"]=tp.getName()
                 ret["value-type"]=tp.jsonDescribe()
             else:
                 ret["typename"]="Not found"
             if tp.isSubtype(vtype.recordType):
                 ret["subitems"]=[]
                 keys=tp.getMemberKeys()
                 for key in keys:
                     mem=tp.getRecordMember(key)
                     subi=dict()
                     subi["name"]=key
                     subi["type"]=mem.type.getName()
                     #subi["value-type"]=mem.type.jsonDescribe()
                     optstr=""
                     conststr=""
                     if mem.isOptional():
                         subi["optional"]=1
                     if mem.isConst():
                         subi["const"]=1
                     if mem.isComplete():
                         subi["complete"]=1
                     if mem.desc is not None:
                         subi["desc"]=mem.desc.get()
                     ret["subitems"].append( subi )
             elif (tp.isSubtype(vtype.arrayType) or
                   tp.isSubtype(vtype.dictType)):
                 mem=tp.getMembers()
                 subi={"type" : mem.getName()}
                 ret["subitems"]=[ subi ]
         elif isinstance(item, active_inst.ActiveInstance):
             ret["type"]="instance"
             ret["name"]=item.getCanonicalName()
             ret["fn_name"]=item.function.getFullName()
             ret["inputs" ]=item.getInputs().getSubValueList()
             ret["outputs" ]=item.getOutputs().getSubValueList()
             net=item.getNet()
             if net is not None:
                 ret["instances" ]=net.getActiveInstanceList(False,
                                                             False)
             ret["state"]=item.getPropagatedStateStr()
             cputime=int(item.getCputime())
             if cputime > 0:
                 ret["cputime" ]=str(cputime)
             cputime=int(item.getCumulativeCputime())
             if cputime > 0:
                 ret["cumulative-cputime" ]=str(cputime)
         elif isinstance(item, Project):
             ret["type"]="network"
             ret["name"]=pathname
             ret["instances"]=item.network.getActiveInstanceList(
                                                         False,
                                                         False)
             cputime=int(item.network.getCumulativeCputime())
             if cputime > 0:
                 ret["cumulative-cputime" ]=str(cputime)
         else:
             ret["type"]="Unknown type of item: "
             ret["name"]=pathname
         return ret
Ejemplo n.º 26
0
 def getInputNames(self):
     return vtype.parseItemList(" ")
Ejemplo n.º 27
0
    def startElement(self, name, attrs):
        # if name == "value" or name == "data":
        if name in vtype.basicTypes:
            basicType = vtype.basicTypes[name]
            if "type" in attrs:
                tpnm = keywords.fixID(attrs.getValue("type"))
                if self.importList is not None:
                    tp = self.importList.getTypeByFullName(tpnm, self.currentImport)
                else:
                    tp = basicType
            else:
                tp = basicType
            # determine the numerical location in the subitem tree
            if self.depth == self.lastDepth:
                self.subCounters[self.depth] += 1
            elif self.depth > self.lastDepth:
                if len(self.subCounters) < self.depth + 1:
                    self.subCounters.append(0)
                else:
                    self.subCounters[self.depth] = 0
            else:
                self.subCounters[self.depth] += 1
            # now determine the sub-item context
            itemStackAdd = None  # the item to add to the item stack at the end
            if len(self.subStack) > 0:
                subVal = self.subStack[-1]  # subVal is the current value to read
                if "field" in attrs:
                    if len(self.typeStack) > 0 and self.typeStack[-1].isCompound():
                        # if it's a field, it's named.
                        itemStackAdd = keywords.fixID(attrs.getValue("field"))
                        createType = None
                        if self.allowUnknownTypes:
                            createType = tp
                        subVal = subVal.getCreateSubValue(
                            [itemStackAdd], createType=createType, setCreateSourceTag=self.sourceTag
                        )
                        if subVal is None:
                            raise ValXMLError("Did not find field '%s'" % attrs.getValue("field"), self)
                    else:
                        raise ValXMLError("field '%s' inside non-compound type" % attrs.getValue("field"), self)
                elif "subitem" in attrs:
                    # this is a single, directly addressed sub-item
                    subitems = vtype.parseItemList(keywords.fixID(attrs.getValue("subitem")))
                    subVal = subVal.getCreateSubValue(subitems, setCreateSourceTag=self.sourceTag)
                elif len(self.typeStack) > 0 and (self.typeStack[-1] == vtype.arrayType):
                    itemStackAdd = self.subCounters[self.depth]
                    createType = None
                    if self.allowUnknownTypes:
                        createType = tp
                    subVal = subVal.getCreateSubValue(
                        [itemStackAdd], createType=createType, setCreateSourceTag=self.sourceTag
                    )
            else:
                # this is the top-level value
                self.value = self.valueType(None, tp)
                subVal = self.value

            if tp is not None:
                # check the type
                if not tp.isSubtype(subVal.getType()):
                    raise ValXMLError("%s not a subtype of %s." % (tp.getName(), subVal.getType().getName()), self)
            else:
                tp = subVal.getType()
            if not subVal.getType().isCompound():
                if "value" in attrs:
                    # this means that the type is a literal and can be parsed
                    nval = interpretLiteral(attrs.getValue("value"), tp)
                    subVal.copy(nval)
                    # log.debug("Setting value for %s to %s"%
                    #          (subVal.getFullName(), subVal.value) )
                    # subVal._set(tp.valueFromLiteral(attrs.getValue('value')))
            else:
                if "value" in attrs:
                    raise ValXMLError("Literal value for compound type", self)
            # increment depth
            if "seqnr" in attrs:
                subVal.seqNr = int(attrs.getValue("seqnr"))
            if "updated" in attrs:
                updated = cpc.util.getBooleanAttribute(attrs, "updated")
                if updated:
                    subVal.markUpdated(updated)
            # log.debug("Setting value for %s"%subVal.getFullName())
            subVal.sourceTag = self.sourceTag
            self.lastDepth = self.depth
            self.depth += 1
            self.typeStack.append(basicType)
            # self.itemStack.append(itemStackAdd)
            self.subStack.append(subVal)
Ejemplo n.º 28
0
    def startElement(self, name, attrs):
        #if name == "value" or name == "data":
        if name in vtype.basicTypes:
            basicType=vtype.basicTypes[name]
            if 'type' in attrs:
                tpnm=keywords.fixID(attrs.getValue('type'))
                if self.importList is not None:
                    tp=self.importList.getTypeByFullName(tpnm,
                                                         self.currentImport)
                else:
                    tp=basicType
            else:
                tp=basicType
            # determine the numerical location in the subitem tree
            if self.depth == self.lastDepth:
                self.subCounters[self.depth] += 1
            elif self.depth > self.lastDepth:
                if len(self.subCounters) < self.depth+1:
                    self.subCounters.append(0)
                else:
                    self.subCounters[self.depth] = 0
            else:
                self.subCounters[self.depth] += 1
            # now determine the sub-item context
            itemStackAdd=None  # the item to add to the item stack at the end
            if len(self.subStack) > 0:
                subVal=self.subStack[-1] # subVal is the current value to read
                if 'field' in attrs:
                    if (len(self.typeStack)>0
                        and self.typeStack[-1].isCompound()):
                        # if it's a field, it's named.
                        itemStackAdd=keywords.fixID(attrs.getValue('field'))
                        createType=None
                        if self.allowUnknownTypes:
                            createType=tp
                        subVal=subVal.getCreateSubValue([itemStackAdd],
                                            createType=createType,
                                            setCreateSourceTag=self.sourceTag)
                        if subVal is None:
                            raise ValXMLError("Did not find field '%s'"%
                                              attrs.getValue('field'), self)
                    else:
                        raise ValXMLError("field '%s' inside non-compound type"%
                                          attrs.getValue('field'), self)
                elif 'subitem' in attrs:
                    # this is a single, directly addressed sub-item
                    subitems=vtype.parseItemList(
                                    keywords.fixID(attrs.getValue('subitem')))
                    subVal=subVal.getCreateSubValue(subitems,
                                              setCreateSourceTag=self.sourceTag)
                elif ( len(self.typeStack) > 0 and
                       (self.typeStack[-1] == vtype.arrayType) ):
                    itemStackAdd=self.subCounters[self.depth]
                    createType=None
                    if self.allowUnknownTypes:
                        createType=tp
                    subVal=subVal.getCreateSubValue([itemStackAdd],
                                              createType=createType,
                                              setCreateSourceTag=self.sourceTag)
            else:
                # this is the top-level value
                self.value=self.valueType(None, tp)
                subVal=self.value

            if tp is not None:
                # check the type
                if not tp.isSubtype(subVal.getType()):
                    raise ValXMLError("%s not a subtype of %s."%
                                      (tp.getName(),
                                       subVal.getType().getName()),
                                      self)
            else:
                tp=subVal.getType()
            if not subVal.getType().isCompound():
                if 'value' in attrs:
                    # this means that the type is a literal and can be parsed
                    nval=interpretLiteral(attrs.getValue('value'), tp)
                    subVal.copy(nval)
                    #log.debug("Setting value for %s to %s"%
                    #          (subVal.getFullName(), subVal.value) )
                    #subVal._set(tp.valueFromLiteral(attrs.getValue('value')))
            else:
                if 'value' in attrs:
                    raise ValXMLError("Literal value for compound type", self)
            # increment depth
            if 'seqnr' in attrs:
                subVal.seqNr=int(attrs.getValue('seqnr'))
            if 'updated' in attrs:
                updated=cpc.util.getBooleanAttribute(attrs, "updated")
                if updated:
                    subVal.markUpdated(updated)
            #log.debug("Setting value for %s"%subVal.getFullName())
            subVal.sourceTag=self.sourceTag
            self.lastDepth=self.depth
            self.depth+=1
            self.typeStack.append(basicType)
            #self.itemStack.append(itemStackAdd)
            self.subStack.append(subVal)
Ejemplo n.º 29
0
 def getSubnetOutputValue(self, itemname):
     """Get the Value object associated with an input."""
     items=vtype.parseItemList(itemname)
     retv=self.subnetOutputs.getSubValue(items)
     return retv
Ejemplo n.º 30
0
 def getInputNames(self):
     return vtype.parseItemList(" ")
Ejemplo n.º 31
0
def splitIOName(name, expectedDirection=None):
    """Split an input/output name into a 3-tuple, as:
       instance-name:'in'/'out'.itemname.subItemname[subItem2name]
       (except for 'self')

       Checks whether [in/out] item corresponds with expected
       type, if given (it can be implicit, such as instance-name.itemname.
       If expectedDirection is not given, it must be specified in name.

       returns tuple of  instance-name, in/out/sub-in/sub-out, item-list
       """
    instance=None
    direction=None
    ioitem=None
    #subItem=None

    # split into fullInstance and ioitem
    srcp0=name.split(keywords.SubTypeSep,1)
    if len(srcp0) < 2:
        if name.find(keywords.SubTypeSep) >= 0:
            raise ConnError("Item '%s': syntax error"%name)
        fullInstance=name
        fullIoItem=None
    else:
        fullInstance=srcp0[0]
        #fullIoItem=".%s"%srcp0[1] # TODO: fix this so it's more flexible
        fullIoItem=srcp0[1]
    # now split fullInstance
    srcp1=fullInstance.rsplit(keywords.InstSep,1)
    dirnm=srcp1[-1]
    instance=srcp1[0]
    if (dirnm==keywords.In or dirnm==keywords.Out):
        if (expectedDirection is not None) and (dirnm != expectedDirection):
            raise ConnError("%s: expected %s item, not %s"%
                            (name, expectedDirection, dirnm))
        if instance != keywords.Self:
            if dirnm == keywords.In:
                direction=function_io.inputs
            else:
                direction=function_io.outputs
        else:
            if dirnm == keywords.In:
                direction=function_io.subnetInputs
            else:
                direction=function_io.subnetOutputs
    elif (dirnm==keywords.ExtIn or dirnm==keywords.ExtOut):
        if (expectedDirection is not None) and (dirnm != expectedDirection):
            raise ConnError("%s: expected %s item, not %s"%
                            (name, expectedDirection, dirnm))
        if instance != keywords.Self:
            raise ConnError(
                      "%s: can't specify external I/O on non-self instance %s"%
                      (name, instance))
        else:
            if dirnm == keywords.ExtIn:
                direction=function_io.inputs
            else:
                direction=function_io.outputs
    elif (dirnm==keywords.SubIn or dirnm==keywords.SubOut):
        if (expectedDirection is not None) and (dirnm != expectedDirection):
            raise ConnError("%s: expected %s item, not %s"%
                            (name, expectedDirection, dirnm))
        # in this case, 'self' doesn't change anything.
        if dirnm == keywords.SubIn:
            direction=function_io.subnetInputs
        else:
            direction=function_io.subnetOutputs
    else:
        if expectedDirection is None:
            raise ConnError("Item %s ambigiuous on in/out"%name)
        elif srcp1[-1]!="":
            raise ConnError("Syntax error in in/out specifier in %s"%name)
        else:
            dirstr=expectedDirection
    # now split ioitem
    #if fullIoItem is not None:
    #    # TODO fix this so we check for closing brackets etc.
    #    # for now, we just replace the brackets with dots.
    #    ioitemlist=fullIoItem.replace('[', keywords.SubTypeSep).\
    #                          replace(']', '').split(keywords.SubTypeSep)
    ##    ioitem=ioitemlist[0]
    #    subItems=ioitemlist[1:]
    #    for i in range(len(subItems)):
    #        if subItems[i].isdigit():
    #            subItems[i]=int(subItems[i])
    #else:
    #    subItems=[]
    #log.debug("instance=%s, direction=%s, ioitem=%s, subitems=%s"%
    #          (str(instance), str(direction), str(ioitem), str(subItems)))
    if fullIoItem is not None:
        ioitem=vtype.parseItemList(fullIoItem)
    else:
        ioitem=[]
    return (instance, direction, ioitem)
Ejemplo n.º 32
0
 def hasSubnetOutput(self, itemname):
     """Check whether a particular output exists"""
     items = vtype.parseItemList(itemname)
     if self.subnetOutputs is None:
         return False
     return self.subnetOutputs.hasSubValue(items)
Ejemplo n.º 33
0
 def getNamedItemList(self, pathname):
     """Get an list based on a path name according to the rule
        [instance]:[instance]"""
     pathname = keywords.fixID(pathname)
     with self.updateLock:
         itemlist = vtype.parseItemList(pathname)
         item = self.getSubValue(itemlist)
         ret = dict()
         if item is None:
             ret["type"] = "Not found: "
             ret["name"] = pathname
         elif isinstance(item, value.Value):
             # it is an active I/O item
             tp = item.getType()
             ret["type"] = "input/output value"
             ret["name"] = pathname
             if tp is not None:
                 ret["typename"] = tp.getName()
                 ret["value-type"] = tp.jsonDescribe()
             else:
                 ret["typename"] = "Not found"
             if tp.isSubtype(vtype.recordType):
                 ret["subitems"] = []
                 keys = tp.getMemberKeys()
                 for key in keys:
                     mem = tp.getRecordMember(key)
                     subi = dict()
                     subi["name"] = key
                     subi["type"] = mem.type.getName()
                     #subi["value-type"]=mem.type.jsonDescribe()
                     optstr = ""
                     conststr = ""
                     if mem.isOptional():
                         subi["optional"] = 1
                     if mem.isConst():
                         subi["const"] = 1
                     if mem.isComplete():
                         subi["complete"] = 1
                     if mem.desc is not None:
                         subi["desc"] = mem.desc.get()
                     ret["subitems"].append(subi)
             elif (tp.isSubtype(vtype.arrayType)
                   or tp.isSubtype(vtype.dictType)):
                 mem = tp.getMembers()
                 subi = {"type": mem.getName()}
                 ret["subitems"] = [subi]
         elif isinstance(item, active_inst.ActiveInstance):
             ret["type"] = "instance"
             ret["name"] = item.getCanonicalName()
             ret["fn_name"] = item.function.getFullName()
             ret["inputs"] = item.getInputs().getSubValueList()
             ret["outputs"] = item.getOutputs().getSubValueList()
             net = item.getNet()
             if net is not None:
                 ret["instances"] = net.getActiveInstanceList(False, False)
             ret["state"] = item.getPropagatedStateStr()
             cputime = int(item.getCputime())
             if cputime > 0:
                 ret["cputime"] = str(cputime)
             cputime = int(item.getCumulativeCputime())
             if cputime > 0:
                 ret["cumulative-cputime"] = str(cputime)
         elif isinstance(item, Project):
             ret["type"] = "network"
             ret["name"] = pathname
             ret["instances"] = item.network.getActiveInstanceList(
                 False, False)
             cputime = int(item.network.getCumulativeCputime())
             if cputime > 0:
                 ret["cumulative-cputime"] = str(cputime)
         else:
             ret["type"] = "Unknown type of item: "
             ret["name"] = pathname
         return ret
Ejemplo n.º 34
0
 def hasInput(self, itemname):
     """Check whether a particular input exists"""
     items = vtype.parseItemList(itemname)
     return self.inputs.hasSubValue(items)
Ejemplo n.º 35
0
 def hasInput(self, itemname):
     """Check whether a particular input exists"""
     items=vtype.parseItemList(itemname)
     return self.inputs.hasSubValue(items)
Ejemplo n.º 36
0
 def hasSubnetOutput(self, itemname):
     """Check whether a particular output exists"""
     items=vtype.parseItemList(itemname)
     if self.subnetOutputs is None:
         return False
     return self.subnetOutputs.hasSubValue(items)