Esempio n. 1
0
def promptLicense():
  if not comm.isWindows: # windows will probably display its license in the installer.
    if os.path.exists(PATH_LICENSE_FILE):
      if sys.stdin.isatty():
        subprocess.call(["more", PATH_LICENSE_FILE]) # TODO: test this on dirs w/ spaces.  prob works fine.
      else:
        logger.info(open(PATH_LICENSE_FILE, 'r').read())
    else: # don't barf in dev envs
      comm.out("Could not find license file.")
    if not comm.prompt_user("Do you agree with this license? [y/n]: ", checkValidResponse = True):
      raise cex.InputError("License refused - exiting.")
Esempio n. 2
0
def promptLicense():
  if not comm.isWindows: # windows will probably display its license in the installer.
    if os.path.exists(PATH_LICENSE_FILE):
      if sys.stdin.isatty():
        subprocess.call(["more", PATH_LICENSE_FILE]) # TODO: test this on dirs w/ spaces.  prob works fine.
      else:
        logger.info(open(PATH_LICENSE_FILE, 'r').read())
    else: # don't barf in dev envs
      comm.out("Could not find license file.")
    if not comm.prompt_user("Do you agree with this license? [y/n]: ", checkValidResponse = True):
      raise cex.InputError("License refused - exiting.")
Esempio n. 3
0
def checkXmlFiles(args, fromCLI):
    """
  Gathers all .xml files in path, recursively, and runs them through the
  minidom parser.
  """

    print "\tChecking configuration... ",
    sys.stdout.flush()

    paramReq = ()
    paramOpt = ()
    comm.validateArgs(paramReq, paramOpt, args)

    retDict = {}

    ################
    ################ BEGIN PART 1
    ################

    xmlErrs = 0
    xmlFiles = []
    # path to search.
    dirPath = os.path.join(comm.splunk_home, "etc")
    # gather .xml files into xmlFiles.
    xmlFiles = comm.findFiles(dirPath, "\\.xml$", caseSens=False, minBytes=10)

    # run the cmd on appropriately sized subsets of xml files.
    for file in xmlFiles:

        # should not start with "." (editor temp, hidden, etc) because dotfiles are lame
        # this is only enforced via this pre-flight message at the moment (4.2.2)
        if os.path.basename(file).startswith("."):
            logger.error("\nIgnored file '%s': filename begins with '.'\n",
                         file)
            continue

        try:
            xml.dom.minidom.parse(file)
        except:
            value = sys.exc_info()[1]
            logger.error("Error while parsing '%s':\n %s\n", file, value)
            xmlErrs += 1

    ### all done, report/prompt now.

    if xmlErrs > 0:
        if not comm.prompt_user(
                "\nThere were problems with the configuration files.\nWould you like to ignore these errors? [y/n]:"
        ):
            raise cex.ParsingError, "Parsing error in configuration files."

    print "Done."
    return retDict
Esempio n. 4
0
def checkXmlFiles(args, fromCLI):
  """
  Gathers all .xml files in path, recursively, and runs them through the
  minidom parser.
  """

  print "\tChecking configuration... ",; sys.stdout.flush()


  paramReq = ()
  paramOpt = ()
  comm.validateArgs(paramReq, paramOpt, args)

  retDict  = {}

  ################
  ################ BEGIN PART 1
  ################

  xmlErrs  = 0
  xmlFiles = []
  # path to search.
  dirPath  = os.path.join(comm.splunk_home, "etc")
  # gather .xml files into xmlFiles. 
  xmlFiles = comm.findFiles(dirPath, "\\.xml$", caseSens = False, minBytes = 10)

  # run the cmd on appropriately sized subsets of xml files.
  for file in xmlFiles:

    # should not start with "." (editor temp, hidden, etc) because dotfiles are lame
    # this is only enforced via this pre-flight message at the moment (4.2.2)
    if os.path.basename(file).startswith("."):
      logger.error("\nIgnored file '%s': filename begins with '.'\n", file)
      continue

    try:
      xml.dom.minidom.parse(file)
    except:
      value = sys.exc_info()[1]
      logger.error("Error while parsing '%s':\n %s\n", file, value)
      xmlErrs += 1

  ### all done, report/prompt now.

  if xmlErrs > 0:
    if not comm.prompt_user("\nThere were problems with the configuration files.\nWould you like to ignore these errors? [y/n]:"):
      raise cex.ParsingError, "Parsing error in configuration files."

  print "Done." 
  return retDict
Esempio n. 5
0
def checkXmlFiles(args, fromCLI):
  """
  Gathers all .xml files in path, recursively, and runs them through the
  minidom parser.
  """

  print "\tChecking configuration... ",; sys.stdout.flush()

  BLACKLIST = [
    {
      "condition": lambda root: os.path.split(root)[0] == os.path.join(comm.splunk_home, "etc", "apps"),
      "filter": lambda dir: dir in ("default", "local")
    },
  ]

  paramReq = ()
  paramOpt = ()
  comm.validateArgs(paramReq, paramOpt, args)

  retDict  = {}

  ################
  ################ BEGIN PART 1
  ################

  xmlErrs  = 0
  xmlFiles = []
  # path to search.
  dirPath  = os.path.join(comm.splunk_home, "etc")

  def filter_dirs(root, dirs):
    new_dirs = dirs
    for exclude in BLACKLIST:
      condition = exclude["condition"]
      filter_fn = exclude["filter"]
      if condition(root):
        new_dirs = filter(filter_fn, new_dirs)
        
    return new_dirs
        
  # run the cmd on appropriately sized subsets of xml files.
  for root, dirs, files in os.walk(dirPath, topdown=True):
    files[:] = filter(lambda x: x.endswith(".xml"), files)
    dirs[:] = filter_dirs(root, dirs)
    
    for filename in files:      
      file = os.path.join(root, filename)

      # should not start with "." (editor temp, hidden, etc) because dotfiles are lame
      # this is only enforced via this pre-flight message at the moment (4.2.2)
      if os.path.basename(file).startswith("."):
        logger.error("\nIgnored file '%s': filename begins with '.'\n", file)
        continue

      try:
        xml.dom.minidom.parse(file)
      except:
        value = sys.exc_info()[1]
        logger.error("Error while parsing '%s':\n %s\n", file, value)
        xmlErrs += 1

  ### all done, report/prompt now.

  if xmlErrs > 0:
    if not comm.prompt_user("\nThere were problems with the configuration files.\nWould you like to ignore these errors? [y/n]:"):
      raise cex.ParsingError, "Parsing error in configuration files."

  print "Done." 
  return retDict