Ejemplo n.º 1
0
def launch(bDryRun=True, project="", **kwargs):

    global proj, wastedNodes, dbNodeList

    sProject = os.environ["DAVOS_INIT_PROJECT"] if not project else project
    proj = DamProject(sProject)
    print sProject.center(80, "-")

    if wastedNodes is None:
        dbNodeList = proj.findDbNodes()
        wastedNodes = findWastedDbNodes(proj, dbNodeList, **kwargs)

    numNodes = len(wastedNodes)
    print "\n", "\n".join(n.file + "\n    " + os.path.normpath(p) for n, p in wastedNodes)
    print "found {}/{} unused DbNodes".format(numNodes, len(dbNodeList))

    if (not bDryRun) and numNodes:
        if raw_input("Delete these nodes ? (yes/no)").strip() == "yes":
            for n, _ in wastedNodes:
                print "deleting", n
                n.delete()
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
import os

from pytd.util.fsutils import pathJoin, copyFile

from davos.core.damproject import DamProject
#from davos.core.dbtypes import DummyDbCon, DrcDb

proj = DamProject("zombtest")

sMaFilePath = pathJoin(proj.getPath("template", "project"), "initial_files", "maya_2016.ma")
print sMaFilePath, os.path.isfile(sMaFilePath)

for sAstType in proj.getVar("asset_lib", "asset_types"):
    for sPathVar in proj.getVar(sAstType, "all_tree_vars"):
        p = proj.getTemplatePath(sAstType, sPathVar)
        if p.endswith(".ma"):
            copyFile(sMaFilePath, p, dry_run=False)
Ejemplo n.º 5
0
def launch(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)

    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)

    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)