From 49475f79bafdd07ba5106336eb89e18df879af1d Mon Sep 17 00:00:00 2001 From: Julien Cristau Date: Sun, 26 Apr 2015 18:20:09 +0200 Subject: [PATCH] Simplify a bit the loop to read our config file - split the one-liner into a for and an if - use open() as a context manager - don't use string.strip which is gone in python3 Signed-off-by: Julien Cristau --- britney.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/britney.py b/britney.py index cc68ab9..62af5bd 100755 --- a/britney.py +++ b/britney.py @@ -364,15 +364,20 @@ class Britney(object): # are handled as an ad-hoc case self.MINDAYS = {} self.HINTS = {'command-line': self.HINTS_ALL} - for k, v in [map(string.strip,r.split('=', 1)) for r in open(self.options.config) if '=' in r and not r.strip().startswith('#')]: - if k.startswith("MINDAYS_"): - self.MINDAYS[k.split("_")[1].lower()] = int(v) - elif k.startswith("HINTS_"): - self.HINTS[k.split("_")[1].lower()] = \ - reduce(lambda x,y: x+y, [hasattr(self, "HINTS_" + i) and getattr(self, "HINTS_" + i) or (i,) for i in v.split()]) - elif not hasattr(self.options, k.lower()) or \ - not getattr(self.options, k.lower()): - setattr(self.options, k.lower(), v) + with open(self.options.config) as config: + for line in config: + if '=' in line and not line.strip().startswith('#'): + k, v = line.split('=', 1) + k = k.strip() + v = v.strip() + if k.startswith("MINDAYS_"): + self.MINDAYS[k.split("_")[1].lower()] = int(v) + elif k.startswith("HINTS_"): + self.HINTS[k.split("_")[1].lower()] = \ + reduce(lambda x,y: x+y, [hasattr(self, "HINTS_" + i) and getattr(self, "HINTS_" + i) or (i,) for i in v.split()]) + elif not hasattr(self.options, k.lower()) or \ + not getattr(self.options, k.lower()): + setattr(self.options, k.lower(), v) if not hasattr(self.options, "heidi_delta_output"): self.options.heidi_delta_output = self.options.heidi_output + "Delta"