Пример #1
0
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
Пример #2
0
def getCollection(collectionId, dbSysInst, folderOnly = False):
    '''
    The basic algrithom for this function is:
    1. Find the original collection for the collectionId represented collection
    2. Update the collectionId represented collection if possible
    3. return the latest collection snapshot for the original collection
    So we can always get the latest snapshot for the original collection
    '''
    #If the collection is an uuid, for example: uuid://xxxx-xxxxxxxx-xxxx-xxxx-xxxx,
    #then get the local cache for that object. If no local cache for the object, return the collection directly
    if objTools.isUuid(collectionId) or objTools.isUfsFs(collectionId):
        #it is uuid://xxxxx or is ufsFs://xxxx
        id = objTools.getUuid(collectionId)
        #It's a UUID
        try:
            import localLibs.cache.localFileSystemCache as localFileSystemCache
            try:
                cacheSys = localFileSystemCache.localFileSystemCache(dbSysInst)
                cachedPath = cacheSys.getCached(id)
            except KeyError:
                cachedPath = None
        except ImportError:
            cachedPath = None
        if cachedPath is None:
            #No local path exist, return the collection directly
            return collectionBase.collectionBase(collectionId, dbSysInst.getCollectionDb())
    elif objTools.isUfsUrl(collectionId):
        #It is not uuid://xxx and not ufsFs:xxx, but in other ufs url format like xxxx://xxxxxx
        return getCollectionByProtocol(collectionId, dbSysInst)
    else:
        #The collectionID is not in uuid://xxxx-xxxx-xxxx format. Treat it as a path.
        cachedPath = collectionId
    #Either it is an ID that pointed to a local filesystem collection or treat it as a directory
    try:
        #print 'create new cache'
        import localLibSys
        import localLibs.collection.fileSystem.fileSystemCollection as fileSystemCollection
        import cachedCollection
        try:
            f = fileSystemCollection.fileSystemCollection(cachedPath, folderOnly)
        except fileSystemCollection.pathNotExist:
            return collectionBase.collectionBase(collectionId, dbSysInst.getCollectionDb())
        except fileSystemCollection.pathIsNotCollection:
            #print 'pathIsNotCollection, it seems to be a file', collectionId.encode('gbk', 'replace')
            return collectionInterface.emptyCollection()
        c = cachedCollection.simpleCacheCollection(dbSysInst, f)
        #print '----------------------------------'
        #print c
        return c
    except ImportError:
        pass
    raise undefinedCollection
Пример #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