コード例 #1
0
    def fetch_metadata(self, session, id, mType):
        """ Open irodsFile and get metadata from it. """

        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()
            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
        umd = irods.getFileUserMetadata(self.cxn,
                                        '{0}/{1}'.format(collPath, id)
                                        )

#        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
#        umd = f.getUserMetadata()
#        f.close()

        val = None
        for x in umd:
            if x[0] == mType:
                val = icatValToPy(x[1], x[2])
                break

        for x in range(upwards):
            self.coll.upCollection()
        return val
コード例 #2
0
    def find_documents(self, session, cache=0):
        # Given a location in irods, go there and descend looking for files
        c = self.coll
        files = c.getObjects()
        files.sort()
        fList = [x[0] for x in files]
        for i, f in enumerate(self._processFiles(session, fList)):
            md = {}
            irodsFilePath = '{0}/{1}'.format(c.getCollName(), f.filename)
            for x in irods.getFileUserMetadata(self.cxn, irodsFilePath):
                md[x[0]] = icatValToPy(x[1], x[2])
            if len(md):
                f.metadata['iRODS'] = md
            # Delete the file on its resource
            c.delete(files[i][0], files[i][1])
            yield f

        dirs = c.getSubCollections()
        while dirs:
            d = dirs.pop(0)
            upColls = 0
            for dx in d.split('/'):
                c.openCollection(dx)
                upColls += 1

            files = c.getObjects()
            files.sort()
            fList = [x[0] for x in files]
            for i, f in enumerate(self._processFiles(session, fList)):
                md = {}
                irodsFilePath = '{0}/{1}'.format(c.getCollName(), f.filename)
                for x in irods.getFileUserMetadata(self.cxn, irodsFilePath):
                    md[x[0]] = icatValToPy(x[1], x[2])
                if len(md):
                    f.metadata['iRODS'] = md
                # Delete the file on its resource
                c.delete(files[i][0], files[i][1])
                yield f
            ndirs = c.getSubCollections()
            dirs.extend(["%s/%s" % (d, x) for x in ndirs])
            for x in range(upColls):
                c.upCollection()
コード例 #3
0
    def find_documents(self, session, cache=0):
        # Given a location in irods, go there and descend looking for files
        c = self.coll
        files = c.getObjects()
        files.sort()
        fList = [x[0] for x in files]
        for i, f in enumerate(self._processFiles(session, fList)):
            md = {}
            irodsFilePath = '{0}/{1}'.format(c.getCollName(), f.filename)
            for x in irods.getFileUserMetadata(self.cxn, irodsFilePath):
                md[x[0]] = icatValToPy(x[1], x[2])
            if len(md):
                f.metadata['iRODS'] = md
            # Delete the file on its resource
            c.delete(files[i][0], files[i][1])
            yield f

        dirs = c.getSubCollections()
        while dirs:
            d = dirs.pop(0)
            upColls = 0
            for dx in d.split('/'):
                c.openCollection(dx)
                upColls += 1

            files = c.getObjects()
            files.sort()
            fList = [x[0] for x in files]
            for i, f in enumerate(self._processFiles(session, fList)):
                md = {}
                irodsFilePath = '{0}/{1}'.format(c.getCollName(), f.filename)
                for x in irods.getFileUserMetadata(self.cxn, irodsFilePath):
                    md[x[0]] = icatValToPy(x[1], x[2])
                if len(md):
                    f.metadata['iRODS'] = md
                # Delete the file on its resource
                c.delete(files[i][0], files[i][1])
                yield f
            ndirs = c.getSubCollections()
            dirs.extend(["%s/%s" % (d, x) for x in ndirs])
            for x in range(upColls):
                c.upCollection()
コード例 #4
0
    def find_documents(self, session, cache=0):
        # given a location in irods, go there and descend looking for files
        c = self.coll
        files = c.getObjects()
        files = [x[0] for x in files]
        files.sort()
        for f in self._processFiles(session, files):
            md = {}
            for x in irods.getFileUserMetadata(self.cxn, '{0}/{1}'.format(c.getCollName(), f.filename)):
                md[x[0]] = icatValToPy(x[1], x[2])
            if len(md):
                f.metadata['iRODS'] = md
            yield f

        dirs = c.getSubCollections()
        while dirs:
            d = dirs.pop(0)
            upColls = 0
            for dx in d.split('/'):
                c.openCollection(dx)
                upColls += 1

            files = c.getObjects()
            files = [x[0] for x in files]
            files.sort()
            for f in self._processFiles(session, files):
                md = {}
                for x in irods.getFileUserMetadata(self.cxn, '{0}/{1}'.format(c.getCollName(), f.filename)):
                    md[x[0]] = icatValToPy(x[1], x[2])
                if len(md):
                    f.metadata['iRODS'] = md
                yield f

            ndirs = c.getSubCollections()
            dirs.extend(["%s/%s" % (d, x) for x in ndirs])
            for x in range(upColls):
                c.upCollection()
コード例 #5
0
def sync_irods(params, id):
    """
    Fetches a resource from database with the same path as user specified and 
    that matches an existing resource in CKAN.
    """
    from irods import getFileUserMetadata, rcModAccessControl
    rev = model.repo.new_revision()
    conn = get_connection_from_params(params)
    resource = Resource.get(id)
    path = params['path']
    extras = {}
    # Lets handle only resources with file names
    if resource.name:
        fname = "%s/%s" % (path, resource.name.split('/')[-1])
        log.debug(fname)
        i = 0
        access = rcModAccessControl()
        log.debug(access.getPath())
        if conn:
            for met in getFileUserMetadata(conn, fname):
                i += 1
                key, value, _ = met
                extras[key] = value
            resource.extras = extras
            Session.add(resource)
            conn.disconnect()
            model.repo.commit()
            rev.message = "Update from iRODS, matched file %s" % fname
            h.flash_success(
                "iRODS import to resource OK! Imported %s metadatas" % i)
        else:
            h.flash_error("Could not connect to iRODS!")
    else:
        h.flash_error("Resource is an URL, cannot import!")
    h.redirect_to(controller='package', action='resource_read', \
              id=resource.resource_group.package.name, \
              resource_id=resource.id)
コード例 #6
0
def sync_irods(params, id):
    """
    Fetches a resource from database with the same path as user specified and 
    that matches an existing resource in CKAN.
    """
    from irods import getFileUserMetadata, rcModAccessControl
    rev = model.repo.new_revision()
    conn = get_connection_from_params(params)
    resource = Resource.get(id)
    path = params['path']
    extras = {}
    # Lets handle only resources with file names
    if resource.name:
        fname = "%s/%s" % (path, resource.name.split('/')[-1])
        log.debug(fname)
        i = 0
        access = rcModAccessControl()
        log.debug(access.getPath())
        if conn:
            for met in getFileUserMetadata(conn, fname):
                i += 1
                key, value, _ = met
                extras[key] = value
            resource.extras = extras
            Session.add(resource)
            conn.disconnect()
            model.repo.commit()
            rev.message = "Update from iRODS, matched file %s" % fname
            h.flash_success("iRODS import to resource OK! Imported %s metadatas" % i)
        else:
            h.flash_error("Could not connect to iRODS!")
    else:
        h.flash_error("Resource is an URL, cannot import!")
    h.redirect_to(controller='package', action='resource_read', \
              id=resource.resource_group.package.name, \
              resource_id=resource.id)
コード例 #7
0
ファイル: app_model.py プロジェクト: kaldrill/irodspython
 def get_file_metadatas(self, irods_path):
     """Get a list of metadatas for a file
     a metadata is a tuple (name, value, units)"""
     return irods.getFileUserMetadata(self.conn, irods_path)