def store(self, item, pendingCollection):
     #Check if the item in folder storage is newer than the target one
     relaPath = item["idInCol"]
     localFullPath = transform.transformDirToInternal(os.path.join(self.rootDir, relaPath))
     localPathDir = transform.transformDirToInternal(os.path.dirname(localFullPath))
     #Check the updates of the object is done in advCollectionProcess.
     #When we come here, the item is for sure needed for update
     
     #Backup if it exists
     if os.path.exists(localFullPath):
         backupFullPath = fileTools.getFreeNameFromFullPath(os.path.join(self.backupDir, relaPath))
         backupPathDir = os.path.dirname(backupFullPath)
         misc.ensureDir(backupPathDir)
         shutil.move(localFullPath, backupFullPath)
             
     misc.ensureDir(localPathDir)
     item.saveTo(self.rootDir)
     #################################
     #Update collection info
     #################################
     #Remove the legacy timestamp
     objInfo = copy.copy(item.getItemInfo())
     if objInfo.has_key("timestamp"):
         objInfo["externalTimestamp"] = objInfo["timestamp"]
         del objInfo["timestamp"]
     
     
     obj = objectDatabase.fsObjBase(localFullPath, objInfo)
     #ncl(obj.getItemInfo())
     #print type(obj.getItemInfo())
     #ncl(self.objDb.getDbObj(obj.getItemObjUrl()))
     itemUuid = self.objDb.addDbObj(obj.getObjUrl(), obj.getItemInfo())
     ncl("collection obj uuid:", itemUuid)
     #ncl(self.objDb.getDbObj(obj.getItemObjUrl()))
     self.updateObjUuid(item["idInCol"], itemUuid)
     return True
    def run(self):
        ###############################################
        #Scan for existing files
        ###############################################
        collection = self.objDb.getCollection(self.targetCollectionId)
        cl('start scanning')
        for i in os.walk(self.rootFolder):
            #cl(i)
            for j in i[2]:
                if (self.addedItemCnt % 100) == 0:
                    cl("processing item cnt:", self.addedItemCnt)
                self.addedItemCnt += 1
                
                
                fullPath = transform.transformDirToInternal(os.path.join(i[0], j))
                #print '---------------------real adding item'
                #Update the item info for the item
                ncl('before fs obj base')
                itemUrl = objectDatabase.fsObjBase(fullPath).getObjUrl()
                ncl('before get fs obj')
                newObjUuid = self.objDb.getFsObjUuid(itemUrl)
                if newObjUuid is None:
                    cl("item deleted, do not add it")
                    continue
                ncl('before update obj uuid')
                '''
                collection.updateObjUuidIfNeeded(itemUrl, newObjUuid)
                '''
                if collection.isSame(itemUrl, newObjUuid):
                    ncl("no updates needed", itemUrl, newObjUuid)
                    continue
                collection.updateObjUuidRaw(itemUrl, newObjUuid)
                ncl('new item added', itemUrl)
                

        self.receiver.sendNotification(self.targetCollectionId)
Exemplo n.º 3
0
 def getObjUrl(self, idInCol):
     fullPath = transform.transformDirToInternal(os.path.join(self.rootDir, idInCol))
     objUrl = objectDatabase.fsObjBase(fullPath).getObjUrl()
     return objUrl