def packageCollection(collectionId, dbSysInst, dictElem, folderOnly=False):
    """
    collectionId would be cache system ID or ufsFs url/local path, it would not be cache collectionId
    """
    co = manager.getCollection(collectionId, dbSysInst, folderOnly)
    res = []
    coList = co.getRange(0, None)
    # print coList
    for i in coList:
        if not objTools.isUfsUrl(i):
            j = objTools.getUfsUrl(i)
            res.append(j)
        else:
            res.append(i)
    if objTools.isUuid(collectionId):
        """
        file id in cache system: uuid:xxxx-xxxx-xxxx-xxxxx-xxxx
        """
        id = objTools.getUuid(collectionId)
        # It's a UUID
        import localLibs.cache.localFileSystemCache as localFileSystemCache

        try:
            cacheSys = localFileSystemCache.localFileSystemCache(dbSysInst)
            cachedPath = cacheSys.getCached(id)
            targetId = objTools.getUfsUrl(cachedPath)
        except KeyError:
            targetId = id
    elif not objTools.isUfsUrl(collectionId):
        # It is a local path?
        targetId = objTools.getUfsUrl(collectionId)
    else:
        targetId = collectionId
    dictElem[targetId] = res
Beispiel #2
0
def updateCollectionFromJson(jsonCollectionStr, htmlGen, dbInst):
    r = json.loads(jsonCollectionStr)
    for k in r:
        data = r[k]
        for i in data:
            c = collectionManager.getCollection(i, dbInst)
            if k == "add":
                op = c.append
            if k == "del":
                op = c.remove
            if k == "update":
                c.removeAll()
                op = c.append

            if type(data[i]) == list:
                for idInCol in data[i]:
                    objFullPath = stringTools.jsIdDecoding(idInCol)
                    objUfsUrl = objTools.getUfsUrl(objFullPath)
                    htmlGen.write(u"%s:" % k + objUfsUrl + u"<br>")
                    # continue
                    op(objUfsUrl)
            else:
                idInCol = data[i]
                objFullPath = stringTools.jsIdDecoding(idInCol)
                objUfsUrl = objTools.getUfsUrl(objFullPath)
                htmlGen.write(u"%s:" % k + objUfsUrl + u"<br>")
                # continue
                op(objUfsUrl)
Beispiel #3
0
def packageTreePath(collectionId, dbSysInst, dictElem):
    if objTools.isUuid(collectionId):
        id = objTools.getUuid(collectionId)
        #It's a UUID
        import localLibs.cache.localFileSystemCache as localFileSystemCache
        cacheSys = localFileSystemCache.localFileSystemCache(dbSysInst)
        cachedPath = cacheSys.getCached(id)
    elif objTools.isUfsUrl(collectionId):
        protocol,cachedPath = objTools.parseUrl(collectionId)
    else:
        cachedPath = collectionId
    parent = None
    while True:
        parent = os.path.dirname(os.path.abspath(cachedPath))
        #print parent, cachedPath
        if os.path.abspath(parent) == os.path.abspath(cachedPath):
            #Root dir, return root item
            dictElem[objTools.getUfsLocalRootUrl()] = objTools.getUfsUrl(cachedPath)
            dictElem[ufs.getUfsUuidItemUrl()] = objTools.getUfsLocalRootUrl()
            break
        dictElem[objTools.getUfsUrl(parent)] = objTools.getUfsUrl(cachedPath)
        cachedPath = parent