Ejemplo n.º 1
0
class FindFilesNode(Node):
    """ This node uses fnmatch to find matching file paths in the given folder
        @ivar _location: base folder to search in
        @ivar _pattern: fnmatch pattern to search for
        @ivar _files: all files found
    """
    def __init__(self, name, parent):
        super(FindFilesNode, self).__init__(name, parent)

        self._location = StringAttribute("location", self)
        self._location.setSpecializationOverride("Path")
        self._pattern = StringAttribute("pattern", self)
        self._files = StringAttribute("files", self)
        self._setAttributeAllowedSpecializations(self._location, ["Path"])
        self._setAttributeAllowedSpecializations(self._pattern, ["String"])
        self._setAttributeAllowedSpecializations(self._files, ["PathArray"])

        self.addInputAttribute(self._location)
        self.addInputAttribute(self._pattern)
        self.addOutputAttribute(self._files)

        self._setAttributeAffect(self._location, self._files)
        self._setAttributeAffect(self._pattern, self._files)

        self._setSliceable(True)

    def update(self, attribute):
        coralApp.logDebug("FindFiles.update")
        location = self._location.value().stringValueAt(0)
        pattern = self._pattern.value().stringValueAt(0)

        assets = []
        if location == "":
            return
        if not os.path.isdir(location):
            coralApp.logError("Location does not exist.")
            return
        filenames = os.listdir(location)
        for filename in filenames:
            if fnmatch.fnmatch(filename, pattern):
                fullPath = os.path.join(location, filename)
                if os.path.isfile(fullPath):
                    assets.append(fullPath)

        self._files.outValue().setPathValues(assets)
        coralApp.logDebug("FindFiles.update: Done")
Ejemplo n.º 2
0
class FindFilesNode(Node):
    """ This node uses fnmatch to find matching file paths in the given folder
        @ivar _location: base folder to search in
        @ivar _pattern: fnmatch pattern to search for
        @ivar _files: all files found
    """
    def __init__(self, name, parent):
        super(FindFilesNode, self).__init__(name, parent)

        self._location = StringAttribute("location", self)
        self._location.setSpecializationOverride("Path")
        self._pattern = StringAttribute("pattern", self)
        self._files = StringAttribute("files", self)
        self._setAttributeAllowedSpecializations(self._location, ["Path"])
        self._setAttributeAllowedSpecializations(self._pattern, ["String"])
        self._setAttributeAllowedSpecializations(self._files, ["PathArray"])

        self.addInputAttribute(self._location)
        self.addInputAttribute(self._pattern)
        self.addOutputAttribute(self._files)

        self._setAttributeAffect(self._location, self._files)
        self._setAttributeAffect(self._pattern, self._files)

        self._setSliceable(True)
    
    def update(self, attribute):
        coralApp.logDebug("FindFiles.update")
        location = self._location.value().stringValueAt(0)
        pattern = self._pattern.value().stringValueAt(0)

        assets = []
        if location == "":
            return
        if not os.path.isdir(location):
            coralApp.logError("Location does not exist.")
            return
        filenames = os.listdir(location)
        for filename in filenames:
            if fnmatch.fnmatch(filename, pattern):
                fullPath = os.path.join(location, filename)
                if os.path.isfile(fullPath):
                    assets.append(fullPath)

        self._files.outValue().setPathValues(assets)
        coralApp.logDebug("FindFiles.update: Done")