示例#1
0
    def test_valid_file(self):
        """
        Test functionality of valid_file function
        """

        filename = get_test_config('utilities/newline.ini')
        _stderr = sys.stderr
        sys.stderr = file(os.devnull, 'wb')
        # need to do this instead of putting this in assert so that stderr can
        # be restored after call
        result = validation.valid_ini_file(filename)
        self.assertFalse(result,
                         "Didn't detect newline in %s" % filename)
        # test whether we catch sections that has a space before the first setting
        filename = get_test_config('utilities/section_space.ini')
        self.assertFalse(result,
                         "Didn't detect space in %s" % filename)
        sys.stderr = _stderr

        filename = get_test_config('utilities/valid_boolean.ini')
        self.assertTrue(validation.valid_ini_file(filename),
                        "Got error on valid file %s" % filename)

        filename = get_test_config('utilities/valid_variable.ini')
        self.assertTrue(validation.valid_ini_file(filename),
                        "Got error on valid file %s" % filename)
示例#2
0
def read_config_files(**kwargs):
    """
    Read config files located in /etc/osg/config.d and return a config parser
    object for it

    Keyword arguments:
    config_directory -- indicates which directory holds the config files
    case_sensitive -- indicates whether the ConfigParser should be case
      sensitive when parsing the config file, this is needed for Local Options
      section

    Raises:
    IOError -- error when parsing files
    """

    config_dir = kwargs.get('config_directory', CONFIG_DIRECTORY)
    case_sensitive = kwargs.get('case_sensitive', False)
    if not validation.valid_directory(config_dir):
        raise IOError("%s does not exist" % config_dir)
    file_list = get_file_list(config_directory=config_dir)
    for filename in file_list:
        if not validation.valid_ini_file(filename):
            sys.stderr.write("Error found in %s\n" % filename)
            sys.exit(1)
    try:
        config = ConfigParser.SafeConfigParser()
        if case_sensitive:
            config.optionxform = str
    except ConfigParser.Error, e:
        raise IOError("Can't read and parse config files:\n%s" % e)
示例#3
0
def read_config_files(**kwargs):
    """
    Read config files located in /etc/osg/config.d and return a config parser
    object for it

    Keyword arguments:
    config_directory -- indicates which directory holds the config files
    case_sensitive -- indicates whether the ConfigParser should be case
      sensitive when parsing the config file, this is needed for Local Options
      section

    Raises:
    IOError -- error when parsing files
    """

    config_dir = kwargs.get('config_directory', CONFIG_DIRECTORY)
    case_sensitive = kwargs.get('case_sensitive', False)
    if not validation.valid_directory(config_dir):
        raise IOError("%s does not exist" % config_dir)
    file_list = get_file_list(config_directory=config_dir)
    for filename in file_list:
        if not validation.valid_ini_file(filename):
            sys.stderr.write("Error found in %s\n" % filename)
            sys.exit(1)
    try:
        config = ConfigParser.SafeConfigParser()
        if case_sensitive:
            config.optionxform = str
    except ConfigParser.Error, e:
        raise IOError("Can't read and parse config files:\n%s" % e)
    def test_valid_file(self):
        """
        Test functionality of valid_file function
        """

        filename = get_test_config("utilities/newline.ini")
        _stderr = sys.stderr
        sys.stderr = file(os.devnull, "wb")
        # need to do this instead of putting this in assert so that stderr can
        # be restored after call
        result = validation.valid_ini_file(filename)
        self.assertFalse(result, "Didn't detect newline in %s" % filename)
        # test whether we catch sections that has a space before the first setting
        filename = get_test_config("utilities/section_space.ini")
        self.assertFalse(result, "Didn't detect space in %s" % filename)
        sys.stderr = _stderr

        filename = get_test_config("utilities/valid_boolean.ini")
        self.assertTrue(validation.valid_ini_file(filename), "Got error on valid file %s" % filename)

        filename = get_test_config("utilities/valid_variable.ini")
        self.assertTrue(validation.valid_ini_file(filename), "Got error on valid file %s" % filename)