def fix0Bytes(res, dryRun=True, refresh=False): badFileList = [] for badFile in res[0]: if not badFile: continue #badFile.refresh() if badFile.fileSize: continue # if badFile.origin != "pipangai": # continue if badFile.isVersionFile(): continue #print badFile._dbnode.dataRepr() badFileList.append(badFile) if dryRun: report(badFileList, []) else: for badFile in badFileList: print badFile.dbPath() latestVers = badFile.getVersionFile(-1, refresh=refresh) copyFile(latestVers.absPath(), badFile.absPath(), in_place=True, preserve_times=False) badFile.updateToLatestVersion(prompt=False)
def createDirsAndFiles(self, sSpace="public", log=True, **kwargs): bDryRun = kwargs.pop("dryRun", True) sEntityName = self.name cls = self.__class__ cls.assertNameParts(cls.getNameParts(sEntityName)) sTemplatePath = self.getTemplatePath() if not sTemplatePath: raise EnvironmentError("{} has NO template configured.".format(self)) return [] sDestPathList = [] bCheckIfExists = True sEntityDirPath = self.getPath(sSpace) if not osp.exists(sEntityDirPath): bCheckIfExists = False if not bDryRun: os.makedirs(sEntityDirPath) sDestPathList.append(sEntityDirPath) sSrcPathIter = iterPaths(sTemplatePath, ignoreFiles=ignorePatterns("*.db", ".*")) for sSrcPath in sSrcPathIter: sDestPath = (sSrcPath.replace(sTemplatePath, sEntityDirPath) .format(**vars(self))) bExists = osp.exists(sDestPath) if bCheckIfExists else False if not bExists: sDestPathList.append(sDestPath) if not bDryRun: if sDestPath.endswith("/"): os.makedirs(pathNorm(sDestPath)) else: sDirPath = osp.dirname(sDestPath) if not osp.exists(sDirPath): os.makedirs(sDirPath) copyFile(sSrcPath, sDestPath, dry_run=bDryRun) if log and sDestPathList: sAction = "Creating" if not bDryRun else "Missing" sMsg = '\n{} {} paths for "{}":'.format(sAction, sSpace.upper(), sEntityName) sMsg += "\n " + "\n ".join(sDestPathList) print sMsg return sDestPathList
def createDirsAndFiles(self, sSpace="public", **kwargs): bDryRun = kwargs.pop("dryRun", True) bCheckDb = kwargs.pop("checkDb", True) bLog = kwargs.pop("log", True) bLoadDbNodes = kwargs.pop("loadDbNodes", True) sEntityName = self.name library = self.getLibrary(sSpace) cls = self.__class__ cls.assertNameParts(cls.getNameParts(sEntityName)) sTemplatePath = self.getTemplatePath() if not sTemplatePath: raise EnvironmentError("{} has NO template configured.".format(self)) sDestPathList = [] bNewEntity = False sEntityDirPath = self.getPath(sSpace) entityDir = library._weakDir(sEntityDirPath, dbNode=False) if not osp.exists(sEntityDirPath): dbNode = entityDir.loadDbNode() if dbNode: sMsg = """{}'s directory already exists in DB: \n{}""" raise RuntimeError(sMsg.format(self, dbNode.dataRepr())) bNewEntity = True if not bDryRun: os.makedirs(sEntityDirPath) entityDir.refresh(simple=True, dbNode=False) sDestPathList.append(sEntityDirPath) if bCheckDb and bLoadDbNodes: entityDir.loadChildDbNodes(recursive=True, noVersions=True) ruledDirDct = OrderedDict() newDirList = [] sSrcPathIter = iterPaths(sTemplatePath, ignoreFiles=ignorePatterns("*.db", ".*")) for sSrcPath in sSrcPathIter: sDestPath = pathRedir(sSrcPath, sTemplatePath, sEntityDirPath).format(**vars(self)) bExists = False if bNewEntity else osp.exists(sDestPath) if bExists: continue bIsDir = (sSrcPath.endswith("/") or sDestPath.endswith("/")) if bCheckDb: if bIsDir: sEntryType = "Directory" drcEntry = library._weakDir(sDestPath, dbNode=False) else: sEntryType = "File" drcEntry = library._weakFile(sDestPath, dbNode=False) dbNode = drcEntry.loadDbNode(fromDb=False) if dbNode: print "{} already exists in DB: '{}'".format(sEntryType, drcEntry.dbPath()) continue sDestPathList.append(sDestPath) bDirCreated = True if bIsDir: sDirPath = pathNorm(sDestPath) if not bDryRun: os.makedirs(sDirPath) else: sDirPath = osp.dirname(sDestPath) if not osp.exists(sDirPath): if not bDryRun: os.makedirs(sDirPath) else: bDirCreated = False if not bDryRun: copyFile(sSrcPath, sDestPath, dry_run=bDryRun) if not bDryRun: drcDir = library.getEntry(sDirPath, dbNode=False) else: drcDir = library._weakDir(sDirPath, dbNode=False) if drcDir not in ruledDirDct: sSyncRuleList = [] if bDirCreated: sSyncRuleList = drcDir.getParam("default_sync_rules", None) newDirList.append(drcDir) else: dbNode = drcDir.loadDbNode(fromDb=False) if dbNode: drcDir.refresh(simple=True, dbNode=False) sSyncRuleList = drcDir.syncRules if sSyncRuleList: ruledDirDct[drcDir] = sSyncRuleList newDbNodeList = [] for rcDir in newDirList: initData = rcDir.getDbNodeInitData(syncRules=False) newDbNodeList.append(initData) if newDbNodeList and (not bDryRun): newDbNodeList = self.project._db.createNodes(newDbNodeList) for dbnode in newDbNodeList: library._addDbNodeToCache(dbnode) for rcDir in newDirList: rcDir.refresh(simple=True, dbNode=False) for drcDir, sSyncRuleList in reversed(ruledDirDct.items()): #print drcDir, "default_sync_rules:", sSyncRuleList if not bDryRun: drcDir.setSyncRules(sSyncRuleList, applyRules=True, refresh=False) if bLog and sDestPathList: sSep = "\n " sAction = "Created" if not bDryRun else "Missing" sMsg = '\n{} {} paths for "{}":'.format(sAction, sSpace.upper(), sEntityName) sMsg += sSep + sSep.join(sDestPathList) print sMsg, "\n" return sDestPathList
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)