Esempio n. 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
Esempio n. 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
Esempio n. 3
0
 def getItemWithInfo(self, size):
     #print 'checking size:',size
     import localLibs.cache.localFileSystemCache as localFileSystemCache
     #The mongo database do not support "." in key. So use _reverse instead of .reverse
     sizeDb = self.dbSysInst.getDb(self.infoName+"_reverse")
     cacheSys = localFileSystemCache.localFileSystemCache(self.dbSysInst)
     try:
         idList = sizeDb[unicode(str(size))]
         #print 'same size id list:', idList
     except KeyError:
         idList = []
         #print 'no item found'
     res = []
     #print idList
     for i in idList:
         res.append(cacheSys.getCached(i))
     return res
Esempio n. 4
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
Esempio n. 5
0
#import libs.utils.stringTools as stringTools
import shutil
import os
import uuid
import localLibSys
import localLibs.cache.localFileSystemCache as localFileSystemCache
import libs.ufsDb.dbSys as dbSys

import libs.utils.misc as misc
import libs.utils.transform as transform



if __name__=='__main__':
    fields = libs.http.queryParam.queryInfo().getAllFieldStorageUnicode()
    h = libs.html.response.html()
    h.genTxtHead()
    dbSysInst = dbSys.dbSysSmart()
    fullPath = urllib.unquote(fields[u"path"][0])
    fullPath = transform.transformDirToInternal(fullPath)
    
    rootPath = configurationTools.getRootDir()
    recyclePath = os.path.join(rootPath, 'recycle')
    misc.ensureDir(recyclePath)

    dst = os.path.join(recyclePath, str(uuid.uuid4())+os.path.basename(fullPath))
    localFileSystemCache.localFileSystemCache(dbSysInst).moveCached(fullPath, dst)
    #print fullPath
    h.write(u'{"path":"%s","removed":"true"}'%fullPath)
    h.end()
Esempio n. 6
0
 def getId(self):
     import localLibs.cache.localFileSystemCache as localFileSystemCache
     cacheSys = localFileSystemCache.localFileSystemCache(self.dbInst)
     return cacheSys.getObjId(self.fullPath)