Skip to contentSkip to conversation

toaster: orm Add get_base_recipe_file to CustomImageRecipe

PATCH New Elliot Smith 1 participant 2 messages Apr 26, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 toaster: orm Add get_base_recipe_file to CustomImageRecipe

From: Michael Wood <[email protected]>

This function returns the base recipe file path only if it currently exists. This allows us to know whether we can proceed at this point with generating a custom image recipe. It also enables us to call this function from the templates to enable visual indication of this state.

Some whitespace fixes also added in generate_recipe_file_contents

---
 bitbake/lib/toaster/orm/models.py | 60 ++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 23 deletions(-)
bitbake/lib/toaster/orm/models.py +37 -23
index 0b83b99..6716ddf 100644
@@ -1585,6 +1585,21 @@ class CustomImageRecipe(Recipe):
                                                   Q(recipe_includes=self)) &
                                                  ~Q(recipe_excludes=self))
 
+    def get_base_recipe_file(self):
+        """Get the base recipe file path if it exists on the file system"""
+        path_schema_one = "%s/%s" % (self.base_recipe.layer_version.dirpath,
+                                     self.base_recipe.file_path)
+
+        path_schema_two = self.base_recipe.file_path
+
+        if os.path.exists(path_schema_one):
+            return path_schema_one
+
+        # The path may now be the full path if the recipe has been built
+        if os.path.exists(path_schema_two):
+            return path_schema_two
+
+        return None
 
     def generate_recipe_file_contents(self):
         """Generate the contents for the recipe file."""
@@ -1599,17 +1614,16 @@ class CustomImageRecipe(Recipe):
             # We add all the known packages to be built by this recipe apart
             # from locale packages which are are controlled with IMAGE_LINGUAS.
             for pkg in self.get_all_packages().exclude(
-                name__icontains="locale"):
+                    name__icontains="locale"):
                 packages_conf += pkg.name+' '
 
         packages_conf += "\""
-        try:
-            base_recipe = open("%s/%s" %
-                               (self.base_recipe.layer_version.dirpath,
-                                self.base_recipe.file_path), 'r').read()
-        except IOError:
-            # The path may now be the full path if the recipe has been built
-            base_recipe = open(self.base_recipe.file_path, 'r').read()
+
+        base_recipe_path = self.get_base_recipe_file()
+        if base_recipe_path:
+            base_recipe = open(base_recipe_path, 'r').read()
+        else:
+            raise IOError("Based on recipe file not found")
 
         # Add a special case for when the recipe we have based a custom image
         # recipe on requires another recipe.
@@ -1618,8 +1632,8 @@ class CustomImageRecipe(Recipe):
         # "require recipes-core/images/core-image-minimal.bb"
 
         req_search = re.search(r'(require\s+)(.+\.bb\s*$)',
-                                   base_recipe,
-                                   re.MULTILINE)
+                               base_recipe,
+                               re.MULTILINE)
         if req_search:
             require_filename = req_search.group(2).strip()
 
@@ -1629,19 +1643,19 @@ class CustomImageRecipe(Recipe):
 
             new_require_line = "require %s" % corrected_location
 
-            base_recipe = \
-                    base_recipe.replace(req_search.group(0), new_require_line)
-
-
-        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(),
-               }
+            base_recipe = base_recipe.replace(req_search.group(0),
+                                              new_require_line)
+
+        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"
Signature · 12 lines
1.9.3

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
#1 lore raw

PATCH 2/2 toaster: customrecipe Only show download icon or button if it's possible

From: Michael Wood <[email protected]>

If the based on recipe has not yet been checked out/cloned we cannot generate the custom image recipe file that uses it. So disable/remove the option to download it.

[YOCTO #9425]

---
 bitbake/lib/toaster/toastergui/tables.py                   |  4 +++-
 bitbake/lib/toaster/toastergui/templates/customrecipe.html | 13 ++++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)
bitbake/lib/toaster/toastergui/tables.py +3 -1
index 2cc2f4e..d375da4 100644
@@ -508,10 +508,12 @@ class CustomImagesTable(ToasterTable):
 
         recipe_file_template = '''
         <code>{{data.name}}_{{data.version}}.bb</code>
+        {% if data.get_base_recipe_file %}
         <a href="{% url 'customrecipedownload' extra.pid data.pk %}">
         <i class="icon-download-alt" data-original-title="Download recipe
         file"></i>
-        </a>'''
+        </a>
+        {% endif %}'''
 
         self.add_column(title="Recipe file",
                         static_data_name='recipe_file_download',
bitbake/lib/toaster/toastergui/templates/customrecipe.html +12 -1
index ea3c9c7..aeb4466 100644
@@ -4,6 +4,7 @@
 {% load static %}
 {% block pagecontent %}
 
+{% with recipe.get_base_recipe_file as base_recipe_file %}
 <div class="section">
   <ul class="breadcrumb">
     <li>
@@ -99,8 +100,15 @@
       <a class="btn btn-large span6 build-custom-image" href="#" style="width: 50%">
         Build {{recipe.name}}
       </a>
-      <a href="{% url 'customrecipedownload' project.id recipe.id %}" class="btn btn-large span6" style="width: 50%">
+      <a href="{% url 'customrecipedownload' project.id recipe.id %}" class="btn btn-large span6" style="width: 50%"
+        {% if not base_recipe_file %}
+        disabled="disabled"
+        {% endif %}>
         Download recipe file
+        {% if not base_recipe_file %}
+        <i class="icon-question-sign get-help"
+          data-original-title="The {{recipe.name}} recipe cannot yet be downloaded as the Based on recipe '{{recipe.base_recipe.name}}' has not yet been fetched"></i>
+        {% endif %}
       </a>
     </div>
     <div id="no-results-special-{{table_name}}" class="air" style="display:none;">
@@ -177,7 +185,9 @@
         <dt>Recipe file</dt>
         <dd>
           <code>{{recipe.name}}_{{recipe.version}}.bb</code>
+          {% if base_recipe_path %}
           <a href="{% url 'customrecipedownload' project.pk recipe.pk %}"><i class="icon-share" title="" data-original-title="View recipe file"></i></a>
+          {% endif %}
         </dd>
         <dt>Layer</dt>
         <dd><a href="{% url 'layerdetails' project.id recipe.layer_version.pk %}">{{recipe.layer_version.layer.name}}</a></dd>
@@ -220,4 +230,5 @@
     </div>
   </div>
 
+{% endwith %}{# end base_recipe_file #}
   {% endblock %}
Signature · 12 lines
1.9.3

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.