#! /usr/bin/env python

import os.path
from mcia_irods_utils import IrodsCommand, iargw, isrel, guess_icwd

imv = IrodsCommand( "imv" )

if __name__ == "__main__":
    import sys

    icwd = guess_icwd()

    args = iargw( sys.argv[1:] )

    # because we spawn imv in a subprocess, we need to expand relative paths here,
    # otherwise, imv wouldn't recognize wd correctly
    newargs = []
    for arg in args:
        if isrel( arg ) and not arg.startswith( '-' ):
            arg = os.path.normpath( icwd + '/' + arg )
        newargs.append( arg )

    retcode, output = imv( newargs )

    print output.rstrip()

    sys.exit( retcode )
