summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTodd Zullinger <tmz@pobox.com>2008-11-27 21:19:33 -0500
committerTodd Zullinger <tmz@pobox.com>2008-11-27 21:39:58 -0500
commite9b2085371b5524e7a3e42a93d03cc7aee335029 (patch)
tree7ea9484cd821bda6ee772012fc74a0d5508ecb8e
parent1c025e053689188592d9df10865bf55577ebbe8d (diff)
downloadpuppet-host-package-e9b2085371b5524e7a3e42a93d03cc7aee335029.tar.gz
puppet-host-package-e9b2085371b5524e7a3e42a93d03cc7aee335029.tar.xz
puppet-host-package-e9b2085371b5524e7a3e42a93d03cc7aee335029.zip
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.
-rwxr-xr-xpuppethost.py14
1 files changed, 14 insertions, 0 deletions
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']