]> jfr.im git - erebus.git/blobdiff - config.py
stafflist - add online nicks
[erebus.git] / config.py
index 6abad40d280df0145529a5e4c2fefaadd772ba58..0d4106c7e0b51d0897074e56e83ad12be742d2e5 100644 (file)
--- a/config.py
+++ b/config.py
@@ -1,7 +1,13 @@
 # Erebus IRC bot - Author: John Runyon
 # "Config" class (reading/providing access to bot.config)
 
-import ConfigParser
+from __future__ import print_function
+import sys
+
+if sys.version_info.major < 3:
+       import ConfigParser
+else:
+       import configparser as ConfigParser
 
 class Config(object):
        def __init__(self, filename, writeout=True):
@@ -35,13 +41,14 @@ class Config(object):
                        return default
        def getboolean(self, section, key):
                val = self.get(section, key, False)
-               if val == False or val == "0" or val.lower() == "false" or val.strip() == "":
+               if val == False or val == "0" or val.lower() == "false":
                        return False
                else:
                        return True
 
        def set(self, section, key, value):
                self.config.set(section, key, value)
+               if self.writeout: self.write()
 
        def write(self):
                with open(self.filename, 'wb') as configfile:
@@ -50,15 +57,13 @@ class Config(object):
        def __del__(self):
                if self.writeout: self.write()
 
-def setup(fn='bot.config', writeout=True):
-       return Config(fn, writeout)
-
 if __name__ == '__main__':
        import sys
-       cfg = Config(sys.argv[1], False)
+       if len(sys.argv) > 1:
+               cfg = Config(sys.argv[1], False)
+       else:
+               cfg = Config('bot.config', False)
 
        for s in cfg.config.sections():
                for k, v in cfg.items(s):
-                       print "[%r][%r] = %r" % (s, k, v)
-#      for k, v in cfg.items():
-#              print 'erebus.'+k, '=', v
+                       print("[%r][%r] = %r" % (s, k, v))