Example #1
0
    def read(self, configuration):
        c = config_t()
        if (config_read_file(c, self._file) != CONFIG_TRUE):
            error_text = c.error_text
            config_destroy(c)
            raise Exception(error_text)
        try:
            self._parser.unparse(c, configuration)
        finally:
            config_destroy(c)

        config_destroy(c)
        return configuration
Example #2
0
    def read(self, configuration):
        c = config_t()
        if (config_read_file(c, self._file) != CONFIG_TRUE):
            error_text = c.error_text
            config_destroy(c)
            raise Exception(error_text)
        try:
            self._parser.unparse(c, configuration)
        finally:
            config_destroy(c)

        config_destroy(c)
        return configuration
Example #3
0
    def read(self, configuration):

        if not os.path.isfile(self._file):
            raise IOError("%s is not a file." % self._file)

        c = config_t()
        if (config_read_file(c, self._file) != CONFIG_TRUE):
            error_text = c.error_text
            config_destroy(c)
            raise Exception(error_text)
        try:
            self._parser.unparse(c, configuration)
        finally:
            config_destroy(c)

        config_destroy(c)
        return configuration
Example #4
0
    def write(self, configuration):
        backup = "%s.%s" % (self._file, time.strftime("%Y%m%d-%H:%M:%S", time.localtime()))
        shutil.copy(self._file, backup)
        c = config_t()
        c.root = config_setting_t()
        c.root.type = CONFIG_TYPE_GROUP
        c.root.value = config_value_t()
        c.root.config = c

        try:
            self._parser.parse(configuration, c)
        except Exception as e:
            config_destroy(c)
            raise e

        if (config_write_file(c, self._file) != CONFIG_TRUE):
            error_text = c.error_text
            config_destroy(c)
            raise Exception(error_text)

        config_destroy(c)
Example #5
0
    def write(self, configuration):
        backup = "%s.%s" % (self._file, time.strftime("%Y%m%d-%H:%M:%S", time.localtime()))
        shutil.copy(self._file, backup)
        c = config_t()
        c.root = config_setting_t()
        c.root.type = CONFIG_TYPE_GROUP
        c.root.value = config_value_t()
        c.root.config = c

        try:
            self._parser.parse(configuration, c)
        except Exception as e:
            config_destroy(c)
            raise e

        if (config_write_file(c, self._file) != CONFIG_TRUE):
            error_text = c.error_text
            config_destroy(c)
            raise Exception(error_text)

        config_destroy(c)
Example #6
0
    def read(self, configuration):

        if not os.path.isfile(self._file):
            raise IOError("%s is not a file." % self._file)

        c = config_t()
        if (config_read_file(c, self._file) != CONFIG_TRUE):
            error_text = c.error_text
            error_line = c.error_line
            config_destroy(c)
            raise SyntaxError('cannot read file %s, %s at line %d' %
                              (self._file, error_text, error_line))
        try:
            self._parser.unparse(c, configuration)
        except SyntaxError as e:
            raise type(e)("Syntax error in file %s (%s)" %
                          (self._file, str(e)))
        finally:
            config_destroy(c)

        config_destroy(c)
        return configuration
Example #7
0
    def read(self, configuration):

        if not os.path.isfile(self._file):
            raise IOError("%s is not a file." % self._file)

        c = config_t()
        if (config_read_file(c, self._file) != CONFIG_TRUE):
            error_text = c.error_text
            error_line = c.error_line
            config_destroy(c)
            raise SyntaxError('cannot read file %s, %s at line %d'
                               % (self._file, error_text, error_line))
        try:
            self._parser.unparse(c, configuration)
        except SyntaxError as e:
                raise type(e)("Syntax error in file %s (%s)" 
                              % (self._file, str(e)))
        finally:
            config_destroy(c)

        config_destroy(c)
        return configuration