Ejemplo n.º 1
0
def launch(bDryRun=True):

    dbNodeDct = dict((n.file.lower(), n)  for n in proj.findDbNodes())

    for drcLib in proj.loadedLibraries.itervalues():

        if not drcLib.isPublic():
            continue

        for p in iterPaths(drcLib.absPath(), dirs=True,
                           ignoreDirs=ignorePatterns(".*", "chr_old", "*xxxx*"),
                           ignoreFiles=ignorePatterns(".*", "Thumbs.db", "*xxxx*")):

            entry = drcLib.getEntry(p, dbNode=False)
            if not entry:
                print "No such", p
                continue

            sDbPath = entry.dbPath().lower()
            dbnode = dbNodeDct.get(sDbPath)
            if not dbnode:
                continue

            sDbFilePath = entry.dbPath()
            sDbNodePath = dbnode.file
            if sDbNodePath != sDbFilePath:
                print "\nfs:", sDbFilePath, "\ndb:", sDbNodePath
                if not bDryRun:
                    dbnode.setField("file", sDbFilePath)
                    print dbnode.dataRepr("file")
def iterTreeData():

    for p in iterPaths("C:/Users/styx/Google Drive", intermediateDirs=True,
                       relative=False):
        data = {"path":p}

        if osp.isfile(p):
            roleData = {Qt.BackgroundRole:(0, QtGui.QBrush(Qt.green))}
            data["roles"] = roleData

        yield data
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
def launch(bDryRun=True):

    dbNodeDct = dict((n.file, n)  for n in proj.findDbNodes())

    for drcLib in proj.loadedLibraries.itervalues():

        if not drcLib.isPublic():
            continue

        for p in iterPaths(drcLib.absPath(), dirs=False,
                           ignoreDirs=ignorePatterns(".*", "chr_old", "*xxxx*")):

            entry = drcLib.getEntry(p, dbNode=False)
            if not entry:
                print "No such", p
                continue

            sDbPath = entry.dbPath().lower()
            dbnode = dbNodeDct.get(sDbPath)
            if not dbnode:
                continue

            print dbnode
            sNewDbPath = "/" + entry.dbPath()
    #        print sNewDbPath
    #        print dbnode.file

            data = {"file":sNewDbPath}
            if not dbnode.checksum:
                print "empty checksum found"
                data["checksum"] = None

            if bDryRun:
                print data
            else:
                dbnode.setData(data)
                dbnode.logData()

            print ""
Ejemplo n.º 5
0
    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