Ejemplo n.º 1
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()
Ejemplo n.º 2
0
 def add_file_metadata(self, irods_path, name, value, units=''):
     """Add metadatas to a file"""
     return irods.addFileUserMetadata(self.conn, irods_path, name, value,
                                      units)