(command)
Find a command in our path
Find a command in our path
Find a command in our path
def path_lookup(command):
    '''Find a command in our path'''
    if os.path.isabs(command):
        if os.path.isfile(command):
            return(command)
        else:
            return(None)
    elif command[:2] == './' and os.path.isfile(command):
        dbg('path_lookup: Relative filename %s found in cwd' % command)
        return(command)

    try:
        paths = os.environ['PATH'].split(':')
        if len(paths[0]) == 0: 
            raise(ValueError)
    except (ValueError, NameError):
        dbg('path_lookup: PATH not set in environment, using fallbacks')
        paths = ['/usr/local/bin', '/usr/bin', '/bin']

    dbg('path_lookup: Using %d paths: %s' % (len(paths), paths))

    for path in paths:
        target = os.path.join(path, command)
        if os.path.isfile(target):
            dbg('path_lookup: found %s' % target)
            return(target)

    dbg('path_lookup: Unable to locate %s' % command)
def path_lookup ( command ) : if os . path . isabs ( command ) : if os . path . isfile ( command ) : return ( command ) else : return ( None ) elif command [ : 2 ] == './' and os . path . isfile ( command ) : dbg ( 'path_lookup: Relative filename %s found in cwd' % command ) return ( command ) try : paths = os . environ [ 'PATH' ] . split ( ':' ) if len ( paths [ 0 ] ) == 0 : raise ( ValueError ) except ( ValueError , NameError ) : dbg ( 'path_lookup: PATH not set in environment, using fallbacks' ) paths = [ '/usr/local/bin' , '/usr/bin' , '/bin' ] dbg ( 'path_lookup: Using %d paths: %s' % ( len ( paths ) , paths ) ) for path in paths : target = os . path . join ( path , command ) if os . path . isfile ( target ) : dbg ( 'path_lookup: found %s' % target ) return ( target ) dbg ( 'path_lookup: Unable to locate %s' % command )