Ejemplo n.º 1
0
def upload_from_irods(username, password, host, port, zone, irods_fnames, res_files):
    """
    use iget to transfer selected data object from irods zone to local as a NamedTemporaryFile
    :param username: iRODS login account username used to download irods data object for uploading
    :param password: iRODS login account password used to download irods data object for uploading
    :param host: iRODS login host used to download irods data object for uploading
    :param port: iRODS login port used to download irods data object for uploading
    :param zone: iRODS login zone used to download irods data object for uploading
    :param irods_fnames: the data object file name to download to local for uploading
    :param res_files: list of files for uploading to create resources
    :raises SessionException(proc.returncode, stdout, stderr) defined in django_irods/icommands.py
            to capture iRODS exceptions raised from iRODS icommand subprocess run triggered from
            any method calls from IrodsStorage() if an error or exception ever occurs
    :return: None, but the downloaded file from the iRODS will be appended to res_files list for
    uploading
    """
    irods_storage = IrodsStorage()
    irods_storage.set_user_session(username=username, password=password, host=host, port=port,
                                   zone=zone)
    ifnames = string.split(irods_fnames, ',')
    for ifname in ifnames:
        size = irods_storage.size(ifname)
        tmpFile = irods_storage.download(ifname)
        fname = os.path.basename(ifname.rstrip(os.sep))
        fileobj = File(file=tmpFile, name=fname)
        fileobj.size = size
        res_files.append(fileobj)

    # delete the user session after iRODS file operations are done
    irods_storage.delete_user_session()
Ejemplo n.º 2
0
def get_size_and_avu_for_irods_ref_files(username, password, host, port, zone,
                                         irods_fnames):
    """
    use iget to transfer selected data object from irods zone to local as a NamedTemporaryFile
    :param username: iRODS login account username used to download irods data object for uploading
    :param password: iRODS login account password used to download irods data object for uploading
    :param host: iRODS login host used to download irods data object for uploading
    :param port: iRODS login port used to download irods data object for uploading
    :param zone: iRODS login zone used to download irods data object for uploading
    :param irods_fnames: the data object file name to download to local for uploading
    :raises SessionException(proc.returncode, stdout, stderr) defined in django_irods/icommands.py
            to capture iRODS exceptions raised from iRODS icommand subprocess run triggered from
            any method calls from IrodsStorage() if an error or exception ever occurs
    :return: list of file sizes corresponding to irods_fnames, and extra metadata dicts with each dict item
             corresponding to iRODS AVUs on the file or data object with file name preappended to attributes
    """
    irods_storage = IrodsStorage()
    irods_storage.set_user_session(username=username,
                                   password=password,
                                   host=host,
                                   port=port,
                                   zone=zone)
    ifnames = string.split(irods_fnames, ',')

    ifsizes = []
    ifextra_mds = {}
    for ifname in ifnames:
        size = irods_storage.size(ifname)
        ifsizes.append(size)
        extra_md_dict = irods_storage.getAVU(ifname, type='-d')
        for key, val in extra_md_dict.iteritems():
            ukey = ifname + '_' + key
            ifextra_mds[ukey] = val

    # delete the user session after iRODS file operations are done
    irods_storage.delete_user_session()
    return ifsizes, ifextra_mds