From e9b2085371b5524e7a3e42a93d03cc7aee335029 Mon Sep 17 00:00:00 2001 From: Todd Zullinger Date: Thu, 27 Nov 2008 21:19:33 -0500 Subject: Handle boolean and numeric options in config file This ugly bit of code ensures that setting boolean and numeric options in the config file are handled without the user needing to worry about quoting (or not quoting) the options, nor about capitilizing True and False. --- puppethost.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/puppethost.py b/puppethost.py index 3f6671d..53efe7d 100755 --- a/puppethost.py +++ b/puppethost.py @@ -35,6 +35,20 @@ except: config = os.path.expanduser('~/.puppethost') if os.path.exists(config): execfile(config, {}, defaults) + truths = ['true', 'yes', '1'] + # Ensure boolean options are set correctly + for opt in ['force', 'force_cert', 'force_tarball', 'force_package']: + defaults[opt] = str(defaults[opt]).lower() in truths + # Ensure numeric options are set correctly + for opt in ['verbose']: + if isinstance(defaults[opt], bool): + defaults[opt] = int(defaults[opt]) + elif not isinstance(defaults[opt], int): + try: + defaults[opt] = int(str(defaults[opt]).lower() in truths) + except: + raise + defaults[opt] = 0 package_types = ['deb', 'rpm'] -- cgit