Accept uncomplete configuration file, fall back to default value
darcs-hash:20080515064539-86b55-23b6f5dfb124f10c8f5eebdfdcdcc10b83e08564.gz
This commit is contained in:
@@ -130,12 +130,14 @@ class JCLRunner(object):
|
|||||||
(section, set_func) = cleanopts[opt]
|
(section, set_func) = cleanopts[opt]
|
||||||
if section is not None:
|
if section is not None:
|
||||||
attr = opt.replace("-", "_")
|
attr = opt.replace("-", "_")
|
||||||
config_property = self.config.get(section, attr)
|
if self.config.has_section(section) \
|
||||||
self.logger.debug("Setting " + attr + " = " +
|
and self.config.has_option(section, attr):
|
||||||
config_property +
|
config_property = self.config.get(section, attr)
|
||||||
" from configuration file " +
|
self.logger.debug("Setting " + attr + " = " +
|
||||||
self.config_file)
|
config_property +
|
||||||
set_func(config_property)
|
" from configuration file " +
|
||||||
|
self.config_file)
|
||||||
|
set_func(config_property)
|
||||||
|
|
||||||
def configure(self):
|
def configure(self):
|
||||||
"""
|
"""
|
||||||
@@ -154,7 +156,9 @@ class JCLRunner(object):
|
|||||||
else:
|
else:
|
||||||
cleanopts[option[1]] = (option[2], option[4])
|
cleanopts[option[1]] = (option[2], option[4])
|
||||||
|
|
||||||
commandline_args = self.__configure_commandline_args(shortopts, longopts, cleanopts)
|
commandline_args = self.__configure_commandline_args(shortopts,
|
||||||
|
longopts,
|
||||||
|
cleanopts)
|
||||||
if commandline_args.has_key("debug") or commandline_args.has_key("d"):
|
if commandline_args.has_key("debug") or commandline_args.has_key("d"):
|
||||||
self.debug = True
|
self.debug = True
|
||||||
self.logger.debug("Debug activated")
|
self.logger.debug("Debug activated")
|
||||||
|
|||||||
@@ -70,6 +70,19 @@ class JCLRunner_TestCase(unittest.TestCase):
|
|||||||
self.assertEquals(self.runner.pid_file, "/var/run/jabber/test_jcl.pid")
|
self.assertEquals(self.runner.pid_file, "/var/run/jabber/test_jcl.pid")
|
||||||
self.assertFalse(self.runner.debug)
|
self.assertFalse(self.runner.debug)
|
||||||
|
|
||||||
|
def test_configure_uncomplete_configfile(self):
|
||||||
|
self.runner.config_file = "src/jcl/tests/uncomplete_jcl.conf"
|
||||||
|
self.runner.configure()
|
||||||
|
self.assertEquals(self.runner.server, "test_localhost")
|
||||||
|
self.assertEquals(self.runner.port, 42)
|
||||||
|
self.assertEquals(self.runner.secret, "test_secret")
|
||||||
|
self.assertEquals(self.runner.service_jid, "test_jcl.localhost")
|
||||||
|
self.assertEquals(self.runner.language, "test_en")
|
||||||
|
self.assertEquals(self.runner.db_url, "test_sqlite://root@localhost/var/spool/jabber/test_jcl.db")
|
||||||
|
# pid_file is not in uncmplete_jcl.conf, must be default value
|
||||||
|
self.assertEquals(self.runner.pid_file, "/var/run/jabber/jcl.pid")
|
||||||
|
self.assertFalse(self.runner.debug)
|
||||||
|
|
||||||
def test_configure_commandline_shortopt(self):
|
def test_configure_commandline_shortopt(self):
|
||||||
sys.argv = ["", "-c", "src/jcl/tests/jcl.conf", \
|
sys.argv = ["", "-c", "src/jcl/tests/jcl.conf", \
|
||||||
"-S", "test2_localhost", \
|
"-S", "test2_localhost", \
|
||||||
@@ -172,4 +185,3 @@ def suite():
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main(defaultTest='suite')
|
unittest.main(defaultTest='suite')
|
||||||
|
|
||||||
|
|||||||
19
src/jcl/tests/uncomplete_jcl.conf
Normal file
19
src/jcl/tests/uncomplete_jcl.conf
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
[jabber]
|
||||||
|
server: test_localhost
|
||||||
|
port: 42
|
||||||
|
secret: test_secret
|
||||||
|
service_jid: test_jcl.localhost
|
||||||
|
#supported language: en, fr (See src/jmc/lang.py to add more)
|
||||||
|
language: test_en
|
||||||
|
|
||||||
|
[db]
|
||||||
|
#type: mysql
|
||||||
|
type: test_sqlite
|
||||||
|
#host: root@localhost
|
||||||
|
host: root@localhost
|
||||||
|
name: /var/spool/jabber/test_jcl.db
|
||||||
|
#url: %(type)%(host)%(name)?debug=1&debugThreading=1
|
||||||
|
db_url: %(type)s://%(host)s%(name)s
|
||||||
|
|
||||||
|
[component]
|
||||||
|
log_file: /tmp/jcl.log
|
||||||
Reference in New Issue
Block a user