commit 0d4ef9a3f573595d08f7d3d4a50d6a41af711485
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Fri Nov 9 14:48:38 2012 +0100
Config: add method dump_config
This patch adds a method that returns the currently loaded config values
in a .ini file formatted string. In the future it will be used to create
the config file in users home directory.
I decided to dump all config values and use the '=' operator. Using the
'+=' where it can be used would make more sense but it would be more
complicated to implement and I currently don't see any pretty way to do
it. But I might change this in the future.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Common/Config.py | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/Common/Config.py b/Common/Config.py
index 4a4905b..56269b8 100644
--- a/Common/Config.py
+++ b/Common/Config.py
@@ -218,3 +218,25 @@ class Config():
raise ConfigError(msg)
return timeval
+
+ def dump_config(self):
+ string = ""
+ for section in self.options:
+ string += "[%s]\n" % section
+ for option in self.options[section]:
+ val = self.value_to_string(section, option)
+ opt_name = self.options[section][option]["name"]
+ string += "%s = %s\n" % (opt_name, val)
+
+ return string
+
+ def value_to_string(self, section, option):
+ string = ""
+ value = self.options[section][option]["value"]
+
+ if type(value) == list:
+ string = " ".join(value)
+ else:
+ string = str(value)
+
+ return string
Show replies by date