]> jfr.im git - erebus.git/blobdiff - config.py
urls - allow to block channels in config
[erebus.git] / config.py
index c1f61b4cb152b4eee008aae37296324cea990904..bb44ba3a4e9a049aa58b379a058b73a616b5ffb1 100644 (file)
--- a/config.py
+++ b/config.py
@@ -3,7 +3,7 @@
 # "Config" class (reading/providing access to bot.config)
 
 from __future__ import print_function
-import sys
+import sys, os
 
 if sys.version_info.major < 3:
        import ConfigParser
@@ -47,7 +47,9 @@ class Config(object):
                        return default
        def getboolean(self, section, key, default=False):
                val = self.get(section, key, default)
-               if val == False or val == "0" or val.lower() == "false":
+               if type(val) is bool:
+                       return val
+               elif val == "0" or val.lower() == "false":
                        return False
                else:
                        return True
@@ -55,12 +57,13 @@ class Config(object):
        def set(self, section, key, value):
                if not self.config.has_section(section):
                        self.config.add_section(section)
-               self.config.set(section, key, value)
+               self.config.set(section, key, str(value))
                if self.writeout: self.write()
 
        def write(self):
-               with open(self.filename, 'wb') as configfile:
+               with open(self.filename+'.tmp', 'w') as configfile:
                        self.config.write(configfile)
+                       os.rename(configfile.name, self.filename)
 
        def __del__(self):
                if self.writeout: self.write()