From ae52c3d39e9bb07a16f34b57525d9e787a6322d9 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 1 Oct 2012 00:31:03 -0400 Subject: [PATCH] Improved handling of booleans. --- irkerhook.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/irkerhook.py b/irkerhook.py index d12dcdb..02cd212 100755 --- a/irkerhook.py +++ b/irkerhook.py @@ -49,6 +49,8 @@ def do(command): class GenericExtractor: "Generic class for encapsulating data from a VCS." + booleans = ["tcp", "color"] + numerics = ["maxchannels"] def __init__(self, arguments): self.arguments = arguments self.project = None @@ -109,21 +111,19 @@ class GenericExtractor: setattr(self, variable, value) def do_overrides(self): "Make command-line overrides possible." - booleans = ["tcp", "color"] - numerics = ["maxchannels"] for tok in self.arguments: for key in self.__dict__: if tok.startswith(key + "="): val = tok[len(key)+1:] - if key in booleans: - if val.lower() == "true": - setattr(self, key, True) - elif val.lower() == "false": - setattr(self, key, False) - elif key in numerics: - setattr(self, key, int(val)) - else: - setattr(self, key, val) + setattr(self, key, val) + for (key, val) in self.__dict__.items(): + if key in GenericExtractor.booleans: + if val.lower() == "true": + setattr(self, key, True) + elif val.lower() == "false": + setattr(self, key, False) + elif key in GenericExtractor.numerics: + setattr(self, key, int(val)) if not self.project: sys.stderr.write("irkerhook.py: no project name set!\n") raise SystemExit, 1 -- 2.26.2