def transfer_toClient( self, fileID, token, fileHelper ):
    """ Method to send files to clients.
fileID is the local file name in the SE.
token is used for access rights confirmation.
"""

    conn , error = self.__irodsClient( "r" )
    if not conn:
      return S_ERROR( error )

    file_path = self.__resolveFileID( fileID )
    file_path = IRODS_HOME + file_path
    gLogger.debug( "file_path to read: %s" % file_path )

    fd = iRodsOpen( conn , file_path , "r" )
    if not fd:
      rcDisconnect( conn )
      gLogger.error( "Failed to get file object" )
      return S_ERROR( "Failed to get file object" )

    result = fileHelper.FileToNetwork( fd )
    fd.close()

    rcDisconnect( conn )
    if not result[ "OK" ]:
      gLogger.error( "Failed to get file " + fileID )
      return S_ERROR( "Failed to get file " + fileID )
    else:
      return result
Beispiel #2
0
    def transfer_toClient(self, fileID, token, fileHelper):
        """ Method to send files to clients.
fileID is the local file name in the SE.
token is used for access rights confirmation.
"""

        conn, error = self.__irodsClient("r")
        if not conn:
            return S_ERROR(error)

        file_path = self.__resolveFileID(fileID)
        file_path = IRODS_HOME + file_path
        gLogger.debug("file_path to read: %s" % file_path)

        fd = iRodsOpen(conn, file_path, "r")
        if not fd:
            rcDisconnect(conn)
            gLogger.error("Failed to get file object")
            return S_ERROR("Failed to get file object")

        result = fileHelper.FileToNetwork(fd)
        fd.close()

        rcDisconnect(conn)
        if not result["OK"]:
            gLogger.error("Failed to get file " + fileID)
            return S_ERROR("Failed to get file " + fileID)
        else:
            return result
Beispiel #3
0
def irods_isfile(url, **kw):
    chk_cache()
    with IrodsConnection(url, **kw) as ic:
        log.debug("irods_delete %s -> %s", url, ic.path)
        f = irods.iRodsOpen(ic.conn, ic.path, 'r')  # pylint: disable=no-member
        if f:
            f.close()
            return True
        return False
Beispiel #4
0
def irods_delete_file(url, **kw):
    chk_cache()
    ic = IrodsConnection(url, **kw)
    log.debug("irods-path %s", ic.path)
    localname = irods_cache_fetch(ic.path)
    if localname is not None:
        os.remove(localname)
    with ic:
        log.debug("irods_delete %s -> %s", url, ic.path)
        f = irods.iRodsOpen(ic.conn, ic.path)  # pylint: disable=no-member
        if not f:
            raise IrodsError("can't read from %s" % url)
        f.close()
        f.delete()
Beispiel #5
0
def irods_push_file(fileobj, url, savelocal=True, **kw):
    chk_cache()
    with IrodsConnection(url, **kw) as ic:
        # Hmm .. if an irodsEnv exists then it is used over our login name provided above,
        # meaning even though we have logged in as user X we may be the homedir of user Y (in .irodsEnv)
        # irods.mkCollR(conn, basedir, os.path.dirname(path))
        retcode = irods.mkCollR(ic.conn, '/', os.path.dirname(ic.path))  # pylint: disable=no-member
        log.debug("irods-path %s", ic.path)
        f = irods.iRodsOpen(ic.conn, ic.path, 'w')  # pylint: disable=no-member
        if f:
            localname = irods_cache_save(fileobj, ic.path, f)
            f.close()
            return localname
        raise IrodsError("can't write irods url %s" % url)
Beispiel #6
0
def irods_fetch_file(url, **kw):
    chk_cache()
    ic = IrodsConnection(url, **kw)
    log.debug("irods-path %s", ic.path)
    localname = irods_cache_fetch(ic.path)
    if localname is None:
        with ic:
            log.debug("irods_fetching %s -> %s", url, ic.path)
            f = irods.iRodsOpen(ic.conn, ic.path)  # pylint: disable=no-member
            if not f:
                raise IrodsError("can't read from %s", url)
            localname = irods_cache_save(f, ic.path)
            f.close()
    return localname
Beispiel #7
0
	def getIrodsMetrics(self):

                irodsMetrics = None
                conn = self.mRods.getConnection()

		if (conn is not None):
                	metricsFile = self.mRods.getMetricsFilePath() \
                        	+ '/' + self.__class__.__name__ + '.json'
                	f = irods.iRodsOpen(conn, metricsFile, 'r')
                	if f is not None:
                        	metricsStream = f.read()
                        	irodsMetrics = json.loads(metricsStream)
                        	f.close
			self.mRods.disconnect()

                return irodsMetrics
Beispiel #8
0
def import_collection_to_package(params, id):
    """
    Import a collection to dataset. Does not import whole file data but
    rather the metadata.
    """
    from irods import irodsCollection
    path = params['path']
    pkg = Package.get(id)
    conn = get_connection_from_params(params)
    if (conn):
        coll = irodsCollection(conn, path)
        from irods import iRodsOpen
        rev = model.repo.new_revision()
        i = 0
        for obj in coll.getObjects():
            extras = {}
            fname, _ = obj
            fpath = "%s/%s" % (coll.getCollName(), fname)
            f = iRodsOpen(conn, fpath, 'r')
            if f:
                i += 1
                res = Resource.by_name(fname)
                if not res:
                    res = Resource(url = '', name=fname, extras=extras, \
                                   resource_type='file')
                for met in f.getUserMetadata():
                    key, value, _ = met
                    extras[key] = value
                res.extras = extras
                resgrp = pkg.resource_groups[0]
                resgrp.resources.append(res)
                Session.add(res)
                Session.add(resgrp)
                rev.message = "Update from iRODS, matched file %s" % fname
        for met in coll.getUserMetadata():
            key, value, _ = met
            pkg.extras[key] = value
        Session.add(pkg)
        model.repo.commit()
        conn.disconnect()
        h.flash_success("iRODS import to dataset OK! Imported %s resources." %
                        i)
    else:
        h.flash_error("Could not connect to iRODS!")
    h.redirect_to(controller='package', action='read', id=id)
def import_collection_to_package(params, id):
    """
    Import a collection to dataset. Does not import whole file data but
    rather the metadata.
    """
    from irods import irodsCollection
    path = params['path']
    pkg = Package.get(id)
    conn = get_connection_from_params(params)
    if (conn):
        coll = irodsCollection(conn, path)
        from irods import iRodsOpen
        rev = model.repo.new_revision()
        i = 0
        for obj in coll.getObjects():
            extras = {} 
            fname, _ = obj
            fpath = "%s/%s" % (coll.getCollName(), fname) 
            f = iRodsOpen(conn, fpath, 'r')
            if f:
                i += 1
                res = Resource.by_name(fname)
                if not res:
                    res = Resource(url = '', name=fname, extras=extras, \
                                   resource_type='file')
                for met in f.getUserMetadata():
                    key, value, _ = met
                    extras[key] = value
                res.extras = extras
                resgrp = pkg.resource_groups[0]
                resgrp.resources.append(res)
                Session.add(res)
                Session.add(resgrp)
                rev.message = "Update from iRODS, matched file %s" % fname
        for met in coll.getUserMetadata():
            key, value, _ = met
            pkg.extras[key] = value
        Session.add(pkg)
        model.repo.commit()
        conn.disconnect()
        h.flash_success("iRODS import to dataset OK! Imported %s resources." % i)
    else:
        h.flash_error("Could not connect to iRODS!")
    h.redirect_to(controller='package', action='read', id=id)
Beispiel #10
0
        def setIrodsMetrics(self, metrics):

                if (metrics is None):
                        return

                irodsMetricsList = list()

                # retrieve list of metrics passed in
                tmpMetricsList = metrics[self.__class__.__name__]

                # first see if irods metrics already exist
                irodsMetrics = self.getIrodsMetrics()
                if irodsMetrics is not None:
                        irodsMetricsList = \
                                 irodsMetrics[self.__class__.__name__]

                # now add my new metrics to these metrics
                irodsMetricsList += tmpMetricsList
                metrics[self.__class__.__name__] = irodsMetricsList

                # finally save as a json file to iRODS
                conn = self.mRods.getConnection()
		if (conn is not None):
			# create the guinan collection in iRODS if it does not already exist
			metricsCollection = self.mRods.getMetricsFilePath()
			self.createGuinanCollection()

                	metricsFile = metricsCollection \
                        	+ '/' + self.__class__.__name__ + '.json'
                	f = irods.iRodsOpen(conn, metricsFile, 'w')
                	if f is not None:
                        	metricsJson = json.dumps(metrics)
                        	f.write(metricsJson)
                        	f.close()
                        	logging.debug('Saved updated metrics to iRODS')
			self.mRods.disconnect()