def parse_options()

in python/awis.py [0:0]


def parse_options( argv ):
    """Parse command line options."""

    opts = {}

    urlargs = {}

    try:
        user_opts, user_args = getopt.getopt( \
            argv, \
            'k:u:o:a:t:?', \
            [ 'key=', 'user=', 'options=', 'action=', 'help=' ] )
    except Exception as e:
        print('Command parse error:', e)
        log.error( "Unable to parse command line" )
        return None

    if ( '-?', '' ) in user_opts or ( '--help', '' ) in user_opts:
        opts['help'] = True
        return opts
    #
    # Convert command line options to dictionary elements
    #
    for opt in user_opts:
        if  opt[0] == '-k' or opt[0] == '--key':
            opts['key'] = opt[1]
        elif opt[0] == '-u' or opt[0] == '--user':
            opts['user'] = opt[1]
        elif opt[0] == '-a' or opt[0] == '--action':
            opts['action'] = opt[1]
        elif opt[0] == '-o' or opt[0] == '--options':
            opts['options'] = opt[1]
        elif opt[0] == '--action':
            opts['action'] = opt[1]
        elif opt[0] == '-v' or opt[0] == '--verbose':
            log.verbose()

    if 'key' not in opts or \
       'user' not in opts or \
       'action' not in opts:
        log.error( "Missing required arguments" )
        return None

    #
    # Return a dictionary of settings
    #
    success = True
    return opts