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
def jqueryListOnCollection(): #Get request param: collectionId, start, cnt param = webUtils.paramWithDefault({u"collectionId":u"D:/tmp",u"start":0,u"cnt":100}) #Get collection from system, collection system contains cached collections and filesystem collections. #h.write("<!--") #print "hello" if not objTools.isUuid(param["collectionId"]): #param["collectionId"] = collectionListItems.jsIdEncoding(param["collectionId"]) param["collectionId"] = stringTools.jsIdDecoding(param["collectionId"]) #h.write(unicode(str(int(param["start"])))+unicode(str(int(param["cnt"])))) co = collectionManager.getCollection(param["collectionId"], dbSys.dbSysSmart()) containerCo = container.collectionContainer(co, dbSys.dbSysSmart()).getRange(int(param["start"]), int(param["cnt"])) #Output #h.write(str(co)) #res = "" #h.write("-->") if True:#try: res = collectionListItem(containerCo) else:#except: pass h = libs.html.response.html() #print "hello" #h.write("good") h.genPartialHtmlHead() h.write(res) #h.write(l.s) #print res h.end()
def jqueryListOnCollection(req): #Get request param: collectionId, start, cnt param = webUtils.paramWithDefault({u"collectionId":u"C:/",u"start":0,u"cnt":40}, req.getQueryInfo()) #Get collection from system, collection system contains cached collections and filesystem collections. #h.write("<!--") #print "hello" print param if not objTools.isUuid(param["collectionId"]): #param["collectionId"] = collectionListItems.jsIdEncoding(param["collectionId"]) param["collectionId"] = stringTools.jsIdDecoding(param["collectionId"]) #h.write(unicode(str(int(param["start"])))+unicode(str(int(param["cnt"])))) co = collectionManager.getCollection(param["collectionId"], req.getDbSys()).getRange(int(param["start"]), int(param["cnt"])) #Output #h.write(str(co)) #res = "" #h.write("-->") if True:#try: resList = collectionListItem(co, req) else:#except: pass #h = libs.html.response.html() #print "hello" #h.write("good") req.resp.genJsonHead() req.resp.write(json.dumps(resList, indent = 4)) #h.write(l.s) #print res req.resp.end()
def jqueryListOnCollection(req): #Get request param: collectionId, start, cnt param = webUtils.paramWithDefault({u"collectionId":u"-1"}, req.getQueryInfo()) #Get collection from system, collection system contains cached collections and filesystem collections. if not objTools.isUuid(param["collectionId"]): #It is not uuid://xxxx-xxx-xxx-xxx-xxxx-xxxx param["collectionId"] = stringTools.jsIdDecoding(param["collectionId"]) #Output req.resp.genJsonHead() if param["collectionId"] == "-1": p = ufs.ufsTreeUuidItem() #res = path else: #p = desktopApp.lib.localTreeItem.localTreeItem(path.decode('utf8')) if objTools.isUfsUrl(param["collectionId"]):#try: p = ufsTreeItem.getUfsTreeItem(param["collectionId"], req) #print "after getufstreeitem" #res += str(p.listNamedChildren()) else:#except ValueError: #No schema/protocol string. Normal dir p = jsTreeItemWithCollectionBackend.jsTreeItemWithCollectionBackend(param["collectionId"], None, req.getDbSys()) #Get the checked elements in the tree try: co = collectionManager.getCollection(u"uuid://3b84d155-cc5c-428e-8009-12d5fdc68b2a", req.getDbSys()).getRange(0, None) except KeyError: co = [] #print "before containerListJson" data = jsTreeNamedItemFunc.containerListJson(p, checkedItems=co) #print data if data == u"": raise "no item, raise exception to prevent loop query" req.resp.write(data) req.resp.end()
def jqueryListOnCollection(req): #Get request param: collectionId, start, cnt param = webUtils.paramWithDefault({u"collectionId":u"-1", u"tree":u"n", u"start":0, u"cnt":40}, req.getQueryInfo()) #print param if param["collectionId"] == "-1": #################################### # It is the root element of the tree #################################### collectionItemList = ufs.ufsRootItem() elif not objTools.isUuid(param["collectionId"]): ############################################# #It is not uuid://xxxx-xxx-xxx-xxx-xxxx-xxxx ############################################# param["collectionId"] = stringTools.jsIdDecoding(param["collectionId"]) if not objTools.isUfsUrl(param["collectionId"]): param["collectionId"] = u"file:///"+param["collectionId"] #Change URL to file:///D:/tmp etc. collectionItemList = ufsCollection.getUfsCollection(param["collectionId"], req) req.resp.genJsonHead() #print collectionItemList.listNamedChildren(0, 40, False) ############################################## # Get checked item for tree ############################################## try: checkedItemList = collectionManager.getCollection(gCheckedCollectionId, req.getDbSys()).getRange(0, None) except KeyError: checkedItemList = [] #print "before containerListJson" # Check if we are generating the tree. if param["tree"] == u"n": #print "false" isTree = False start = int(param["start"]) cnt = int(param["cnt"]) else: isTree = True start = 0 cnt = None #print start, cnt #print >>sys.stderr, "-------------", start, cnt #data = "1" #################################################### # Generate JSON string for collection #################################################### data = collection2Json.containerListJson(collectionItemList, start, cnt, isTree, req, checkedItemList) #print data if data == u"": raise "no item, raise exception to prevent loop query" req.resp.write(data) req.resp.end()
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
def jqueryListOnCollection(req): #Get request param: collectionId, start, cnt param = webUtils.paramWithDefault({u"collectionId":u"-1"}, req.getQueryInfo()) #Get collection from system, collection system contains cached collections and filesystem collections. if not objTools.isUuid(param["collectionId"]): #It is not uuid://xxxx-xxx-xxx-xxx-xxxx-xxxx param["collectionId"] = stringTools.jsIdDecoding(param["collectionId"]) #Output if gDebugFlag: h = libs.html.response.html() h.genHead('Collections') res = u"" res += u'<!--' if param["collectionId"] == "-1": p = ufs.ufsTreeUuidItem() #res = path else: #p = desktopApp.lib.localTreeItem.localTreeItem(path.decode('utf8')) if objTools.isUfsUrl(param["collectionId"]):#try: #h.write(realUrl) h.setEncoding("utf8") p = ufsTreeItem.getUfsTreeItem(param["collectionId"], req) #res += str(p.listNamedChildren()) else:#except ValueError: #No schema/protocol string. Normal dir p = jsTreeItemWithCollectionBackend.jsTreeItemWithCollectionBackend(param["collectionId"], None, req.getDbSys()) #Get the checked elements in the tree try: co = collectionManager.getCollection(u"uuid://3b84d155-cc5c-428e-8009-12d5fdc68b2a", req.getDbSys()).getRange(0, None) except KeyError: co = [] data = jsTreeNamedItemFunc.containerList(p, checkedItems=co) res +=u'-->' #print res,d if data == u"": raise "no item, raise exception to prevent loop query" res += data if gDebugFlag: h.write(res) h.genEnd() else: print res.encode('gbk')
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