def launch(dryRun=True, project=""): app = qtGuiApp() if not app: app = QtGui.QApplication(sys.argv) sProject = os.environ["DAVOS_INIT_PROJECT"] if not project else project proj = DamProject(sProject) print sProject.center(80, "-") dbNodeDct = {} sFieldSet = set() print "Querying all dbnodes..." dbNodeList = proj.findDbNodes() print "Got {} dbnodes.".format(len(dbNodeList)) for dbnode in dbNodeList: sFieldSet.update(dbnode._data.iterkeys()) dbNodeDct.setdefault(dbnode.file.lower(), []).append(dbnode) dlg = QuickTreeDialog() treeWdg = dlg.treeWidget sFieldList = sorted(sFieldSet) sFieldList.remove("file") sFieldList.remove("#parent") sFieldList.insert(0, "file") treeWdg.setHeaderLabels(sFieldList) treeWdg.setTextElideMode(Qt.ElideLeft) topLevelItemDct = {} for sDbPath, nodes in dbNodeDct.iteritems(): x = len(nodes) if x > 1: nodes = sorted(nodes, key=lambda n:int(n.time) * .001, reverse=True) if sDbPath not in topLevelItemDct: topItem = TreeItem(treeWdg, [sDbPath]) topLevelItemDct[sDbPath] = topItem else: topItem = topLevelItemDct[sDbPath] for n in nodes: sTime = (datetime.fromtimestamp(int(n.time) / 1000) .strftime(u"%Y-%m-%d %H:%M")) n._data["time"] = sTime itemData = tuple(toUnicode(n._data.get(f, "")) for f in sFieldList) print itemData[0] item = TreeItem(topItem, itemData) item.setCheckState(0, Qt.Unchecked) item.setData(0, Qt.UserRole, n) treeWdg.expandAll() for c in xrange(treeWdg.columnCount()): treeWdg.resizeColumnToContents(c) bOk = dlg.exec_() if not bOk: return itemIter = QTreeWidgetItemIterator(treeWdg, QTreeWidgetItemIterator.Checked) toDeleteNodes = [item.value().data(0, Qt.UserRole) for item in itemIter] if toDeleteNodes: sMsg = "Delete these {} Db nodes ???".format(len(toDeleteNodes)) sConfirm = confirmDialog(title="WARNING !", message=sMsg, button=("Yes", "No"), defaultButton="No", cancelButton="No", dismissString="No", icon="warning", ) if sConfirm == "Yes": for n in toDeleteNodes: print "Deleting", n.file, n._data if not dryRun: n.delete()
def launch(rootDirList, update=False, dryRun=True, project="", dialogParent=None): global TREE_ITEM_DCT TREE_ITEM_DCT = {} app = qtGuiApp() if not app: app = QtGui.QApplication(sys.argv) proj = initProject(project) dlg = QuickTreeDialog(dialogParent) treeWdg = dlg.treeWidget treeWdg.setHeaderLabels(("Entity Name", "Infos")) missingPathItems = listMissingPathItems(rootDirList, update=update) badEntityList = [] treeDataList = [] for damEntity, sMissingPaths in missingPathItems: if isinstance(damEntity, basestring): p = pathJoin("Errors", damEntity) badEntityList.append({"path":p, "texts":[damEntity, sMissingPaths], "flags":Qt.ItemIsEnabled, "roles":{Qt.ForegroundRole:(1, QtGui.QBrush(Qt.red))} }) continue drcLib = proj.getLibrary("public", damEntity.libraryName) sLibPath = drcLib.absPath() sEntityTitle = damEntity.sgEntityType + 's' sEntityPath = damEntity.getPath("public") sEntiTreePath = re.sub("^" + sLibPath, sEntityTitle, sEntityPath) roleData = {Qt.UserRole:(0, damEntity)} treeDataList.append({"path":sEntiTreePath, "flags":None, "roles":roleData}) sTreePathList = tuple(re.sub("^" + sLibPath, sEntityTitle, p) for p in sMissingPaths) tree = OrderedTree.fromPaths(sTreePathList) for sTreePath in tree.iterPaths(rootPath=sEntiTreePath): treeDataList.append({"path":sTreePath, "flags":Qt.NoItemFlags}) treeWdg.createTree(badEntityList) treeWdg.defaultFlags |= Qt.ItemIsTristate treeWdg.defaultRoles = {Qt.CheckStateRole:(0, Qt.Unchecked)} treeWdg.createTree(treeDataList) topItemCount = treeWdg.topLevelItemCount() if topItemCount == 1: curItem = treeWdg.topLevelItem(0) treeWdg.setRootIndex(treeWdg.indexFromItem(curItem)) while curItem.childCount() == 1: curItem = curItem.child(0) curItem.setExpanded(True) else: for i in xrange(topItemCount): treeWdg.topLevelItem(i).setExpanded(True) dlg.show() while True: bOk = dlg.exec_() if not bOk: return bApply = False flags = (QTreeWidgetItemIterator.Checked | QTreeWidgetItemIterator.Enabled) treeIter = QTreeWidgetItemIterator(treeWdg, flags) damEntities = tuple(it.value().data(0, Qt.UserRole) for it in treeIter) damAssets = tuple(e for e in damEntities if isinstance(e, DamAsset)) damShots = tuple(e for e in damEntities if isinstance(e, DamShot)) if damAssets or damShots: sMsg = "Create directories and files for:\n" if damAssets: sMsg += "\n - {} Assets".format(len(damAssets)) if damShots: sMsg += "\n - {} Shots".format(len(damShots)) sConfirm = confirmDialog(title="WARNING !", message=sMsg, button=("Yes", "No"), defaultButton="No", cancelButton="No", dismissString="No", icon="warning", ) if sConfirm == "Yes": bApply = True break if bApply: entityDirList = len(damEntities) * [None] for i, damEntity in enumerate(damEntities): if not damEntity: continue damEntity.createDirsAndFiles(dryRun=dryRun, checkDb=False) entityDirList[i] = damEntity.getResource("public", "entity_dir") for drcDir in entityDirList: if drcDir: drcDir.setSyncRules(drcDir.syncRules)
def launch_old(entityType="", dryRun=True, project="", dialogParent=None): global TREE_ITEM_DCT TREE_ITEM_DCT = {} app = qtGuiApp() if not app: app = QtGui.QApplication(sys.argv) sProject = os.environ["DAVOS_INIT_PROJECT"] if not project else project proj = DamProject(sProject) print sProject.center(80, "-") dlg = QuickTreeDialog(dialogParent) treeWdg = dlg.treeWidget treeWdg.setHeaderLabels(("Entity Name", "Infos")) dlg.show() missingPathItems = listMissingPathItems(proj, entityType) badEntityItems = [] for damEntity, sMissingPaths in missingPathItems: if isinstance(damEntity, basestring): badEntityItems.append((damEntity, sMissingPaths)) continue drcLib = proj.getLibrary("public", damEntity.libraryName) sLibPath = drcLib.absPath() sEntityTitle = damEntity.sgEntityType + 's' sEntityPath = damEntity.getPath("public") sEntityPath = re.sub("^" + sLibPath, sEntityTitle, sEntityPath) sEntityPathDirs = pathSplitDirs(sEntityPath) for sAbsPath in sMissingPaths: sTreePath = re.sub("^" + sLibPath, sEntityTitle, sAbsPath) sParentPath, sFilename = osp.split(pathNorm(sTreePath)) parentItem = TREE_ITEM_DCT.get(sParentPath) if not parentItem: sDirList = pathSplitDirs(sParentPath) curParentItem = treeWdg for i, sDirName in enumerate(sDirList): if i == 0: sItemPath = sDirName else: sItemPath = pathJoin(*sDirList[:i + 1]) item = TREE_ITEM_DCT.get(sItemPath) if not item: flags = None if sItemPath.startswith(sEntityPath): if len(pathSplitDirs(sItemPath)) > len(sEntityPathDirs): flags = Qt.NoItemFlags userData = None if sItemPath == sEntityPath: userData = damEntity item = loadTreeItem(curParentItem, sItemPath, [sDirName], flags=flags, userData=userData) curParentItem = item parentItem = curParentItem flags = None if sTreePath.startswith(sEntityPath): if len(pathSplitDirs(sTreePath)) > len(sEntityPathDirs): flags = Qt.NoItemFlags userData = None if sTreePath == sEntityPath: userData = damEntity loadTreeItem(parentItem, sTreePath, [sFilename], flags=flags, userData=userData) if badEntityItems: errorsItem = loadTreeItem(None, "Errors", ["ERRORS"]) treeWdg.insertTopLevelItem(0, errorsItem) for sEntityName, sError in badEntityItems: loadTreeItem(errorsItem, sEntityName, [sEntityName, sError], checkable=False) for i in xrange(treeWdg.topLevelItemCount()): treeWdg.topLevelItem(i).setExpanded(True) while True: bOk = dlg.exec_() if not bOk: return bApply = False flags = (QTreeWidgetItemIterator.Checked | QTreeWidgetItemIterator.Enabled) treeIter = QTreeWidgetItemIterator(treeWdg, flags) damEntities = tuple(it.value().data(0, Qt.UserRole) for it in treeIter) damAssets = tuple(e for e in damEntities if isinstance(e, DamAsset)) damShots = tuple(e for e in damEntities if isinstance(e, DamShot)) if damAssets or damShots: sMsg = "Create directories and files for:\n" if damAssets: sMsg += "\n - {} Assets".format(len(damAssets)) if damShots: sMsg += "\n - {} Shots".format(len(damShots)) sConfirm = confirmDialog(title="WARNING !", message=sMsg, button=("Yes", "No"), defaultButton="No", cancelButton="No", dismissString="No", icon="warning", ) if sConfirm == "Yes": bApply = True break if bApply: for damEntity in damEntities: if not damEntity: continue damEntity.createDirsAndFiles(dryRun=dryRun)