]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
toaster: orm add CustomImageRecipe generate contents function
authorMichael Wood <michael.g.wood@intel.com>
Wed, 4 Nov 2015 14:56:36 +0000 (14:56 +0000)
committerMichael Wood <michael.g.wood@intel.com>
Mon, 8 Feb 2016 17:30:15 +0000 (17:30 +0000)
Add function generate_recipe_file_contents to dump the custom image
recipe instance to a string for use either to push to the user as a
downloaded version of their custom image recipe or to use to generate
the recipe that we build.

Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: brian avery <avery.brian@gmail.com>
lib/toaster/orm/models.py

index 20557abfc7d83b7998e71f9848efb8dece54af13..f826bcea342044bc32e954ad86f6538a4dbaeeb2 100644 (file)
@@ -1400,6 +1400,55 @@ class CustomImageRecipe(Recipe):
     base_recipe = models.ForeignKey(Recipe, related_name='based_on_recipe')
     project = models.ForeignKey(Project)
 
+    def generate_recipe_file_contents(self):
+        """Generate the contents for the recipe file."""
+        # If we have no excluded packages we only need to _append
+        if self.excludes_set.count() == 0:
+            packages_conf = "IMAGE_INSTALL_append = \" "
+
+            for pkg in self.appends_set.all():
+                packages_conf += pkg.name+' '
+        else:
+            packages_conf = "IMAGE_INSTALL = \""
+            # We add all the known packages to be built by this recipe apart
+            # from the packagegroups, which would bring the excluded package
+            # back in and locale packages which are dynamic packages which
+            # bitbake will not know about.
+            for pkg in \
+                    self.includes_set.exclude(
+                    Q(pk__in=self.excludes_set.values_list('pk', flat=True)) |
+                    Q(name__icontains="packagegroup") |
+                    Q(name__icontains="locale")):
+                print pkg.name
+                packages_conf += pkg.name+' '
+
+        packages_conf += "\""
+
+        base_recipe = open("%s/%s" %
+                           (self.base_recipe.layer_version.dirpath,
+                            self.base_recipe.file_path), 'r').read()
+
+        info = {"date" : timezone.now().strftime("%Y-%m-%d %H:%M:%S"),
+                "base_recipe" : base_recipe,
+                "recipe_name" : self.name,
+                "base_recipe_name" : self.base_recipe.name,
+                "license" : self.license,
+                "summary" : self.summary,
+                "description" : self.description,
+                "packages_conf" : packages_conf.strip(),
+               }
+
+        recipe_contents = ("# Original recipe %(base_recipe_name)s \n"
+                           "%(base_recipe)s\n\n"
+                           "# Recipe %(recipe_name)s \n"
+                           "# Customisation Generated by Toaster on %(date)s\n"
+                           "SUMMARY = \"%(summary)s\"\n"
+                           "DESCRIPTION = \"%(description)s\"\n"
+                           "LICENSE = \"%(license)s\"\n"
+                           "%(packages_conf)s") % info
+
+        return recipe_contents
+
 class ProjectVariable(models.Model):
     project = models.ForeignKey(Project)
     name = models.CharField(max_length=100)