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[:]
def setPath(self, path): """ Set the path for the item. :rtype: str """ self._path = studiolibrary.normPath(path)
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)
def normPath(self, path): """ Normalize the path and make all back slashes to forward slashes. :type path: str :rtype: str """ return studiolibrary.normPath(path)
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)
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)
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()
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)
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)
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)