From 07bf49a3262c5128cc737add62c808bc1cd3d9c8 Mon Sep 17 00:00:00 2001 From: Jonatan Schlag Date: Mon, 23 Apr 2018 13:38:01 +0200 Subject: [PATCH] Code cleanup in recipe parse I cleaned up the code to avoid multiple identical code statements and to improve readability. Signed-off-by: Jonatan Schlag --- test.py | 53 +++++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/test.py b/test.py index 942411b..2e2f13a 100755 --- a/test.py +++ b/test.py @@ -442,42 +442,35 @@ class recipe(): if len(raw_line) < 2: self.log.error("Error parsing the recipe in line {}".format(i)) raise RecipeExeption - cmd = raw_line[1] + cmd = raw_line[1].strip() raw_line = raw_line[0].strip().split(" ") if len(raw_line) == 0: self.log.error("Failed to parse the recipe in line {}".format(i)) raise RecipeExeption - elif len(raw_line) == 1: - if raw_line[0] == "": + + if raw_line[0].strip() == "": self.log.error("Failed to parse the recipe in line {}".format(i)) raise RecipeExeption - # We could get a machine here or a include statement - if raw_line[0].strip() == "include": - path = cmd.strip() - path = os.path.normpath(self.path + "/" + path) - path = path + "/recipe" - if path in self.circle: - self.log.error("Detect import loop!") - raise RecipeExeption - self.circle.append(path) - recipe_to_include = recipe(path, circle=self.circle) - else: - machine = raw_line[0] - extra = "" - elif len(raw_line) == 2: - if raw_line[0].strip() == "include": - path = cmd - path = os.path.normpath(self.path + "/" + path) - path = path + "/recipe" - if path in self.circle: - self.log.error("Detect import loop!") - raise RecipeExeption - self.circle.append(path) - recipe_to_include = recipe(path, circle=self.circle) - else: - machine = raw_line[0] - extra = raw_line[1] - if raw_line[0].strip() == "include": + + machine = raw_line[0].strip() + + if len(raw_line) == 2: + extra = raw_line[1].strip() + else: + extra = "" + + # We could get a machine here or a include statement + if machine == "include": + path = cmd.strip() + path = os.path.normpath(self.path + "/" + path) + path = path + "/recipe" + if path in self.circle: + self.log.error("Detect import loop!") + raise RecipeExeption + self.circle.append(path) + recipe_to_include = recipe(path, circle=self.circle) + + if machine == "include": self._recipe.extend(recipe_to_include.recipe) else: self._recipe.append((machine.strip(), extra.strip(), cmd.strip())) -- 2.39.2