Example #1
0
def command_loop(test_command_list):
  
  # If a test command list is passed, filter the tab completion warning
  if test_command_list:
    warnings.filterwarnings("ignore", "Auto tab completion is off, because it is not available on your operating system.",
                            ImportWarning)


  # Things that may be set herein and used in later commands.
  # Contains the local variables of the original command loop.
  # Keeps track of the user's state in seash. Referenced 
  # during command executions by the command_parser.
  environment_dict = {
    'host': None, 
    'port': None, 
    'expnum': None,
    'filename': None,
    'cmdargs': None,
    'defaulttarget': None,
    'defaultkeyname': None,
    'currenttarget': None,
    'currentkeyname': None,
    'autosave': False,
    'handleinfo': {},
    'showparse': True,
    }

  

  # Set up the tab completion environment (Added by Danny Y. Huang)
  if tabcompletion:
    # Initializes seash's tab completer
    completer = tab_completer.Completer()
    readline.parse_and_bind("tab: complete")
    # Determines when a new tab complete instance should be initialized,
    # which, in this case, is never, so the tab completer will always take
    # the entire user's string into account
    readline.set_completer_delims("")
    # Sets the completer function that readline will utilize
    readline.set_completer(completer.complete)
  else:
    warnings.warn("Auto tab completion is off, because it is not available on your operating system.",ImportWarning)


  # If passed a list of commands, do not prompt for user input
  if test_command_list:
    seash_helper.update_time()
    # Iterates through test_command_list in sequential order
    for command_strings in test_command_list:
      # Saving state after each command? (Added by Danny Y. Huang)
      if environment_dict['autosave'] and environment_dict['defaultkeyname']:
        try:
          # State is saved in file "autosave_username", so that user knows which
          # RSA private key to use to reload the state.
          autosavefn = "autosave_" + str(environment_dict['defaultkeyname'])
          seash_helper.savestate(autosavefn, environment_dict['handleinfo'], environment_dict['host'], 
                                 environment_dict['port'], environment_dict['expnum'], 
                                 environment_dict['filename'], environment_dict['cmdargs'], 
                                 environment_dict['defaulttarget'], environment_dict['defaultkeyname'], 
                                 environment_dict['autosave'], environment_dict['defaultkeyname'])
        except Exception, error:
          raise seash_exceptions.UserError("There is an error in autosave: '" + str(error) + "'. You can turn off autosave using the command 'set autosave off'.")

      # Returns the dictionary of dictionaries that correspond to the
      # command string
      cmd_input = seash_dictionary.parse_command(command_strings, display_parsed_result=environment_dict['showparse'])
      
      # by default, use the target specified in the prompt
      environment_dict['currenttarget'] = environment_dict['defaulttarget']
      
      # by default, use the identity specified in the prompt
      environment_dict['currentkeyname'] = environment_dict['defaultkeyname']

      # calls the command_dispatch method of seash_dictionary to execute the callback
      # method associated with the command the user inputed
      seash_dictionary.command_dispatch(cmd_input, environment_dict)
Example #2
0
          continue
      
        # Returns the dictionary of dictionaries that correspond to the
        # command the user inputted
        cmd_input = seash_dictionary.parse_command(userinput, display_parsed_result=environment_dict['showparse'])
      
      
        # by default, use the target specified in the prompt
        environment_dict['currenttarget'] = environment_dict['defaulttarget']
        
        # by default, use the identity specified in the prompt
        environment_dict['currentkeyname'] = environment_dict['defaultkeyname']

        # calls the command_dispatch method of seash_dictionary to execute the callback
        # method associated with the command the user inputed
        seash_dictionary.command_dispatch(cmd_input, environment_dict)


 

# handle errors
      except KeyboardInterrupt:
        # print or else their prompt will be indented
        print
        # Make sure the user understands why we exited
        print 'Exiting due to user interrupt'
        return
      except EOFError:
        # print or else their prompt will be indented
        print
        # Make sure the user understands why we exited