def createItems(self, parentItem, tree, data, parentPath="", rootPath=""): loadedItems = self.loadedItems itemCls = self.itemClass for current, children in tree.iteritems(): p = pathJoin(parentPath, current) bBypassItem = False if rootPath: rp = pathRelativeTo(p, rootPath) if (rp == ".") or (".." in rp): bBypassItem = True if bBypassItem: item = parentItem elif p in loadedItems: item = loadedItems[p] else: kwargs = data.get(p, {}).copy() texts = parentItem.columnCount() * [""] texts[0] = current texts = kwargs.pop("texts", texts) item = itemCls(parentItem, texts, **kwargs) loadedItems[p] = item if children: self.createItems(item, children, data, p, rootPath=rootPath)
def walk(self, parentPath="", rootPath=""): for sChild, children in self.iteritems(): p = pathJoin(parentPath, sChild) bYield = True if rootPath: rp = pathRelativeTo(p, rootPath) if (rp == ".") or (".." in rp): bYield = False if bYield: yield p, children for cp in children.walk(p, rootPath): yield cp
def iterPaths(self, parentPath="", rootPath=""): for sChild, children in self.iteritems(): p = pathJoin(parentPath, sChild) bYield = True if rootPath: rp = pathRelativeTo(p, rootPath) if (rp == ".") or (".." in rp): bYield = False if bYield: yield p for cp in children.iterPaths(p, rootPath): yield cp
def dbToRelPath(self, sDbPath): sDbPath = pathNorm(sDbPath) sRelPath = pathRelativeTo(sDbPath, pathNorm(self.dbPath())) return sRelPath
def absToRelPath(self, sAbsPath): return pathRelativeTo(sAbsPath, self.absPath())