]> git.ipfire.org Git - people/ms/nitsi.git/commitdiff
Add basic support for the include statement
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Mon, 23 Apr 2018 11:28:00 +0000 (13:28 +0200)
committerJonatan Schlag <jonatan.schlag@ipfire.org>
Mon, 23 Apr 2018 11:28:00 +0000 (13:28 +0200)
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
test.py

diff --git a/test.py b/test.py
index 634bf5b174faff4de75215cadded0c3295f92631..942411ba9c1db70b9cb6f0d7f1016bb0546040f0 100755 (executable)
--- a/test.py
+++ b/test.py
@@ -408,10 +408,15 @@ class RecipeExeption(Exception):
 # Should read the test, check if the syntax are valid
 # and return tuples with the ( host, command ) structure
 class recipe():
-    def __init__(self, path):
+    def __init__(self, path, circle=[]):
         self.log = log(4)
         self.recipe_file = path
+        self.path = os.path.dirname(self.recipe_file)
+        self.log.debug("Path of recipe is: {}".format(self.recipe_file))
         self._recipe = None
+        self.circle = circle
+        self.log.debug(circle)
+        self.log.debug(self.circle)
 
         if not os.path.isfile(self.recipe_file):
             self.log.error("No such file: {}".format(self.recipe_file))
@@ -446,13 +451,36 @@ class recipe():
                 if raw_line[0] == "":
                     self.log.error("Failed to parse the recipe in line {}".format(i))
                     raise RecipeExeption
-                machine = raw_line[0]
-                extra = ""
+                # 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:
-                machine = raw_line[0]
-                extra = raw_line[1]
-
-            self._recipe.append((machine.strip(), extra.strip(), cmd.strip()))
+                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":
+                self._recipe.extend(recipe_to_include.recipe)
+            else:
+                self._recipe.append((machine.strip(), extra.strip(), cmd.strip()))
             i = i + 1