Exemplo n.º 1
0
def irods_reg(fs_path, irods_path):
    """Register a file or a directory of files and subdirectory into
iRODS. The file must already exist on the server where the resource is
located. The full path must be supplied for both paths."""
    logging.warning('Use of iRODS "ireg" command SHOULD BE AVOIDED!')
    out = None
    cmdline = ['imkdir', '-p', os.path.dirname(irods_path)]
    try:
        diag.dbgcmd(cmdline)
        out = subprocess.check_output(cmdline)
    except subprocess.CalledProcessError as ex:
        cmd = ' '.join(cmdline)
        logging.error('Execution failed: {}; {} => {}'
                      .format(ex, cmd, ex.output.decode('utf-8')))
        raise

    os.chmod(fs_path, 0o664)
    cmdline = ['ireg',  '-K', fs_path, irods_path]
    try:
        diag.dbgcmd(cmdline)
        out = subprocess.check_output(cmdline)
    except subprocess.CalledProcessError as ex:
        cmd = ' '.join(cmdline)
        logging.error('Execution failed: {}; {} => {}'
                      .format(ex, cmd, ex.output.decode('utf-8')))
        raise
    return out
Exemplo n.º 2
0
def irods_file_type(irods_fname):
    logging.debug('irods_file_type({})'.format(irods_fname))

    # lut[file_type.py_key] = irods_data_type (list all using "isysmeta ldt")
    lut = dict(FITS = 'FITS image',
               JPEG = 'jpeg image',
               )
    cmdline = ['iexecmd', '-P', irods_fname, 'file_type {}'.format(irods_fname)]
    out = 'NONE'
    try:
        diag.dbgcmd(cmdline)
        out = subprocess.check_output(cmdline)
    except subprocess.CalledProcessError as ex:
        cmd = ' '.join(cmdline)
        logging.error('Execution failed: {}; {} => {}'
                      .format(ex, cmd, ex.output.decode('utf-8')))
        raise
    typeStr = out.decode('utf-8')[:-1]

    # Set datatype in metadata. Not used. Retained for future use.
    #! dt = lut.get(typeStr,'generic')
    #! cmdline = ['isysmeta', 'mod', irods_fname, 'datatype', dt]
    #! try:
    #!     out = subprocess.check_output(cmdline)
    #! except subprocess.CalledProcessError as ex:
    #!     cmd = ' '.join(cmdline)
    #!     logging.error('Execution failed: {}; {} => {}'
    #!                   .format(ex, cmd, ex.output.decode('utf-8')))
    #!     raise

    return typeStr
Exemplo n.º 3
0
def irods_get_physical(ipath):
    #!!! Open access to vault
    out = 'NONE'
    cmdline = ['iexecmd', 'open_vault.sh']
    try:
        diag.dbgcmd(cmdline)
        out = subprocess.check_output(cmdline)
    except subprocess.CalledProcessError as ex:
        cmd = ' '.join(cmdline)
        logging.error('Execution failed: {}; {} => {}'
                      .format(ex, cmd, ex.output.decode('utf-8')))
        raise

    sel = ("select DATA_PATH where COLL_NAME = '{}' and DATA_NAME = '{}'"
           .format(os.path.dirname(ipath), os.path.basename(ipath)))
    cmdline = ['iquest', '"%s"', sel]
    out = 'NONE'
    try:
        diag.dbgcmd(cmdline)
        out = subprocess.check_output(cmdline)
    except subprocess.CalledProcessError as ex:
        cmd = ' '.join(cmdline)
        logging.error('Execution failed: {}; {} => {}'
                      .format(ex, cmd, ex.output.decode('utf-8')))
        raise
    physical_fname = out.decode('utf-8').strip('\n \"')
    return physical_fname
Exemplo n.º 4
0
def get_irods_cksum(irods_path):
    cmdline = ['ichksum', irods_path]
    try:
        diag.dbgcmd(cmdline)
        out = subprocess.check_output(cmdline)
    except subprocess.CalledProcessError as ex:
        cmd = ' '.join(cmdline)
        logging.error('Execution failed: {}; {} => {}'
                      .format(ex, cmd, ex.output.decode('utf-8')))
        raise
    return(out.split()[1].decode('utf-8'))
Exemplo n.º 5
0
def irods_set_meta(ifname, att_name, att_value):
    cmdline = ['imeta', 'set', '-d', ifname, 'prep', 'True']
    out = 'NONE'
    try:
        diag.dbgcmd(cmdline)
        out = subprocess.check_output(cmdline)
    except subprocess.CalledProcessError as ex:
        cmd = ' '.join(cmdline)
        logging.error('Execution failed: {}; {} => {}'
                      .format(ex, cmd, ex.output.decode('utf-8')))
        raise
Exemplo n.º 6
0
def irods_debug():
    """For diagnostics only."""
    if logging.getLogger().isEnabledFor(logging.DEBUG):
        cmdline = ['ienv']
        try:
            diag.dbgcmd(cmdline)
            out = subprocess.check_output(cmdline)
        except subprocess.CalledProcessError as ex:
            cmd = ' '.join(cmdline)
            logging.error('Execution failed: {}; {} => {}'
                          .format(ex, cmd, ex.output.decode('utf-8')))
            raise
        logging.debug('ienv={}'.format(out.decode('utf-8')))
Exemplo n.º 7
0
def irods_unreg(irods_path):
    "unregister the file or collection"
    logging.warning('EXECUTING: "irm -U {}"; Remove need!!!'.format(irods_path))
    out = None
    cmdline = ['irm', '-U', irods_path]
    try:
        diag.dbgcmd(cmdline)
        out = subprocess.check_output(cmdline)
    except subprocess.CalledProcessError as ex:
        cmd = ' '.join(cmdline)
        logging.error('Execution failed: {}; {} => {}'
                      .format(ex, cmd, ex.output.decode('utf-8')))
        raise
    return out
Exemplo n.º 8
0
def irods_mv(src_ipath, dst_ipath):
    'Move/rename irods file' 
    logging.debug('irods_mv({}, {})'.format(src_ipath, dst_ipath))
    # imv /tempZone/mountain_mirror/vagrant/13/foo.nhs_2014_n14_299403.fits /tempZone/mountain_mirror/vagrant/13/nhs_2014_n14_299403.fits

    cmdline = ['imv', src_ipath, dst_ipath]
    out = None
    try:
        diag.dbgcmd(cmdline)
        out = subprocess.check_output(cmdline)
    except subprocess.CalledProcessError as ex:
        cmd = ' '.join(cmdline)
        logging.error('Execution failed: {}; {} => {}'
                      .format(ex, cmd, ex.output.decode('utf-8')))
        raise
    return out
Exemplo n.º 9
0
def irods_get(local_fname, irods_fname, remove_irods=False):
    'Get file from irods, creating local parent directories if needed.'
    os.makedirs(os.path.dirname(local_fname), exist_ok=True)
    cmdargs1 = ['iget', '-f', '-K', irods_fname, local_fname]
    try:
        diag.dbgcmd(cmdargs1)
        subprocess.check_output(cmdargs1)
    except subprocess.CalledProcessError as ex:
        logging.error('Execution failed: {}; {}'
                      .format(ex, ex.output.decode('utf-8')))
        raise

    if remove_irods:
        cmdargs2 = ['irm', '-f', '-U', irods_fname]
        try:
            diag.dbgcmd(cmdargs2)
            subprocess.check_output(cmdargs2)
        except subprocess.CalledProcessError as ex:
            logging.error('Execution failed: {}; {}'
                          .format(ex, ex.output.decode('utf-8')))
            raise