示例#1
0
    def __setattr__(self, name, value):
        if name in DEFAULTS:
            try:
                if DEFAULTS[name][1] == "str":
                    value = str(value)
                elif DEFAULTS[name][1] == "int":
                    value = int(value)
                elif DEFAULTS[name][1] == "bool":
                    if utils.input_boolean(value):
                        value = 1
                    else:
                        value = 0
                elif DEFAULTS[name][1] == "float":
                    value = float(value)
                elif DEFAULTS[name][1] == "list":
                    value = utils.input_string_or_list(value)
                elif DEFAULTS[name][1] == "dict":
                    value = utils.input_string_or_dict(value)[1]
            except:
                raise AttributeError

            self.__dict__[name] = value
            if not utils.update_settings_file(self.to_dict()):
                raise AttributeError

            return 0
        else:
            # FIXME. Not sure why __dict__ is part of name
            # workaround applied, ignore exception
            # raise AttributeError
            pass
示例#2
0
def test_update_settings_file():
    # Arrange
    settings_data = None
    time_before_write = time.time()

    # Act
    result = utils.update_settings_file(settings_data)

    # Assert
    assert result
    # This should work the following: The time of modifying the settings file should be greater then the time taken
    # before modifying it. Thus the value of the subtraction of both should be greater than zero. If writing to the
    # files does not work, this is smaller then 0. The content is a yaml file thus we don't want to test if writing a
    # YAML file is logically correct. This is the matter of the library we are using.
    assert os.path.getmtime("/etc/cobbler/settings") - time_before_write > 0
示例#3
0
    def __setattr__(self, name, value):
        """
        This sets the value of the settings named in the args.

        :param name: The setting to set its value.
        :param value: The value of the setting "name". Must be the correct the type.
        :return: 0 if the action was completed successfully. No return if there is an error.
        :raises AttributeError: Raised if the setting with "name" has the wrong type.
        """
        if name in DEFAULTS:
            try:
                if DEFAULTS[name][1] == "str":
                    value = str(value)
                elif DEFAULTS[name][1] == "int":
                    value = int(value)
                elif DEFAULTS[name][1] == "bool":
                    if utils.input_boolean(value):
                        value = 1
                    else:
                        value = 0
                elif DEFAULTS[name][1] == "float":
                    value = float(value)
                elif DEFAULTS[name][1] == "list":
                    value = utils.input_string_or_list(value)
                elif DEFAULTS[name][1] == "dict":
                    value = utils.input_string_or_dict(value)[1]
            except:
                raise AttributeError

            self.__dict__[name] = value
            if not utils.update_settings_file(self.to_dict()):
                raise AttributeError

            return 0
        else:
            # FIXME. Not sure why __dict__ is part of name
            # workaround applied, ignore exception
            # raise AttributeError
            pass