Example #1
0
 def clean(self, session):
     """ Delete expired data objects. """
     now = time.time()
     now = pyValToIcat(now)[0]
     matches = self._queryMetadata(session, 'expires', '<', now)
     for m in matches:
         self.delete_data(session, m)
     return None
Example #2
0
 def commit_metadata(self, session):
     mymd = self.get_metadataTypes(session)
     # need to delete values first
     umd = self.coll.getUserMetadata()
     umdHash = {}
     for u in umd:
         umdHash[u[0]] = u[1:]            
     for md in mymd:
         try:
             self.coll.rmUserMetadata(md, umdHash[md][0])
         except KeyError:
             # not been set yet
             pass
         val, un = pyValToIcat(getattr(self, md))
         self.coll.addUserMetadata(md, val, un)
Example #3
0
    def store_metadata(self, session, id, mType, value):
        """ Store value for mType metadata against id. """
        if (self.idNormalizer is not None):
            id = self.idNormalizer.process_string(session, id)
        elif type(id) == unicode:
            id = id.encode('utf-8')
        else:
            id = str(id)

        self._open(session)
        upwards = 0
        if id.find('/') > -1 and self.allowStoreSubDirs:
            idp = id.split('/')
            id = idp.pop()  # file is final part
            while idp:
                dn = idp.pop(0)
                if not dn in self.coll.getSubCollections():
                    for x in range(upwards):
                        self.coll.upCollection()
                    raise ObjectDoesNotExistException(id)
                self.coll.openCollection(dn)
                upwards += 1
        else:
            id = id.replace('/', '--')

        collPath = self.coll.getCollName()
        # this is much more efficient than getting the file as it's simply
        # interacting with iCAT
        irods.addFileUserMetadata(self.cxn,
                                  '{0}/{1}'.format(collPath, id),
                                  mType, *pyValToIcat(value)
                                  )

#        if self.resource:
#                f = self.coll.open(id, rescName=self.resource)
#            else:
#                f = self.coll.open(id)
#
#        if not f:
#            for x in range(upwards):
#        	self.coll.upCollection()
#            return None
#
#        f.addUserMetadata(mType, *pyValToIcat(value))
#        f.close()

        for x in range(upwards):
            self.coll.upCollection()
     def _queryMetadata(self, session, attName, opName, attValue):
 
         genQueryInp = irods.genQueryInp_t()
         # select what we want to fetch
         i1 = irods.inxIvalPair_t()
         i1.addInxIval(irods.COL_DATA_NAME, 0)
         genQueryInp.setSelectInp(i1)
 
         attValue, units = pyValToIcat(attValue)
         
         i2 = irods.inxValPair_t()
         i2.addInxVal(irods.COL_META_DATA_ATTR_NAME, "='%s'" % attName)
         i2.addInxVal(irods.COL_META_DATA_ATTR_VALUE,
                      "%s '%s'" % (opName, attValue))
 
         self._open(session)
         collName = self.coll.getCollName()
         i2.addInxVal(irods.COL_COLL_NAME, "= '%s'" % collName)
 
         genQueryInp.setSqlCondInp(i2)
 
         # configure paging
         genQueryInp.setMaxRows(1000)
         genQueryInp.setContinueInx(0)
 
         matches = []
         # do query
         genQueryOut, status = irods.rcGenQuery(self.cxn, genQueryInp)
         if status == irods_error.CAT_NO_ROWS_FOUND:
             return []
         elif status == 0:
             sqlResults = genQueryOut.getSqlResult()
             matches = sqlResults[0].getValues()
         
         while status == 0 and genQueryOut.getContinueInx() > 0:
             genQueryInp.setContinueInx(genQueryOut.getContinueInx())
             genQueryOut, status = irods.rcGenQuery(self.cxn, genQueryInp)
             sqlResults = genQueryOut.getSqlResult()
             matches.extend(sqlResults[0].getValues())
         return matches
Example #5
0
    def _queryMetadata(self, session, attName, opName, attValue):

        genQueryInp = irods.genQueryInp_t()
        # select what we want to fetch
        i1 = irods.inxIvalPair_t()
        i1.addInxIval(irods.COL_DATA_NAME, 0)
        genQueryInp.setSelectInp(i1)

        attValue, units = pyValToIcat(attValue)
        
        i2 = irods.inxValPair_t()
        i2.addInxVal(irods.COL_META_DATA_ATTR_NAME, "='%s'" % attName)
        i2.addInxVal(irods.COL_META_DATA_ATTR_VALUE, "%s '%s'" % (opName, attValue))

        self._open(session)
        collName = self.coll.getCollName()
        i2.addInxVal(irods.COL_COLL_NAME, "= '%s'" % collName)

        genQueryInp.setSqlCondInp(i2)

        # configure paging
        genQueryInp.setMaxRows(1000)
        genQueryInp.setContinueInx(0)

        matches = []
        # do query
        genQueryOut, status = irods.rcGenQuery(self.cxn, genQueryInp)
        if status == irods_error.CAT_NO_ROWS_FOUND:
            return []
        elif status == 0:
            sqlResults = genQueryOut.getSqlResult()
            matches = sqlResults[0].getValues()
        
        while status == 0 and genQueryOut.getContinueInx() > 0:
            genQueryInp.setContinueInx(genQueryOut.getContinueInx())
            genQueryOut, status = irods.rcGenQuery(self.cxn, genQueryInp)
            sqlResults = genQueryOut.getSqlResult()
            matches.extend(sqlResults[0].getValues())
        return matches