Ejemplo n.º 1
0
class PathNode(Node):
    """Node for doing different pathing operations
    """
    def __init__(self, name, parent):
        super(PathNode, self).__init__(name, parent)
        self._setSliceable(True)

        self._inPath = StringAttribute("input", self)
        self._op = EnumAttribute("operation", self)
        self._out = StringAttribute("output", self)

        self._allOps = [("split", os.path.split, "StringArray"),
                        ("splitAll", None, "StringArray"),
                        ("dirname", os.path.dirname, "Path"),
                        ("basename", os.path.basename, "String"),
                        ("splitext", os.path.splitext, "StringArray")]

        for n, op in enumerate(self._allOps):
            self._op.value().addEntry(n, op[0])

        self._setAttributeAllowedSpecializations(self._inPath,
                                                 ["Path", "PathArray"])
        self._setAttributeAllowedSpecializations(
            self._out, ["String", "Path", "StringArray"])

        self.addInputAttribute(self._inPath)
        self.addInputAttribute(self._op)
        self.addOutputAttribute(self._out)

        self._setAttributeAffect(self._inPath, self._out)
        self._setAttributeAffect(self._op, self._out)

        # self._catchAttributeDirtied(self._inPath, True)
        self._catchAttributeDirtied(self._op, True)

    def attributeDirtied(self, attribute):
        if attribute == self._op:
            index = self._op.value().currentIndex()
            self._out._setSpecialization([self._allOps[index][2]])

    def updateSlice(self, attribute, slice):
        logger.debug("PathNode - updateSlice")
        inPaths = self._inPath.value().stringValuesSlice(slice)
        opIndex = self._op.value().currentIndex()
        for ip in inPaths:
            if ip == "":
                continue

            out = []
            if self._allOps[opIndex][1] == None:
                if self._allOps[opIndex][0] == "splitAll":
                    out = ip.split(os.sep)
            else:
                op = self._allOps[opIndex]
                out = op[1](ip)

            if isinstance(out, tuple):
                out = list(out)

            if not isinstance(out, list):
                out = [out]

            self._out.outValue().setPathValuesSlice(slice, out)

        logger.debug("PathNode - updateSlice: complete")
Ejemplo n.º 2
0
class PathNode(Node):
    """Node for doing different pathing operations
    """
    def __init__(self, name, parent):
        super(PathNode, self).__init__(name, parent)
        self._setSliceable(True)

        self._inPath = StringAttribute("input", self)
        self._op = EnumAttribute("operation", self)
        self._out = StringAttribute("output", self)

        self._allOps = [("split", os.path.split, "StringArray"),
                        ("splitAll", None, "StringArray"),
                        ("dirname", os.path.dirname, "Path"),
                        ("basename", os.path.basename, "String"),
                        ("splitext", os.path.splitext, "StringArray")
                        ]

        for n, op in enumerate(self._allOps):
            self._op.value().addEntry(n, op[0])

        self._setAttributeAllowedSpecializations(self._inPath, ["Path", "PathArray"])
        self._setAttributeAllowedSpecializations(self._out, ["String", "Path", "StringArray"])

        self.addInputAttribute(self._inPath)
        self.addInputAttribute(self._op)
        self.addOutputAttribute(self._out)

        self._setAttributeAffect(self._inPath, self._out)
        self._setAttributeAffect(self._op, self._out)

        # self._catchAttributeDirtied(self._inPath, True)
        self._catchAttributeDirtied(self._op, True)

    def attributeDirtied(self, attribute):
        if attribute == self._op:
            index = self._op.value().currentIndex()
            self._out._setSpecialization([self._allOps[index][2]])

    def updateSlice(self, attribute, slice):
        logger.debug("PathNode - updateSlice")
        inPaths = self._inPath.value().stringValuesSlice(slice)
        opIndex = self._op.value().currentIndex()
        for ip in inPaths:
            if ip == "":
                continue

            out = []
            if self._allOps[opIndex][1] == None:
                if self._allOps[opIndex][0] == "splitAll":
                    out = ip.split(os.sep)
            else:
                op = self._allOps[opIndex]
                out = op[1](ip)

            if isinstance(out, tuple):
                out = list(out)

            if not isinstance(out, list):
                out = [out]

            self._out.outValue().setPathValuesSlice(slice, out)

        logger.debug("PathNode - updateSlice: complete")