Exemplo n.º 1
0
def parse_options(options):
    """ Parse the specified options and initialize all required structures
  Note: This modifies global state, specifically, the emulcomm module
  """
    if options.ip:
        emulcomm.user_ip_interface_preferences = True

        # Append this ip to the list of available ones if it is new
        for ip in options.ip:
            if (True, ip) not in emulcomm.user_specified_ip_interface_list:
                emulcomm.user_specified_ip_interface_list.append((True, ip))

    if options.interface:
        emulcomm.user_ip_interface_preferences = True

        # Append this interface to the list of available ones if it is new
        for interface in options.interface:
            if (False, interface
                ) not in emulcomm.user_specified_ip_interface_list:
                emulcomm.user_specified_ip_interface_list.append(
                    (False, interface))

    # Check if they have told us to only use explicitly allowed IP's and interfaces
    if options.nootherips:
        # Set user preference to True
        emulcomm.user_ip_interface_preferences = True
        # Disable nonspecified IP's
        emulcomm.allow_nonspecified_ips = False

    # set up the circular log buffer...
    # Armon: Initialize the circular logger before starting the nanny
    if options.logfile:
        # time to set up the circular logger
        loggerfo = loggingrepy.circular_logger(options.logfile)
        # and redirect err and out there...
        sys.stdout = loggerfo
        sys.stderr = loggerfo
    else:
        # let's make it so that the output (via print) is always flushed
        sys.stdout = loggingrepy.flush_logger(sys.stdout)

    # We also need to pass in whether or not we are going to be using the service
    # log for repy.  We provide the repy directory so that the vessel information
    # can be found regardless of where we are called from...
    tracebackrepy.initialize(options.servicelog, repy_constants.REPY_START_DIR)

    # Set Current Working Directory
    if options.cwd:
        os.chdir(options.cwd)

    # Update repy current directory
    repy_constants.REPY_CURRENT_DIR = os.path.abspath(os.getcwd())

    # Initialize the NM status interface
    nmstatusinterface.init(options.stopfile, options.statusfile)

    # Write out our initial status
    statusstorage.write_status("Started")
Exemplo n.º 2
0
def parse_options(options):
  """ Parse the specified options and initialize all required structures
  Note: This modifies global state, specifically, the emulcomm module
  """
  if options.ip:
    emulcomm.user_ip_interface_preferences = True

    # Append this ip to the list of available ones if it is new
    for ip in options.ip:
      if (True, ip) not in emulcomm.user_specified_ip_interface_list:
        emulcomm.user_specified_ip_interface_list.append((True, ip))

  if options.interface:
    emulcomm.user_ip_interface_preferences = True
      
    # Append this interface to the list of available ones if it is new
    for interface in options.interface:
      if (False, interface) not in emulcomm.user_specified_ip_interface_list:
        emulcomm.user_specified_ip_interface_list.append((False, interface))

  # Check if they have told us to only use explicitly allowed IP's and interfaces
  if options.nootherips:
    # Set user preference to True
    emulcomm.user_ip_interface_preferences = True
    # Disable nonspecified IP's
    emulcomm.allow_nonspecified_ips = False
    
  # set up the circular log buffer...
  # Armon: Initialize the circular logger before starting the nanny
  if options.logfile:
    # time to set up the circular logger
    loggerfo = loggingrepy.circular_logger(options.logfile)
    # and redirect err and out there...
    sys.stdout = loggerfo
    sys.stderr = loggerfo
  else:
    # let's make it so that the output (via print) is always flushed
    sys.stdout = loggingrepy.flush_logger(sys.stdout)
    
  # We also need to pass in whether or not we are going to be using the service
  # log for repy.  We provide the repy directory so that the vessel information
  # can be found regardless of where we are called from...
  tracebackrepy.initialize(options.servicelog, repy_constants.REPY_START_DIR)

  # Set Current Working Directory
  if options.cwd:
    os.chdir(options.cwd)

  # Update repy current directory
  repy_constants.REPY_CURRENT_DIR = os.path.abspath(os.getcwd())

  # Initialize the NM status interface
  nmstatusinterface.init(options.stopfile, options.statusfile)
  
  # Write out our initial status
  statusstorage.write_status("Started")
Exemplo n.º 3
0
def repy_main(argv=sys.argv):
  """Run repy with these command line arguments"""
  global simpleexec
  global logfile

  # Armon: The CMD line path to repy is the first argument
  repy_location = argv[0]

  # Get the directory repy is in
  repy_directory = os.path.dirname(repy_location)
  
  # Translate into an absolute path
  if os.path.isabs(repy_directory):
    absolute_repy_directory = repy_directory
  
  else:
    # This will join the currect directory with the relative path
    # and then get the absolute path to that location
    absolute_repy_directory = os.path.abspath(os.path.join(os.getcwd(), repy_directory))
  
  # Store the absolute path as the repy startup directory
  repy_constants.REPY_START_DIR = absolute_repy_directory
 
  # For security, we need to make sure that the Python path doesn't change even
  # if the directory does...
  newsyspath = []
  for item in sys.path[:]:
    if item == '' or item == '.':
      newsyspath.append(os.getcwd())
    else:
      newsyspath.append(item)

  # It should be safe now.   I'm assuming the user isn't trying to undercut us
  # by setting a crazy python path
  sys.path = newsyspath

  
  args = argv[1:]

  try:
    optlist, fnlist = getopt.getopt(args, '', [
      'simple', 'ip=', 'iface=', 'nootherips', 'logfile=',
      'stop=', 'status=', 'cwd=', 'servicelog', 'safebinary'
      ])

  except getopt.GetoptError:
    usage()
    sys.exit(1)

  # Set up the simple variable if needed
  simpleexec = False

  # By default we don't want to use the service logger
  servicelog = False

  # Default logfile (if the option --logfile isn't passed)
  logfile = None

  # Default stopfile (if the option --stopfile isn't passed)
  stopfile = None

  # Default stopfile (if the option --stopfile isn't passed)
  statusfile = None

  if len(fnlist) < 2:
    usage("Must supply a resource file and a program file to execute")
    sys.exit(1)

  for option, value in optlist:
    if option == '--simple':
      simpleexec = True

    elif option == '--ip':
      emulcomm.user_ip_interface_preferences = True

      # Append this ip to the list of available ones if it is new, since
      # multiple IP's may be specified
      if (True, value) not in emulcomm.user_specified_ip_interface_list:
        emulcomm.user_specified_ip_interface_list.append((True, value))

    elif option == '--iface':
      emulcomm.user_ip_interface_preferences = True
      
      # Append this interface to the list of available ones if it is new
      if (False, value) not in emulcomm.user_specified_ip_interface_list:
        emulcomm.user_specified_ip_interface_list.append((False, value))

    # Check if they have told us explicitly not to allow other IP's
    elif option == '--nootherips':
      # Set user preference to True
      emulcomm.user_ip_interface_preferences = True
      # Disable nonspecified IP's
      emulcomm.allow_nonspecified_ips = False
    
    elif option == '--logfile':
      # set up the circular log buffer...
      logfile = value

    elif option == '--stop':
      # Watch for the creation of this file and abort when it happens...
      stopfile = value

    elif option == '--status':
      # Write status information into this file...
      statusfile = value

    # Set Current Working Directory
    elif option == '--cwd':
      os.chdir(value)

    # Enable logging of internal errors to the service logger.
    elif option == '--servicelog':
      servicelog = True
    
    # Enable safe binary mode
    elif option == '--safebinary':
      safebinary.SAFEBINARY = True
      
  # Update repy current directory
  repy_constants.REPY_CURRENT_DIR = os.path.abspath(os.getcwd())

  # Initialize the NM status interface
  nmstatusinterface.init(stopfile, statusfile)
  
  # Write out our initial status
  statusstorage.write_status("Started")

  resourcefn = fnlist[0]
  progname = fnlist[1]
  progargs = fnlist[2:]

  # We also need to pass in whether or not we are going to be using the service
  # log for repy.  We provide the repy directory so that the vessel information
  # can be found regardless of where we are called from...
  tracebackrepy.initialize(servicelog, absolute_repy_directory)

  
  try:
    main(resourcefn, progname, progargs)
  except SystemExit:
    harshexit.harshexit(4)
  except:
    tracebackrepy.handle_exception()
    harshexit.harshexit(3)
Exemplo n.º 4
0
    # Enable logging of internal errors to the service logger.
    elif option == '--servicelog':
      servicelog = True

  # Update repy current directory
  repy_constants.REPY_CURRENT_DIR = os.path.abspath(os.getcwd())

  # Initialize the NM status interface
  nmstatusinterface.init(stopfile, statusfile)
  
  # Write out our initial status
  statusstorage.write_status("Started")

  restrictionsfn = fnlist[0]
  progname = fnlist[1]
  progargs = fnlist[2:]

  # We also need to pass in whether or not we are going to be using the service
  # log for repy.  We provide the repy directory so that the vessel information
  # can be found regardless of where we are called from...
  tracebackrepy.initialize(servicelog, absolute_repy_directory)

  try:
    main(restrictionsfn, progname, progargs)
  except SystemExit:
    harshexit.harshexit(4)
  except:
    tracebackrepy.handle_exception()
    harshexit.harshexit(3)
Exemplo n.º 5
0
    # Insert program execution separators and log calling information
    elif option == '--execinfo':
      displayexecinfo = True

  # Update repy current directory
  repy_constants.REPY_CURRENT_DIR = os.path.abspath(os.getcwd())

  # Initialize the NM status interface
  nmstatusinterface.init(stopfile, statusfile)
  
  # Write out our initial status
  statusstorage.write_status("Started")

  restrictionsfn = fnlist[0]
  progname = fnlist[1]
  progargs = fnlist[2:]

  # We also need to pass in whether or not we are going to be using the service
  # log for repy.  We provide the repy directory so that the vessel information
  # can be found regardless of where we are called from...
  tracebackrepy.initialize(servicelog, absolute_repy_directory)

  try:
    main(restrictionsfn, progname, progargs)
  except SystemExit:
    harshexit.harshexit(4)
  except:
    tracebackrepy.handle_exception()
    harshexit.harshexit(3)
Exemplo n.º 6
0
def repy_main(argv=sys.argv):
    """Run repy with these command line arguments"""
    global simpleexec
    global logfile

    # Armon: The CMD line path to repy is the first argument
    repy_location = argv[0]

    # Get the directory repy is in
    repy_directory = os.path.dirname(repy_location)

    # Translate into an absolute path
    if os.path.isabs(repy_directory):
        absolute_repy_directory = repy_directory

    else:
        # This will join the currect directory with the relative path
        # and then get the absolute path to that location
        absolute_repy_directory = os.path.abspath(
            os.path.join(os.getcwd(), repy_directory))

    # Store the absolute path as the repy startup directory
    repy_constants.REPY_START_DIR = absolute_repy_directory

    # For security, we need to make sure that the Python path doesn't change even
    # if the directory does...
    newsyspath = []
    for item in sys.path[:]:
        if item == '' or item == '.':
            newsyspath.append(os.getcwd())
        else:
            newsyspath.append(item)

    # It should be safe now.   I'm assuming the user isn't trying to undercut us
    # by setting a crazy python path
    sys.path = newsyspath

    args = argv[1:]

    try:
        optlist, fnlist = getopt.getopt(args, '', [
            'simple', 'ip=', 'iface=', 'nootherips', 'logfile=', 'stop=',
            'status=', 'cwd=', 'servicelog', 'safebinary'
        ])

    except getopt.GetoptError:
        usage()
        sys.exit(1)

    # Set up the simple variable if needed
    simpleexec = False

    # By default we don't want to use the service logger
    servicelog = False

    # Default logfile (if the option --logfile isn't passed)
    logfile = None

    # Default stopfile (if the option --stopfile isn't passed)
    stopfile = None

    # Default stopfile (if the option --stopfile isn't passed)
    statusfile = None

    if len(fnlist) < 2:
        usage("Must supply a resource file and a program file to execute")
        sys.exit(1)

    for option, value in optlist:
        if option == '--simple':
            simpleexec = True

        elif option == '--ip':
            emulcomm.user_ip_interface_preferences = True

            # Append this ip to the list of available ones if it is new, since
            # multiple IP's may be specified
            if (True, value) not in emulcomm.user_specified_ip_interface_list:
                emulcomm.user_specified_ip_interface_list.append((True, value))

        elif option == '--iface':
            emulcomm.user_ip_interface_preferences = True

            # Append this interface to the list of available ones if it is new
            if (False, value) not in emulcomm.user_specified_ip_interface_list:
                emulcomm.user_specified_ip_interface_list.append(
                    (False, value))

        # Check if they have told us explicitly not to allow other IP's
        elif option == '--nootherips':
            # Set user preference to True
            emulcomm.user_ip_interface_preferences = True
            # Disable nonspecified IP's
            emulcomm.allow_nonspecified_ips = False

        elif option == '--logfile':
            # set up the circular log buffer...
            logfile = value

        elif option == '--stop':
            # Watch for the creation of this file and abort when it happens...
            stopfile = value

        elif option == '--status':
            # Write status information into this file...
            statusfile = value

        # Set Current Working Directory
        elif option == '--cwd':
            os.chdir(value)

        # Enable logging of internal errors to the service logger.
        elif option == '--servicelog':
            servicelog = True

        # Enable safe binary mode
        elif option == '--safebinary':
            safebinary.SAFEBINARY = True

    # Update repy current directory
    repy_constants.REPY_CURRENT_DIR = os.path.abspath(os.getcwd())

    # Initialize the NM status interface
    nmstatusinterface.init(stopfile, statusfile)

    # Write out our initial status
    statusstorage.write_status("Started")

    resourcefn = fnlist[0]
    progname = fnlist[1]
    progargs = fnlist[2:]

    # We also need to pass in whether or not we are going to be using the service
    # log for repy.  We provide the repy directory so that the vessel information
    # can be found regardless of where we are called from...
    tracebackrepy.initialize(servicelog, absolute_repy_directory)

    return init_namespace(resourcefn, progname, progargs)