Ejemplo n.º 1
0
    def walker(self, path):
        """
        Walk the given root path for valid items and return the item data.

        :type path: str

        :rtype: collections.Iterable[dict]
        """
        path = studiolibrary.normPath(path)
        maxDepth = self.recursiveDepth()
        startDepth = path.count(os.path.sep)

        for root, dirs, files in os.walk(path, followlinks=True):

            files.extend(dirs)

            for filename in files:

                # Normalise the path for consistent matching
                path = studiolibrary.normPath(os.path.join(root, filename))

                # Ignore any paths that have been specified in the config
                if not self.isValidPath(path):
                    continue

                # Match the path with a registered item
                item = self.itemFromPath(path)

                remove = False
                if item:

                    # Yield the item data that matches the current path
                    yield item.createItemData()

                    # Stop walking if the item doesn't support nested items
                    if not item.ENABLE_NESTED_ITEMS:
                        remove = True

                if remove and filename in dirs:
                    dirs.remove(filename)

            if maxDepth == 1:
                break

            # Stop walking the directory if the maximum depth has been reached
            currentDepth = root.count(os.path.sep)
            if (currentDepth - startDepth) >= maxDepth:
                del dirs[:]
Ejemplo n.º 2
0
    def setPath(self, path):
        """
        Set the path for the item.

        :rtype: str
        """
        self._path = studiolibrary.normPath(path)
Ejemplo n.º 3
0
    def setPath(self, path):
        """
        Set the path location on disc for the item.

        :type path: str
        :rtype: None
        """
        if not path:
            raise ItemError('Cannot set an empty item path.')

        path = studiolibrary.normPath(path)

        dirname, basename, extension = studiolibrary.splitPath(path)

        name = os.path.basename(path)
        category = os.path.basename(dirname)

        self.setName(name)
        self.setText("Path", path)
        self.setText("Category", category)

        if os.path.exists(path):
            modified = os.path.getmtime(path)
            timeAgo = studiolibrary.timeAgo(modified)

            self.setText("Modified", timeAgo)
            self.setSortText("Modified", str(modified))

        self.setText("Type", extension)
Ejemplo n.º 4
0
    def normPath(self, path):
        """
        Normalize the path and make all back slashes to forward slashes.

        :type path: str
        :rtype: str
        """
        return studiolibrary.normPath(path)
Ejemplo n.º 5
0
    def itemFromPath(self, path, **kwargs):
        """
        Return a new item instance for the given path.

        :type path: str
        :rtype: studiolibrary.LibraryItem or None
        """
        path = studiolibrary.normPath(path)

        for cls in self.registeredItems():
            if cls.match(path):
                return cls(path, **kwargs)
Ejemplo n.º 6
0
    def selectPaths(self, paths):
        """
        Select the items with the given paths.

        :type paths: list[str]
        :rtype: None
        """
        paths = studiolibrary.normPaths(paths)
        items = self.items()
        for item in items:
            if studiolibrary.normPath(item.path()) in paths:
                item.setSelected(True)
            else:
                item.setSelected(False)
            def _recursive(parent, children, split=None, root=""):
                for text, val in sorted(children.items()):

                    if not parent:
                        parent = self

                    path = split.join([root, text])
                    path = studiolibrary.normPath(path)

                    child = SidebarWidgetItem(parent)
                    child.setText(0, six.text_type(text))
                    child.setPath(path)

                    self._index[path] = child

                    _recursive(child, val, split=split, root=path)
Ejemplo n.º 8
0
    def setPath(self, path):
        """
        Set the path location on disc for the item.

        :type path: str
        :rtype: None
        """
        if not path:
            raise ItemError('Cannot set an empty item path.')

        self.resetImageSequence()

        path = studiolibrary.normPath(path)

        self._path = path

        self.updateItemData()
Ejemplo n.º 9
0
    def setPath(self, path):
        """
        Set the path location on disc for the item.

        :type path: str
        :rtype: None
        """
        if not path:
            raise ItemError('Cannot set an empty item path.')

        self.resetImageSequence()

        path = studiolibrary.normPath(path)

        self._path = path

        self.updateItemData()
Ejemplo n.º 10
0
    def showCreateWidgetOverride(self):
        """
        Show a create widget, but with the same info as this widget already pre filled.
        This is done to allow for a quick "replace"
        """

        widget = self.CreateWidgetClass(self, parent=self.libraryWindow())

        path = '/'.join(studiolibrary.normPath(self.path()).split('/')[:-1])

        widget.folderFrame().hide()
        widget.setFolderPath(path)
        widget.setLibraryWindow(self.libraryWindow())

        self.libraryWindow().setCreateWidget(widget)
        self.libraryWindow().folderSelectionChanged.connect(
            widget.setFolderPath)
Ejemplo n.º 11
0
 def selectFolder(self):
     """select the folder in the library widget"""
     if self.libraryWindow():
         path = '/'.join(
             studiolibrary.normPath(self.path()).split('/')[:-1])
         self.libraryWindow().selectFolderPath(path)
Ejemplo n.º 12
0
 def selectFolder(self):
     """select the folder in the library widget"""
     if self.libraryWindow():
         path = '/'.join(studiolibrary.normPath(self.path()).split('/')[:-1])
         self.libraryWindow().selectFolderPath(path)