(module)
The user has selected a module, so we should parse out all the
        options for this particular module, set the config, and when
        requested, run it.  This is kinda messy, but works for now.
The user has selected a module, so we should parse out all the
        options for this particular module, set the config, and when
        requested, run it.  This is kinda messy, but works for now.
The user has selected a module so we should parse out all the options for this particular module set the config and when requested run it . This is kinda messy but works for now .
def handle_opts(module):
    """ The user has selected a module, so we should parse out all the
        options for this particular module, set the config, and when
        requested, run it.  This is kinda messy, but works for now.
    """
    # fetch generic module options and module-specific options
    options = module.config

    # dump module settings
    Setting = ['', 'Option', 'Value', 'Type', 'Required'] 
    table = display_options(options, Setting)
    while True:
        # fetch command/option
        try:
            choice = raw_input('%s > ' % (color.B_WHITE + module.which + color.END))

            # first check global commands
            tmp = check_opts(choice)
            if tmp == -1:
                continue

            # check module commands
            if choice is "0":
                return False
            elif choice == "info":
                if module.info is None:
                    Msg("Module has no information available")
                    continue

                print '%s%s%s' % (color.GREEN,
                                 '-' * len(module.info.split('\n')[1].strip()),
                                  color.END),
                print dedent(module.info.rstrip())
                print '%s%s%s' % (color.GREEN,
                                  '-' * len(module.info.split('\n')[1].strip()),
                                  color.END)
            elif choice == "ops":
                display_options(options, Setting)
                continue
            elif len(choice.split(' ')) > 1:
                choice = choice.split(' ')
                try:
                    if int(choice[0]) > len(table):
                        continue
                    elif int(choice[0]) is 0:
                        return False

                    key = options.keys()[int(choice[0])-1]

                    if choice[1] == 'o' and module.config[key].opts is not None:
                        Msg("Options: %s" % module.config[key].opts)
                        continue
                    elif choice[1] == 'o' and module.config[key].type == 'list':
                        Msg('%s' % module.config[key].value)
                        continue

                    # generate a temporary zoption
                    tmp = copy(module.config[key])
                    tmp.value = ' '.join(choice[1::])

                    # we've got a valid number, validate the type and set it
                    if not tmp.validate():
                        Error('Wrong type assigned.  Expected value of type "%s"'%
                                        options[key].type)
                    else:
                        module.config[key] = tmp

                except Exception, e:
                    Error('%s' % e) 
                    continue
            elif "r" in choice.lower() or "run" in choice.lower():
                # verify all required options are set
                for opt in options.keys():
                    if options[opt].required and options[opt].value is None:
                        Error('Option \'%s\' is required.'%opt)
                        raise FailedCheck
                return True
        except KeyboardInterrupt:
            return False
        except FailedCheck:
            continue
        except Exception, e:
            Error('%s' % e)
def handle_opts ( module ) : # fetch generic module options and module-specific options options = module . config # dump module settings Setting = [ '' , 'Option' , 'Value' , 'Type' , 'Required' ] table = display_options ( options , Setting ) while True : # fetch command/option try : choice = raw_input ( '%s > ' % ( color . B_WHITE + module . which + color . END ) ) # first check global commands tmp = check_opts ( choice ) if tmp == - 1 : continue # check module commands if choice is "0" : return False elif choice == "info" : if module . info is None : Msg ( "Module has no information available" ) continue print '%s%s%s' % ( color . GREEN , '-' * len ( module . info . split ( '\n' ) [ 1 ] . strip ( ) ) , color . END ) , print dedent ( module . info . rstrip ( ) ) print '%s%s%s' % ( color . GREEN , '-' * len ( module . info . split ( '\n' ) [ 1 ] . strip ( ) ) , color . END ) elif choice == "ops" : display_options ( options , Setting ) continue elif len ( choice . split ( ' ' ) ) > 1 : choice = choice . split ( ' ' ) try : if int ( choice [ 0 ] ) > len ( table ) : continue elif int ( choice [ 0 ] ) is 0 : return False key = options . keys ( ) [ int ( choice [ 0 ] ) - 1 ] if choice [ 1 ] == 'o' and module . config [ key ] . opts is not None : Msg ( "Options: %s" % module . config [ key ] . opts ) continue elif choice [ 1 ] == 'o' and module . config [ key ] . type == 'list' : Msg ( '%s' % module . config [ key ] . value ) continue # generate a temporary zoption tmp = copy ( module . config [ key ] ) tmp . value = ' ' . join ( choice [ 1 : : ] ) # we've got a valid number, validate the type and set it if not tmp . validate ( ) : Error ( 'Wrong type assigned.  Expected value of type "%s"' % options [ key ] . type ) else : module . config [ key ] = tmp except Exception , e : Error ( '%s' % e ) continue elif "r" in choice . lower ( ) or "run" in choice . lower ( ) : # verify all required options are set for opt in options . keys ( ) : if options [ opt ] . required and options [ opt ] . value is None : Error ( 'Option \'%s\' is required.' % opt ) raise FailedCheck return True except KeyboardInterrupt : return False except FailedCheck : continue except Exception , e : Error ( '%s' % e )