Add support for the "debug" keyword in switch config stanzas
Change-Id: I036909295707d83814d8cbc49f47b09d1f326c66
diff --git a/config/config.py b/config/config.py
index 4097c64..1736bbd 100644
--- a/config/config.py
+++ b/config/config.py
@@ -31,6 +31,12 @@
from errors import ConfigError
+def is_positive(text):
+ if text in ('1', 'y', 'Y', 't', 'T', 'True', 'true'):
+ return True
+ elif text in ('0', 'n', 'N', 'f', 'F', 'False', 'false'):
+ return False
+
class DaemonConfigClass:
""" Simple container for stuff to make for nicer syntax """
@@ -67,7 +73,8 @@
'password': None,
'name': None,
'driver': None,
- 'enable_password': None
+ 'enable_password': None,
+ 'debug': False,
})
config.read(filenames)
@@ -186,6 +193,13 @@
self.switches[name].username = config.get(section, 'username')
self.switches[name].password = config.get(section, 'password')
self.switches[name].enable_password = config.get(section, 'enable_password')
+ self.switches[name].debug = config.get(section, 'debug')
+ if not is_positive(self.switches[name].debug):
+ self.switches[name].debug = False
+ elif is_positive(self.switches[name].debug):
+ self.switches[name].debug = True
+ else:
+ raise ConfigError('Invalid vland configuration (switch "%s", debug "%s"' % (name, self.switches[name].debug))
else:
raise ConfigError('Unrecognised config section %s' % section)