From d17080d325b9b82e8b844c207053eb2b3ac111ad Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Fri, 20 Jul 2018 17:15:20 +0200 Subject: [PATCH] Show links to include files on recipe detail On the recipe detail page we provide a link to the actual recipe file for reference purposes. However, for recipes that include a common .inc file, many of the definitions of variable values will be inside the .inc, therefore if you just look at the recipe you won't see the full picture. Of course you can just go up to the parent directory in the repository web interface, but for convenience's sake add links to any files that are included/required by the recipe that are adjacent to the recipe itself. (We already have the data in the form of the RecipeFileDependency records that are intended to ensure we know when the recipe needs to be updated if one of the files it includes changes). Signed-off-by: Paul Eggleton --- layerindex/models.py | 18 ++++++++++++++++++ layerindex/views.py | 5 +++++ templates/layerindex/comparisonrecipebase.html | 7 +++++++ templates/layerindex/recipedetail.html | 7 +++++++ 4 files changed, 37 insertions(+) diff --git a/layerindex/models.py b/layerindex/models.py index 66cbe67..6042d58 100644 --- a/layerindex/models.py +++ b/layerindex/models.py @@ -467,6 +467,17 @@ class Recipe(models.Model): eu = ExtraURL(name=item.name, url=item.render_url(self)) yield eu + def adjacent_includes(self): + """Returns an iterator over any files included by this recipe that are adjacent to the recipe (usually .inc files)""" + recipepath = os.path.join(self.layerbranch.vcs_subdir, self.filepath) + if not recipepath.endswith('/'): + recipepath += '/' + IncludeFile = namedtuple('IncludeFile', 'filepath vcs_web_url') + for rfd in self.recipefiledependency_set.all(): + if rfd.path.startswith(recipepath) and not os.path.basename(rfd.path) == self.filename: + ifile = IncludeFile(filepath=rfd.layer_path(), vcs_web_url=rfd.vcs_web_url()) + yield ifile + def comparison_recipes(self): return ClassicRecipe.objects.filter(cover_layerbranch=self.layerbranch).filter(cover_pn=self.pn) @@ -560,6 +571,13 @@ class RecipeFileDependency(models.Model): class Meta: verbose_name_plural = "Recipe file dependencies" + def layer_path(self): + return os.path.relpath(self.path, self.layerbranch.vcs_subdir) + + def vcs_web_url(self): + url = self.layerbranch.file_url(self.layer_path()) + return url or '' + def __str__(self): return '%s' % self.path diff --git a/layerindex/views.py b/layerindex/views.py index 1ebef49..fb2dd51 100644 --- a/layerindex/views.py +++ b/layerindex/views.py @@ -870,6 +870,11 @@ class RecipeDetailView(DetailView): context['verappends'] = verappends context['packageconfigs'] = recipe.packageconfig_set.order_by('feature') context['staticdependencies'] = recipe.staticbuilddep_set.order_by('name') + extrafiles = [] + for dep in recipe.recipefiledependency_set.all(): + if dep.path.endswith('.inc'): + extrafiles.append(dep) + context['extrafiles'] = extrafiles return context diff --git a/templates/layerindex/comparisonrecipebase.html b/templates/layerindex/comparisonrecipebase.html index 5fba8c1..50bcd76 100644 --- a/templates/layerindex/comparisonrecipebase.html +++ b/templates/layerindex/comparisonrecipebase.html @@ -116,6 +116,13 @@ {% else %} {{ rcp.full_path }} {% endif %} + {% for include in rcp.adjacent_includes %} + {% if include.vcs_web_url %} +
{{ include.filepath }} + {% else %} +
{{ include.filepath }} + {% endif %} + {% endfor %} {% endfor %} diff --git a/templates/layerindex/recipedetail.html b/templates/layerindex/recipedetail.html index 47b5e3f..6ed5a36 100644 --- a/templates/layerindex/recipedetail.html +++ b/templates/layerindex/recipedetail.html @@ -96,6 +96,13 @@ {% else %} {{ recipe.full_path }} {% endif %} + {% for include in recipe.adjacent_includes %} + {% if include.vcs_web_url %} +
{{ include.filepath }} + {% else %} +
{{ include.filepath }} + {% endif %} + {% endfor %}