diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-02-17 15:36:56 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2014-03-04 13:17:06 +0000 |
commit | ccaed5352ce9413cee3d7ab4b60514d0bc4fdbaa (patch) | |
tree | 063ef3f0176416fb0173cf36d0d11fcf6d2a02d1 | |
parent | 206e9f65972b8d6abb8a0f7efb460fdfe8b722c0 (diff) | |
download | infrastructure-ccaed5352ce9413cee3d7ab4b60514d0bc4fdbaa.tar.gz |
Make parse_autostart() into more general get_environment_boolean()
Also, be more flexible when parsing environment booleans -- convert to
lower case and match 0/1 and true/false as well as yes/no.
-rw-r--r-- | writeexts.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/writeexts.py b/writeexts.py index a07c697f..1849f406 100644 --- a/writeexts.py +++ b/writeexts.py @@ -402,14 +402,14 @@ class WriteExtension(cliapp.Application): return value == 'yes' - def parse_autostart(self): - '''Parse $AUTOSTART to determine if VMs should be started.''' + def get_environment_boolean(self, variable): + '''Parse a yes/no boolean passed through the environment.''' - autostart = os.environ.get('AUTOSTART', 'no') - if autostart == 'no': + value = os.environ.get(variable, 'no').lower() + if value in ['no', '0', 'false']: return False - elif autostart == 'yes': + elif value in ['yes', '1', 'true']: return True else: - raise cliapp.AppException('Unexpected value for AUTOSTART: %s' % - autostart) + raise cliapp.AppException('Unexpected value for %s: %s' % + (variable, value)) |