]> git.ipfire.org Git - nitsi.git/commitdiff
Code cleanup in recipe parse
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Mon, 23 Apr 2018 11:38:01 +0000 (13:38 +0200)
committerJonatan Schlag <jonatan.schlag@ipfire.org>
Mon, 23 Apr 2018 11:38:01 +0000 (13:38 +0200)
I cleaned up the code to avoid multiple identical code statements and to
improve readability.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
test.py

diff --git a/test.py b/test.py
index 942411ba9c1db70b9cb6f0d7f1016bb0546040f0..2e2f13ae50cd39c98a1d8903072ba05fe708b9bb 100755 (executable)
--- 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
             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
             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
                     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()))
                 self._recipe.extend(recipe_to_include.recipe)
             else:
                 self._recipe.append((machine.strip(), extra.strip(), cmd.strip()))