Add Distribution, dependency and recommends detection, and import_project
cover Add Distribution, dependency and recommends detection, and import_project
This set of patches adds a number of features to the layerindex code:
- Adds the ability to set the actual-branch to import_layer. - Adds distribution to the database and web interface. - Adds collection & version information to layerbranch. - Uses layer name and collection name to determine dependencies and
recommends.
- Adds import_project to simplify pulling all layers and openembedded-core to a layer index.
Liam R. Howlett (10):
import_layer: Add --actual-branch option layerindex/tools/import_layer.py: Sanitize layer name. layerindex/tools/import_layer.py: Avoid failing if there is any layer
to add.
layerindex/utils: Update runcmd to decode binary strings to strings.
layerindex: Add distribution to web interface and model. layerindex/tools/import_project: Add import_project
layerindex: Detect dependencies from layer.conf files
layerindex: Add collection and version to layerbranch
layerindexer: Add layer recommends support
recipeparse: remove unnecessary else statement.
layerindex/admin.py | 11 ++ layerindex/layerconfparse.py | 39 +++++++ layerindex/models.py | 24 +++++ layerindex/recipeparse.py | 45 +++----- layerindex/restviews.py | 10 +- layerindex/tools/import_classic.py | 2 + layerindex/tools/import_layer.py | 49 ++++++++- layerindex/tools/import_project.py | 176 ++++++++++++++++++++++++++++++++ layerindex/update.py | 22 +++- layerindex/update_layer.py | 71 +++++++++++-- layerindex/urls.py | 3 + layerindex/urls_branch.py | 6 +- layerindex/utils.py | 136 +++++++++++++++++++++++- layerindex/views.py | 29 +++++- templates/layerindex/detail.html | 55 ++++++++-- templates/layerindex/distributions.html | 76 ++++++++++++++ templates/layerindex/layers.html | 1 + templates/layerindex/machines.html | 1 + templates/layerindex/recipes.html | 1 + 19 files changed, 696 insertions(+), 61 deletions(-) create mode 100644 layerindex/layerconfparse.py create mode 100755 layerindex/tools/import_project.py create mode 100644 templates/layerindex/distributions.html
Signature · 1 line
1.9.1
PATCH 1/10 import_layer: Add --actual-branch option
Allow users to set actual-branch from the command line import of layers.
--- layerindex/tools/import_layer.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
layerindex/tools/import_layer.py +8 -2
@@ -200,6 +200,9 @@ def main(): parser.add_option("-q", "--quiet", help = "Hide all output except error messages", action="store_const", const=logging.ERROR, dest="loglevel") + parser.add_option("-a", "--actual-branch", + help = "Set actual branch", + action="store", dest="actual_branch") options, args = parser.parse_args(sys.argv)
@@ -273,10 +276,13 @@ def main(): logger.error("Fetch failed: %s" % str(e)) sys.exit(1) - actual_branch = '' + actual_branch = 'master' + if (options.actual_branch): + actual_branch = options.actual_branch try: - out = utils.runcmd("git checkout origin/master", repodir, logger=logger) + out = utils.runcmd("git checkout origin/%s" % actual_branch, repodir, logger=logger) except subprocess.CalledProcessError: + actual_branch = None branches = utils.runcmd("git branch -r", repodir, logger=logger) for line in branches.splitlines(): if 'origin/HEAD ->' in line:
Signature · 1 line
1.9.1
PATCH 2/10 layerindex/tools/import_layer.py: Sanitize layer name.
In reply to Liam R. HowlettDjango will produce a cryptic error message if layers are added with invalid names. Sanitize the layer names when trying to add them.
--- layerindex/tools/import_layer.py | 6 ++++++ 1 file changed, 6 insertions(+)
layerindex/tools/import_layer.py +6 -0
@@ -181,6 +181,8 @@ def get_github_layerinfo(layer_url, username = None, password = None): def main(): + valid_layer_name = re.compile('[-\w]+$') + parser = optparse.OptionParser( usage = """ %prog [options] <url> [name]""")
@@ -222,6 +224,10 @@ def main(): if layer_name.endswith('.git'): layer_name = layer_name[:-4] + if not valid_layer_name.match(layer_name): + logger.error('Invlaid layer name "%s" - Layer name can only include letters, numbers and dashes.', layer_name) + sys.exit(1) + if options.github_auth: if not ':' in options.github_auth: logger.error('--github-auth value must be specified as username:password')
Signature · 1 line
1.9.1
Re: [layerindex-web][PATCH 02/10] layerindex/tools/import_layer.py: Sanitize layer name.
Quoted 23 lines · On Mon, 26 Sep 2016 14:25:30 Liam R. Howlett wrote:
Django will produce a cryptic error message if layers are added with invalid names. Sanitize the layer names when trying to add them.
Signed-off-by Liam R. Howlett <[email protected]>--- layerindex/tools/import_layer.py | 6 ++++++ 1 file changed, 6 insertions(+)(quoted diff) +0
-0
b/layerindex/tools/import_layer.pyindex 9b5da22..8d9e8cb 100755layerindex/tools/import_layer.py +0
-0@@ -181,6 +181,8 @@ def get_github_layerinfo(layer_url, username = None,password = None):
def
main():layerindex/tools/import_layer.py +2
-0+ valid_layer_name = re.compile('[-\w]+$') + parser = optparse.OptionParser( usage = """ %prog [options] <url> [name]""")
layerindex/tools/import_layer.py def main(): · line 230
Quoted 7 lines
layerindex/tools/import_layer.py +3
-0@@ -222,6 +224,10 @@ def main(): if layer_name.endswith('.git'): layer_name = layer_name[:-4] + if not valid_layer_name.match(layer_name): + logger.error('Invlaid layer name "%s" - Layer name can only include letters, numbers and dashes.', layer_name) + sys.exit(1)
Typo "Invlaid", and the indenting is out here too.
Cheers,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
PATCH 3/10 layerindex/tools/import_layer.py: Avoid failing if there is any layer to add.
In reply to Liam R. HowlettSubdirectories are scanned when adding layers. If any of the subdirectories or root directory layers already exist in the database, then the addition fails. This changes that behaviour to report the failure as a warning and remove it from the list. That way, if a repo has a new layer added it can be rescanned without issue. Layers being rescanned are checked against the vcs_url to ensure there is not a name collision. A name collision without the same vcs_url will still produce a hard failure.
Note that multiple layers with the same vcs_url are supported in the error reporting even though this should never happen.
--- layerindex/tools/import_layer.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
layerindex/tools/import_layer.py +19 -2
@@ -334,8 +334,21 @@ def main(): else: subdir = '' if LayerItem.objects.filter(name=layer.name).exists(): - logger.error('A layer named "%s" already exists in the database' % layer_name) - sys.exit(1) + if LayerItem.objects.filter(name=layer.name).exclude(vcs_url=layer.vcs_url).exists(): + conflict_list = LayerItem.objects.filter(name=layer.name).exclude(vcs_url=layer.vcs_url) + cln = ', ' + conflict_list_urls = [] + for conflict in conflict_list: + conflict_list_urls.append(conflict.vcs_url) + cln = cln.join(conflict_list_urls) + logger.error('A layer named "%s" already exists in the database. Possible name collision with %s.vcs_url = %s' % (layer.name, layer.name, cln)) + sys.exit(1) + else: + logger.info('The layer named "%s" already exists in the database. Skipping this layer with same vcs_url' % layer.name) + layer_paths = [x for x in layer_paths if x != layerdir] + continue + + logger.info('Creating layer %s' % layer.name) # Guess layer type
@@ -411,6 +424,10 @@ def main(): layer.save() + if not layer_paths: + logger.error('No layers added.') + sys.exit(1); + if options.dryrun: raise DryRunRollbackException() except DryRunRollbackException:
Signature · 1 line
1.9.1
Re: [layerindex-web][PATCH 03/10] layerindex/tools/import_layer.py: Avoid failing if there is any layer to add.
Quoted 33 lines · On Mon, 26 Sep 2016 14:25:31 Liam R. Howlett wrote:
Subdirectories are scanned when adding layers. If any of the subdirectories or root directory layers already exist in the database, then the addition fails. This changes that behaviour to report the failure as a warning and remove it from the list. That way, if a repo has a new layer added it can be rescanned without issue. Layers being rescanned are checked against the
vcs_urlto ensure there is not a name collision. A name collision without the samevcs_urlwill still produce a hard failure.Note that multiple layers with the same
vcs_urlare supported in the error reporting even though this should never happen.Signed-off-by Liam R. Howlett <[email protected]>--- layerindex/tools/import_layer.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)(quoted diff) +0
-0
b/layerindex/tools/import_layer.pyindex 8d9e8cb..21b31f5 100755layerindex/tools/import_layer.py +1
-2@@ -334,8 +334,21 @@ def main(): else: subdir = '' if LayerItem.objects.filter(name=layer.name).exists(): - logger.error('A layer named "%s" already exists in the database' % layer_name) - sys.exit(1) + ifLayerItem.objects.filter(name=layer.name).exclude(vcs_url=layer.vcs_url).ex
ists():
+conflict_list=
LayerItem.objects.filter(name=layer.name).exclude(vcs_url=layer.vcs_url)
layerindex/tools/import_layer.py def main(): · line 343
Quoted 5 lines
layerindex/tools/import_layer.py +5
-0+ cln = ', ' + conflict_list_urls = [] + for conflict in conflict_list: + conflict_list_urls.append(conflict.vcs_url) + cln = cln.join(conflict_list_urls)
Not a huge deal, but is there any particular reason you didn't omit the initial assignment and do this instead:
cln = ', '.join(conflict_list_urls)
layerindex/tools/import_layer.py def main(): · line 430
Quoted 5 lines
layerindex/tools/import_layer.py +4
-0+ if not layer_paths: + logger.error('No layers added.') + sys.exit(1); +
Indenting is out here (should always be four spaces for a block indent).
Also typo in the shortlog - "if there is no layer to add" and strictly speaking there shouldn't be a period at the end.
Cheers,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
PATCH 4/10 layerindex/utils: Update runcmd to decode binary strings to strings.
In reply to Liam R. HowlettConvert binary strings to strings and strip leading/trailing whitespace prior to returning errors and output.
--- layerindex/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
layerindex/utils.py +6 -2
@@ -32,7 +32,8 @@ def runcmd(cmd, destdir=None, printerr=True, logger=None): execute command, raise CalledProcessError if fail return output if succeed """ - #logger.debug("run cmd '%s' in %s" % (cmd, os.getcwd() if destdir is None else destdir)) + if logger: + logger.debug("run cmd '%s' in %s" % (cmd, os.getcwd() if destdir is None else destdir)) out = tempfile.TemporaryFile() try: subprocess.check_call(cmd, stdout=out, stderr=out, cwd=destdir, shell=True)
@@ -40,6 +41,7 @@ def runcmd(cmd, destdir=None, printerr=True, logger=None): out.seek(0) if printerr: output = out.read() + output = output.decode('ascii').strip() if logger: logger.error("%s" % output) else:
@@ -49,7 +51,9 @@ def runcmd(cmd, destdir=None, printerr=True, logger=None): out.seek(0) output = out.read() - #logger.debug("output: %s" % output.rstrip() ) + output = output.decode('ascii').strip() + if logger: + logger.debug("output: %s" % output.rstrip() ) return output def setup_django():
Signature · 1 line
1.9.1
PATCH 5/10 layerindex: Add distribution to web interface and model.
In reply to Liam R. HowlettAdd the distributions to the index. This looks a lot like the machines and allows users to search for a particular distribution.
--- layerindex/admin.py | 11 +++++ layerindex/models.py | 14 ++++++ layerindex/recipeparse.py | 5 +++ layerindex/restviews.py | 10 ++++- layerindex/tools/import_classic.py | 2 + layerindex/update_layer.py | 46 +++++++++++++++++++- layerindex/urls.py | 3 ++ layerindex/urls_branch.py | 6 ++- layerindex/views.py | 29 ++++++++++++- templates/layerindex/detail.html | 23 ++++++++++ templates/layerindex/distributions.html | 76 +++++++++++++++++++++++++++++++++ templates/layerindex/layers.html | 1 + templates/layerindex/machines.html | 1 + templates/layerindex/recipes.html | 1 + 14 files changed, 224 insertions(+), 4 deletions(-) create mode 100644 templates/layerindex/distributions.html
layerindex/admin.py +11 -0
@@ -75,6 +75,16 @@ class MachineAdmin(admin.ModelAdmin): def has_delete_permission(self, request, obj=None): return False +class DistributionAdmin(admin.ModelAdmin): + search_fields = ['name'] + list_filter = ['layerbranch__layer__name', 'layerbranch__branch__name'] + readonly_fields = Distribution._meta.get_all_field_names() + def has_add_permission(self, request, obj=None): + return False + def has_delete_permission(self, request, obj=None): + return False + + class BBAppendAdmin(admin.ModelAdmin): search_fields = ['filename'] list_filter = ['layerbranch__layer__name', 'layerbranch__branch__name']
@@ -111,6 +121,7 @@ admin.site.register(LayerNote, LayerNoteAdmin) admin.site.register(Recipe, RecipeAdmin) admin.site.register(RecipeFileDependency) admin.site.register(Machine, MachineAdmin) +admin.site.register(Distribution, DistributionAdmin) admin.site.register(BBAppend, BBAppendAdmin) admin.site.register(BBClass, BBClassAdmin) admin.site.register(RecipeChangeset, RecipeChangesetAdmin)
layerindex/models.py +14 -0
@@ -361,6 +361,20 @@ class Machine(models.Model): def __str__(self): return '%s (%s)' % (self.name, self.layerbranch.layer.name) +class Distribution(models.Model): + layerbranch = models.ForeignKey(LayerBranch) + name = models.CharField(max_length=255) + description = models.CharField(max_length=255) + + updated = models.DateTimeField(auto_now=True) + + def vcs_web_url(self): + url = self.layerbranch.file_url(os.path.join('conf/distro/%s.conf' % self.name)) + return url or '' + + def __str__(self): + return '%s (%s)' % (self.name, self.layerbranch.layer.name) + class BBAppend(models.Model): layerbranch = models.ForeignKey(LayerBranch)
layerindex/recipeparse.py +5 -0
@@ -152,6 +152,7 @@ def get_var_files(fn, varlist, d): return varfiles machine_conf_re = re.compile(r'conf/machine/([^/.]*).conf$') +distro_conf_re = re.compile(r'conf/distro/([^/.]*).conf$') bbclass_re = re.compile(r'classes/([^/.]*).bbclass$') def detect_file_type(path, subdir_start): typename = None
@@ -171,6 +172,10 @@ def detect_file_type(path, subdir_start): if res: typename = 'bbclass' return (typename, None, res.group(1)) + res = distro_conf_re.match(subpath) + if res: + typename = 'distribution' + return (typename, None, res.group(1)) if typename == 'recipe' or typename == 'bbappend': if subdir_start:
layerindex/restviews.py +9 -1
@@ -1,4 +1,4 @@ -from layerindex.models import Branch, LayerItem, LayerNote, LayerBranch, LayerDependency, Recipe, Machine +from layerindex.models import Branch, LayerItem, LayerNote, LayerBranch, LayerDependency, Recipe, Machine, Distribution from rest_framework import viewsets, serializers from layerindex.querysethelper import params_to_queryset, get_search_tuple
@@ -56,3 +56,11 @@ class MachineSerializer(serializers.ModelSerializer): class MachineViewSet(ParametricSearchableModelViewSet): queryset = Machine.objects.all() serializer_class = MachineSerializer + +class DistributionSerializer(serializers.ModelSerializer): + class Meta: + model = Distribution + +class DistributionViewSet(ParametricSearchableModelViewSet): + queryset = Distribution.objects.all() + serializer_class = DistributionSerializer
layerindex/tools/import_classic.py +2 -0
@@ -160,6 +160,7 @@ def main(): layerdir_start = os.path.normpath(oeclassicpath) + os.sep layerrecipes = Recipe.objects.filter(layerbranch=layerbranch) layermachines = Machine.objects.filter(layerbranch=layerbranch) + layerdistributions = Distribution.objects.filter(layerbranch=layerbranch) layerappends = BBAppend.objects.filter(layerbranch=layerbranch) layerclasses = BBClass.objects.filter(layerbranch=layerbranch)
@@ -172,6 +173,7 @@ def main(): layerrecipes.delete() layermachines.delete() + layerdistributions.delete() layerappends.delete() layerclasses.delete() for root, dirs, files in os.walk(oeclassicpath):
layerindex/update_layer.py +45 -1
100 lines not on this page · raw message
layerindex/urls.py +3 -0
@@ -21,6 +21,7 @@ router.register(r'layerBranches', restviews.LayerBranchViewSet) router.register(r'layerDependencies', restviews.LayerDependencyViewSet) router.register(r'recipes', restviews.RecipeViewSet) router.register(r'machines', restviews.MachineViewSet) +router.register(r'distributions', restviews.DistributionViewSet) urlpatterns = patterns('', url(r'^$',
@@ -37,6 +38,8 @@ urlpatterns = patterns('', RedirectView.as_view(url=reverse_lazy('recipe_search', args=('master',)), permanent=False)), url(r'^machines/$', RedirectView.as_view(url=reverse_lazy('machine_search', args=('master',)), permanent=False)), + url(r'^distributions/$', + RedirectView.as_view(url=reverse_lazy('distribution_search', args=('master',)), permanent=False)), url(r'^submit/$', edit_layer_view, {'template_name': 'layerindex/submitlayer.html'}, name="submit_layer"), url(r'^submit/thanks$',
layerindex/urls_branch.py +5 -1
@@ -7,7 +7,7 @@ from django.conf.urls import * from django.views.defaults import page_not_found from django.core.urlresolvers import reverse_lazy -from layerindex.views import LayerListView, RecipeSearchView, MachineSearchView, PlainTextListView, LayerDetailView, edit_layer_view, delete_layer_view, edit_layernote_view, delete_layernote_view, RedirectParamsView, DuplicatesView +from layerindex.views import LayerListView, RecipeSearchView, MachineSearchView, DistributionSearchView, PlainTextListView, LayerDetailView, edit_layer_view, delete_layer_view, edit_layernote_view, delete_layernote_view, RedirectParamsView, DuplicatesView urlpatterns = patterns('', url(r'^$',
@@ -28,6 +28,10 @@ urlpatterns = patterns('', MachineSearchView.as_view( template_name='layerindex/machines.html'), name='machine_search'), + url(r'^distributions/$', + DistributionSearchView.as_view( + template_name='layerindex/distributions.html'), + name='distribution_search'), url(r'^edit/(?P<slug>[-\w]+)/$', edit_layer_view, {'template_name': 'layerindex/editlayer.html'}, name="edit_layer"), url(r'^duplicates/$', DuplicatesView.as_view(
layerindex/views.py +28 -1
@@ -10,7 +10,7 @@ from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidde from django.core.urlresolvers import reverse, reverse_lazy, resolve from django.core.exceptions import PermissionDenied from django.template import RequestContext -from layerindex.models import Branch, LayerItem, LayerMaintainer, LayerBranch, LayerDependency, LayerNote, Recipe, Machine, BBClass, BBAppend, RecipeChange, RecipeChangeset, ClassicRecipe +from layerindex.models import Branch, LayerItem, LayerMaintainer, LayerBranch, LayerDependency, LayerNote, Recipe, Machine, Distribution, BBClass, BBAppend, RecipeChange, RecipeChangeset, ClassicRecipe from datetime import datetime from itertools import chain from django.views.generic import TemplateView, DetailView, ListView
@@ -326,6 +326,7 @@ class LayerDetailView(DetailView): if layerbranch: context['layerbranch'] = layerbranch context['machines'] = layerbranch.machine_set.order_by('name') + context['distributions'] = layerbranch.distribution_set.order_by('name') context['appends'] = layerbranch.bbappend_set.order_by('filename') context['classes'] = layerbranch.bbclass_set.order_by('name') context['url_branch'] = self.kwargs['branch']
@@ -596,6 +597,32 @@ class MachineSearchView(ListView): return context +class DistributionSearchView(ListView): + context_object_name = 'distribution_list' + paginate_by = 50 + + def get_queryset(self): + _check_url_branch(self.kwargs) + query_string = self.request.GET.get('q', '') + init_qs = Distribution.objects.filter(layerbranch__branch__name=self.kwargs['branch']) + if query_string.strip(): + entry_query = simplesearch.get_query(query_string, ['name', 'description']) + return init_qs.filter(entry_query).order_by('name', 'layerbranch__layer') + + if 'q' in self.request.GET: + return init_qs.order_by('name', 'layerbranch__layer') + + # Be consistent with RecipeSearchView + return Distribution.objects.none() + + def get_context_data(self, **kwargs): + context = super(DistributionSearchView, self).get_context_data(**kwargs) + context['search_keyword'] = self.request.GET.get('q', '') + context['url_branch'] = self.kwargs['branch'] + context['this_url_name'] = resolve(self.request.path_info).url_name + return context + + class PlainTextListView(ListView): def render_to_response(self, context): "Returns a plain text response rendering of the template"
templates/layerindex/detail.html +23 -0
@@ -168,6 +168,9 @@ {% if classes.count > 0 %} <li><a href="#classes" data-toggle="tab">Classes</a></li> {% endif %} + {% if distributions.count > 0 %} + <li><a href="#distributions" data-toggle="tab">Distributions</a></li> + {% endif %} </ul> <div class="tab-content">
@@ -265,6 +268,26 @@ </table> </div> {% endif %} + {% if distributions.count > 0 %} + <div class="tab-pane" id="distributions"> + <div class="navbar"> + <div class="navbar-inner"> + <a class="brand pull-left">{{ layeritem.name }} distributions</a> + </div> + </div> + + <table class="table table-bordered"> + <tbody> + {% for distribution in distributions %} + <tr> + <td><a href="{{ distribution.vcs_web_url }}">{{ distribution.name }}</a></td> + <td>{{ distribution.description }}</td> + </tr> + {% endfor %} + </tbody> + </table> + </div> + {% endif %} </div>
templates/layerindex/distributions.html new file +76 -0
76 lines not on this page · raw message
templates/layerindex/layers.html +1 -0
@@ -21,6 +21,7 @@ <li class="active"><a href="{% url 'layer_list' url_branch %}">Layers</a></li> <li><a href="{% url 'recipe_search' url_branch %}">Recipes</a></li> <li><a href="{% url 'machine_search' url_branch %}">Machines</a></li> + <li><a href="{% url 'distribution_search' url_branch %}">Distributions</a></li> {% endautoescape %} {% endblock %}
templates/layerindex/machines.html +1 -0
@@ -20,6 +20,7 @@ <li><a href="{% url 'layer_list' url_branch %}">Layers</a></li> <li><a href="{% url 'recipe_search' url_branch %}">Recipes</a></li> <li class="active"><a href="{% url 'machine_search' url_branch %}">Machines</a></li> + <li><a href="{% url 'distribution_search' url_branch %}">Distributions</a></li> {% endautoescape %} {% endblock %}
templates/layerindex/recipes.html +1 -0
@@ -20,6 +20,7 @@ <li><a href="{% url 'layer_list' url_branch %}">Layers</a></li> <li class="active"><a href="{% url 'recipe_search' url_branch %}">Recipes</a></li> <li><a href="{% url 'machine_search' url_branch %}">Machines</a></li> + <li><a href="{% url 'distribution_search' url_branch %}">Distributions</a></li> {% endautoescape %} {% endblock %}
Signature · 1 line
1.9.1
Re: [layerindex-web][PATCH 05/10] layerindex: Add distribution to web interface and model.
Quoted 4 lines · On Mon, 26 Sep 2016 14:25:33 Liam R. Howlett wrote:
Add the distributions to the index. This looks a lot like the machines and allows users to search for a particular distribution.
Signed-off-by Liam R. Howlett <[email protected]>
Quoted 12 lines
--- layerindex/admin.py | 11 +++++ layerindex/models.py | 14 ++++++ layerindex/recipeparse.py | 5 +++ layerindex/restviews.py | 10 ++++- layerindex/tools/import_classic.py | 2 + layerindex/update_layer.py | 46 +++++++++++++++++++- layerindex/urls.py | 3 ++ layerindex/urls_branch.py | 6 ++- layerindex/views.py | 29 ++++++++++++- templates/layerindex/detail.html | 23 ++++++++++ templates/layerindex/distributions.html | 76
Sorry, I know it's probably going to be a pain, I'd really like to be using the term "distro" here rather than "distribution" - that would match up with our existing variable and path naming, and at the same time will resolve a few typos in this patch (e.g. "distribuiton").
Also, any change to the structure needs to be accompanied by a migration to handle existing databases. Since you're working with Django 1.8 you'd be creating its migrations rather than South's, and we had to start with a clean slate for that so I can see perhaps why you missed them.
Cheers,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
PATCH 6/10 layerindex/tools/import_project: Add import_project
In reply to Liam R. Howlettimport_project will scan through a project and find any layer and add it to the database by calling import_layer on each layer. This differs from import_layer as it tires to figure out the remote url and uses the subdirectory (if one exists) as the name.
--- layerindex/tools/import_layer.py | 7 ++ layerindex/tools/import_project.py | 176 +++++++++++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100755 layerindex/tools/import_project.py
layerindex/tools/import_layer.py +7 -0
@@ -360,6 +360,13 @@ def main(): layerbranch = LayerBranch() layerbranch.layer = layer layerbranch.branch = master_branch + layerbranch.save() + + if layer.name != settings.CORE_LAYER_NAME: + layerconfparser = LayerConfParse(logger=logger) + config_data = layerconfparser.parse_layer(layerdir) + layerconfparser.shutdown() + utils.set_layerbranch_collection_version(layerbranch, config_data, logger=logger) if layerdir != repodir: layerbranch.vcs_subdir = subdir if actual_branch:
layerindex/tools/import_project.py new file +176 -0
176 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [layerindex-web][PATCH 06/10] layerindex/tools/import_project: Add import_project
Quoted 4 lines · On Mon, 26 Sep 2016 14:25:34 Liam R. Howlett wrote:
import_projectwill scan through a project and find any layer and add it to the database by callingimport_layeron each layer. This differs fromimport_layeras it tires to figure out the remote url and uses the subdirectory (if one exists) as the name.
Looks good, but the two dryrun blocks have incorrect indenting.
Cheers,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
PATCH 7/10 layerindex: Detect dependencies from layer.conf files
In reply to Liam R. HowlettRead dependencies from layer.conf and try to create the LayerDependency entry by looking up the correct database object. Dependencies are found by layer name only - no collection support. layer.conf parsing is handled by the bitbake code.
--- layerindex/layerconfparse.py | 39 ++++++++++++++ layerindex/models.py | 4 ++ layerindex/recipeparse.py | 31 ++--------- layerindex/tools/import_layer.py | 8 +++ layerindex/update.py | 20 +++++++- layerindex/utils.py | 108 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 181 insertions(+), 29 deletions(-) create mode 100644 layerindex/layerconfparse.py
layerindex/layerconfparse.py new file +39 -0
@@ -0,0 +1,39 @@ +# Utility functions for parsing layer.conf using bitbake within layerindex-web +# +# Copyright (C) 2016 Wind River Systems +# Author: Liam R. Howlett <[email protected]> +# +# Licensed under the MIT license, see COPYING.MIT for details +# + +import sys +import os +import os.path +import utils +import tempfile +import re + +class LayerConfParse: + def __init__(self, enable_tracking=False, logger=None, bitbakepath=None): + import settings + self.logger = logger + + if not bitbakepath: + fetchdir = settings.LAYER_FETCH_DIR + bitbakepath = os.path.join(fetchdir, 'bitbake') + self.bbpath = bitbakepath + + # Set up BBPATH. + os.environ['BBPATH'] = str("%s" % self.bbpath) + self.tinfoil = utils.setup_tinfoil(self.bbpath, enable_tracking) + self.config_data_copy = bb.data.createCopy(self.tinfoil.config_data) + + + def parse_layer(self, layerdir): + utils.parse_layer_conf(layerdir, self.config_data_copy) + return self.config_data_copy + + def shutdown(self): + self.tinfoil.shutdown() + +
layerindex/models.py +4 -0
@@ -209,6 +209,9 @@ class LayerBranch(models.Model): return "%s: %s" % (self.layer.name, self.branch.name) + def get_required(self): + return self.dependencies_set.filter(required=True) + class LayerMaintainer(models.Model): MAINTAINER_STATUS_CHOICES = ( ('A', 'Active'),
@@ -230,6 +233,7 @@ class LayerMaintainer(models.Model): class LayerDependency(models.Model): layerbranch = models.ForeignKey(LayerBranch, related_name='dependencies_set') dependency = models.ForeignKey(LayerItem, related_name='dependents_set') + required = models.BooleanField(default=True) class Meta: verbose_name_plural = "Layer dependencies"
layerindex/recipeparse.py +3 -28
@@ -20,31 +20,6 @@ class RecipeParseError(Exception): def __str__(self): return self.msg -def _setup_tinfoil(bitbakepath, enable_tracking): - sys.path.insert(0, bitbakepath + '/lib') - import bb.tinfoil - import bb.cooker - import bb.data - try: - tinfoil = bb.tinfoil.Tinfoil(tracking=enable_tracking) - except TypeError: - # old API - tinfoil = bb.tinfoil.Tinfoil() - if enable_tracking: - tinfoil.cooker.enableDataTracking() - tinfoil.prepare(config_only = True) - - return tinfoil - -def _parse_layer_conf(layerdir, data): - data.setVar('LAYERDIR', str(layerdir)) - if hasattr(bb, "cookerdata"): - # Newer BitBake - data = bb.cookerdata.parse_config_file(os.path.join(layerdir, "conf", "layer.conf"), data) - else: - # Older BitBake (1.18 and below) - data = bb.cooker._parse(os.path.join(layerdir, "conf", "layer.conf"), data) - data.expandVarref('LAYERDIR') def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout=False, classic=False, logger=None):
@@ -97,7 +72,7 @@ def init_parser(settings, branch, bitbakepath, enable_tracking=False, nocheckout tempdir = tempfile.mkdtemp(dir=settings.TEMP_BASE_DIR) os.chdir(tempdir) - tinfoil = _setup_tinfoil(bitbakepath, enable_tracking) + tinfoil = utils.setup_tinfoil(bitbakepath, enable_tracking) # Ensure TMPDIR exists (or insane.bbclass will blow up trying to write to the QA log) oe_tmpdir = tinfoil.config_data.getVar('TMPDIR', True)
@@ -125,7 +100,7 @@ def setup_layer(config_data, fetchdir, layerdir, layer, layerbranch): # or across layers, but also because custom variable values might be # set in layer.conf. config_data_copy = bb.data.createCopy(config_data) - _parse_layer_conf(layerdir, config_data_copy) + utils.parse_layer_conf(layerdir, config_data_copy) for dep in layerbranch.dependencies_set.all(): depurldir = dep.dependency.get_fetch_dir() deprepodir = os.path.join(fetchdir, depurldir)
@@ -133,7 +108,7 @@ def setup_layer(config_data, fetchdir, layerdir, layer, layerbranch): if not deplayerbranch: raise RecipeParseError('Dependency %s of layer %s does not have branch record for branch %s' % (dep.dependency.name, layer.name, layerbranch.branch.name)) deplayerdir = os.path.join(deprepodir, deplayerbranch.vcs_subdir) - _parse_layer_conf(deplayerdir, config_data_copy) + utils.parse_layer_conf(deplayerdir, config_data_copy) config_data_copy.delVar('LAYERDIR') return config_data_copy
layerindex/tools/import_layer.py +8 -0
@@ -19,6 +19,7 @@ import glob import utils import logging import subprocess +from layerconfparse import LayerConfParse class DryRunRollbackException(Exception): pass
@@ -375,11 +376,18 @@ def main(): if layer.name != settings.CORE_LAYER_NAME: if not core_layer: core_layer = utils.get_layer(settings.CORE_LAYER_NAME) + if core_layer: + logger.debug('Adding dep %s to %s' % (core_layer.name, layer.name)) layerdep = LayerDependency() layerdep.layerbranch = layerbranch layerdep.dependency = core_layer layerdep.save() + layerconfparser = LayerConfParse(logger=logger) + config_data = layerconfparser.parse_layer(layerdir) + layerconfparser.shutdown() + utils.add_dependencies(layerbranch, config_data, logger=logger) + # Get some extra meta-information readme_files = glob.glob(os.path.join(layerdir, 'README*'))
layerindex/update.py +19 -1
@@ -16,6 +16,8 @@ import subprocess import signal from distutils.version import LooseVersion import utils +from layerconfparse import LayerConfParse + import warnings warnings.filterwarnings("ignore", category=DeprecationWarning)
@@ -92,7 +94,7 @@ def main(): utils.setup_django() import settings - from layerindex.models import Branch, LayerItem + from layerindex.models import Branch, LayerItem, LayerDependency logger.setLevel(options.loglevel)
@@ -201,6 +203,22 @@ def main(): # Interrupted by user, break out of loop break + # Once indexed, then conf/layer.conf dependencies should be reevaluated. + layerconfparser = LayerConfParse(logger=logger, bitbakepath=bitbakepath) + for branch in branches: + for layer in layerquery: + urldir = layer.get_fetch_dir() + repodir = os.path.join(fetchdir, urldir) + + layerbranch = layer.get_layerbranch(branch) + if layerbranch.vcs_subdir: + repodir = os.path.join(repodir, layerbranch.vcs_subdir) + config_data = layerconfparser.parse_layer(repodir) + utils.add_dependencies(layerbranch, config_data, logger=logger) + + layerconfparser.shutdown() + + finally: utils.unlock_file(lockfile)
layerindex/utils.py +108 -0
114 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [layerindex-web][PATCH 07/10] layerindex: Detect dependencies from layer.conf files
Quoted 4 lines · On Mon, 26 Sep 2016 14:25:35 Liam R. Howlett wrote:
Read dependencies from layer.conf and try to create the LayerDependency entry by looking up the correct database object. Dependencies are found by layer name only - no collection support. layer.conf parsing is handled by the bitbake code.
I see you did some refactoring here to move some of the code needed to parse the layer conf to the utils module. Generally I do that kind of thing in a separate patch, although I won't insist upon it - however if you do do it as part of this patch then it needs to at least be mentioned as part of the commit message.
Quoted 22 lines
layerindex/models.py +4
-0@@ -209,6 +209,9 @@ class LayerBranch(models.Model): return "%s: %s" % (self.layer.name, self.branch.name) + def get_required(self): + return self.dependencies_set.filter(required=True) + class LayerMaintainer(models.Model): MAINTAINER_STATUS_CHOICES = ( ('A', 'Active'),@@ -230,6 +233,7 @@ class LayerMaintainer(models.Model): class LayerDependency(models.Model): layerbranch = models.ForeignKey(LayerBranch, related_name='dependencies_set') dependency = models.ForeignKey(LayerItem, related_name='dependents_set') + required = models.BooleanField(default=True) class Meta:
Quoted 1 line
verbose_name_plural= "Layer dependencies"
This "required" field doesn't seem to be used in this commit - can you move these two changes to be part of the "recommends" support patch where they are used?
Quoted 18 lines
layerindex/tools/import_layer.py +3
-0@@ -19,6 +19,7 @@ import glob import utils import logging import subprocess +from layerconfparse import LayerConfParse class DryRunRollbackException(Exception): pass@@ -375,11 +376,18 @@ def main(): if layer.name != settings.CORE_LAYER_NAME: if not core_layer: core_layer = utils.get_layer(settings.CORE_LAYER_NAME) + if core_layer: + logger.debug('Adding dep %s to %s' %
layerindex/tools/import_layer.py def main(): · line 392
Quoted 10 lines
layerindex/tools/import_layer.py +5
-0(core_layer.name, layer.name)) layerdep = LayerDependency() layerdep.layerbranch = layerbranch layerdep.dependency = core_layer layerdep.save() + layerconfparser = LayerConfParse(logger=logger) + config_data = layerconfparser.parse_layer(layerdir) + layerconfparser.shutdown() + utils.add_dependencies(layerbranch, config_data, logger=logger) +
Use try..finally here to ensure shutdown() gets run.
Quoted 29 lines
layerindex/tools/import_layer.py +0
-0# Get some extra meta-information
readme_files=glob.glob(os.path.join(layerdir, 'README*'))layerindex/update.py +4
-1@@ -16,6 +16,8 @@ import subprocess import signal from distutils.version import LooseVersion import utils +from layerconfparse import LayerConfParse + import warnings warnings.filterwarnings("ignore", category=DeprecationWarning)@@ -92,7 +94,7 @@ def main(): utils.setup_django() import settings - from layerindex.models import Branch, LayerItem + from layerindex.models import Branch, LayerItem, LayerDependency logger.setLevel(options.loglevel)@@ -201,6 +203,22 @@ def main(): # Interrupted by user, break out of loop break + # Once indexed, then conf/layer.conf dependencies should be
Quoted 1 line
reevaluated.
Shouldn't this be triggered solely when layer.conf changes rather than every time?
Quoted 13 lines
+ layerconfparser = LayerConfParse(logger=logger,
bitbakepath=bitbakepath)layerindex/update.py +10
-0+ for branch in branches: + for layer in layerquery: + urldir = layer.get_fetch_dir() + repodir = os.path.join(fetchdir, urldir) + + layerbranch = layer.get_layerbranch(branch) + if layerbranch.vcs_subdir: + repodir = os.path.join(repodir, layerbranch.vcs_subdir) + config_data = layerconfparser.parse_layer(repodir) + utils.add_dependencies(layerbranch, config_data,logger=logger)
layerindex/update.py
Quoted 2 lines
layerindex/update.py +2
-0+ + layerconfparser.shutdown()
Use try..finally here as well.
Quoted 13 lines
layerindex/utils.py +4
-0@@ -27,6 +27,114 @@ def get_layer(layername): return res[0] return None +def get_dependency_layer(depname, version_str=None, logger=None): + from layerindex.models import LayerItem, LayerBranch + + # Get any LayerBranch with a layer that has a name that matches thedepname
layerindex/utils.py def get_layer(layername): · line 38
Quoted 5 lines
layerindex/utils.py +5
-0+ res = list(LayerBranch.objects.filter(layer__name=depname)) + + # Nothing found, return. + if len(res) == 0: + return None
This is more simply written as:
if res:
return None
Quoted 29 lines
layerindex/utils.py +10
-0+ + # If there is no version constraint, return the first one found. + if not version_str: + return res[0].layer + + (operator, dep_version) = version_str.split() + for layerbranch in res: + layer_ver = layerbranch.version + + # If there is no version in the found layer, then don't use thislayer.
layerindex/utils.py +5
-0+ if not layer_ver: + continue + + try: + success = bb.utils.vercmp_string_op(layer_ver, version_str,operator)
layerindex/utils.py +10
-0+ except bb.utils.VersionStringException as vse: + raise vse + + if success: + return layerbranch.layer + + return None + +def add_dependencies(layerbranch, config_data, logger=None): + _add_dependency("LAYERDEPENDS", 'dependency', layerbranch, config_data,logger)
layerindex/utils.py +1
-0+
layerindex/utils.py def get_layer(layername): · line 74
Quoted 10 lines
layerindex/utils.py +10
-0+def _add_dependency(var, name, layerbranch, config_data, logger=None): + from layerindex.models import LayerBranch, LayerDependency + + layer_name = layerbranch.layer.name + var_name = layer_name + + dep_list = config_data.getVar("%s_%s" % (var, var_name), True) + + if not dep_list: + return
Indenting is out here.
Cheers,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
PATCH 8/10 layerindex: Add collection and version to layerbranch
In reply to Liam R. HowlettCollection and version will be pulled from the layer.conf if it exists and dependencies will be resolved by first checking for layers with the dependency name and then checking for collections. It is necessary to shutdown tinfoil to avoid bitbake complaining about multiple instances.
--- layerindex/models.py | 2 ++ layerindex/tools/import_layer.py | 3 --- layerindex/update.py | 1 + layerindex/update_layer.py | 25 +++++++++++++++++++------ layerindex/utils.py | 16 ++++++++++++++-- 5 files changed, 36 insertions(+), 11 deletions(-)
layerindex/models.py +2 -0
@@ -130,6 +130,8 @@ class LayerItem(models.Model): class LayerBranch(models.Model): layer = models.ForeignKey(LayerItem) branch = models.ForeignKey(Branch) + collection = models.CharField('Layer Collection', max_length=40, unique=True, null=True, help_text='Name of the layer that could be used in the list of dependencies - must be unique and can only contain letters, numbers and dashes') + version = models.CharField('Layer Version', max_length=10, null=True, help_text='The layer version for this particular branch.') vcs_subdir = models.CharField('Repository subdirectory', max_length=40, blank=True, help_text='Subdirectory within the repository where the layer is located, if not in the root (usually only used if the repository contains more than one layer)') vcs_last_fetch = models.DateTimeField('Last successful fetch', blank=True, null=True) vcs_last_rev = models.CharField('Last revision fetched', max_length=80, blank=True)
layerindex/tools/import_layer.py +0 -3
@@ -383,9 +383,6 @@ def main(): layerdep.layerbranch = layerbranch layerdep.dependency = core_layer layerdep.save() - layerconfparser = LayerConfParse(logger=logger) - config_data = layerconfparser.parse_layer(layerdir) - layerconfparser.shutdown() utils.add_dependencies(layerbranch, config_data, logger=logger)
layerindex/update.py +1 -0
@@ -213,6 +213,7 @@ def main(): layerbranch = layer.get_layerbranch(branch) if layerbranch.vcs_subdir: repodir = os.path.join(repodir, layerbranch.vcs_subdir) + config_data = layerconfparser.parse_layer(repodir) utils.add_dependencies(layerbranch, config_data, logger=logger)
layerindex/update_layer.py +19 -6
@@ -196,16 +196,18 @@ def main(): except recipeparse.RecipeParseError as e: logger.error(str(e)) sys.exit(1) + config_data = bb.data.createCopy(tinfoil.config_data) + tinfoil.shutdown() # Clear the default value of SUMMARY so that we can use DESCRIPTION instead if it hasn't been set - tinfoil.config_data.setVar('SUMMARY', '') + config_data.setVar('SUMMARY', '') # Clear the default value of DESCRIPTION so that we can see where it's not set - tinfoil.config_data.setVar('DESCRIPTION', '') + config_data.setVar('DESCRIPTION', '') # Clear the default value of HOMEPAGE ('unknown') - tinfoil.config_data.setVar('HOMEPAGE', '') + config_data.setVar('HOMEPAGE', '') # Set a blank value for LICENSE so that it doesn't cause the parser to die (e.g. with meta-ti - # why won't they just fix that?!) - tinfoil.config_data.setVar('LICENSE', '') + config_data.setVar('LICENSE', '') try: with transaction.atomic():
@@ -244,7 +246,7 @@ def main(): layerbranch = LayerBranch() layerbranch.layer = layer layerbranch.branch = branch - layerbranch_source = layer.get_layerbranch('master') + if not layerbranch_source: layerbranch_source = layer.get_layerbranch(None) if layerbranch_source:
@@ -262,6 +264,9 @@ def main(): dep.layerbranch = layerbranch dep.save() + layerbranch_source = layer.get_layerbranch('master') + + if layerbranch.vcs_subdir and not options.nocheckout: # Find latest commit in subdirectory # A bit odd to do it this way but apparently there's no other way in the GitPython API
@@ -280,6 +285,14 @@ def main(): layerdir = os.path.join(repodir, layerbranch.vcs_subdir) layerdir_start = os.path.normpath(layerdir) + os.sep + + from layerconfparse import LayerConfParse + layerconfparser = LayerConfParse(logger=logger) + layer_config_data = layerconfparser.parse_layer(layerdir) + layerconfparser.shutdown() + utils.set_layerbranch_collection_version(layerbranch, layer_config_data, logger=logger) + layerbranch.save() + layerrecipes = Recipe.objects.filter(layerbranch=layerbranch) layermachines = Machine.objects.filter(layerbranch=layerbranch) layerdistributions = Distribution.objects.filter(layerbranch=layerbranch)
@@ -305,7 +318,7 @@ def main(): logger.info("Collecting data for layer %s on branch %s" % (layer.name, branchdesc)) try: - config_data_copy = recipeparse.setup_layer(tinfoil.config_data, fetchdir, layerdir, layer, layerbranch) + config_data_copy = recipeparse.setup_layer(config_data, fetchdir, layerdir, layer, layerbranch) except recipeparse.RecipeParseError as e: logger.error(str(e)) sys.exit(1)
layerindex/utils.py +14 -2
@@ -30,8 +30,10 @@ def get_layer(layername): def get_dependency_layer(depname, version_str=None, logger=None): from layerindex.models import LayerItem, LayerBranch - # Get any LayerBranch with a layer that has a name that matches the depname - res = list(LayerBranch.objects.filter(layer__name=depname)) + # Get any LayerBranch with a layer that has a name that matches depmod, or + # a LayerBranch that has the collection name depmod. + res = list(LayerBranch.objects.filter(layer__name=depname)) + \ + list(LayerBranch.objects.filter(collection=depname)) # Nothing found, return. if len(res) == 0:
@@ -104,11 +106,21 @@ def _add_dependency(var, name, layerbranch, config_data, logger=None): if logger: logger.debug('Adding %s %s to %s' % (name, dep_layer.name, layer_name)) + layerdep = LayerDependency() layerdep.layerbranch = layerbranch layerdep.dependency = dep_layer layerdep.save() +def set_layerbranch_collection_version(layerbranch, config_data, logger=None): + + layerbranch.collection = config_data.getVar('BBFILE_COLLECTIONS', True) + ver_str = "LAYERVERSION_" + if layerbranch.collection: + layerbranch.collection = layerbranch.collection.strip() + ver_str += layerbranch.collection + layerbranch.version = config_data.getVar(ver_str, True) + def setup_tinfoil(bitbakepath, enable_tracking): sys.path.insert(0, bitbakepath + '/lib') import bb.tinfoil
Signature · 1 line
1.9.1
Re: [layerindex-web][PATCH 08/10] layerindex: Add collection and version to layerbranch
Quoted 4 lines · Liam R. Howlett
Collection and version will be pulled from the layer.conf if it exists and dependencies will be resolved by first checking for layers with the dependency name and then checking for collections. It is necessary to shutdown tinfoil to avoid bitbake complaining about multiple instances.
I think I found a bug in this patch. The collection/version apparently needs to be 'unique' in the layerbranch.
So if you have two layerbranch entries, associated with different branches (say master and krogoth) you will get an error that they both have the same collection name.
(This happened when I tried to use the admin interface to set the values.)
I will look into a solution for this problem.
--Mark
Quoted 158 lines
Signed-off-by Liam R. Howlett <[email protected]>--- layerindex/models.py | 2 ++ layerindex/tools/import_layer.py | 3 --- layerindex/update.py | 1 + layerindex/update_layer.py | 25 +++++++++++++++++++------ layerindex/utils.py | 16 ++++++++++++++-- 5 files changed, 36 insertions(+), 11 deletions(-)layerindex/models.py +2
-0@@ -130,6 +130,8 @@ class LayerItem(models.Model): class LayerBranch(models.Model): layer = models.ForeignKey(LayerItem) branch = models.ForeignKey(Branch) + collection = models.CharField('Layer Collection', max_length=40, unique=True, null=True, help_text='Name of the layer that could be used in the list of dependencies - must be unique and can only contain letters, numbers and dashes') + version = models.CharField('Layer Version', max_length=10, null=True, help_text='The layer version for this particular branch.') vcs_subdir = models.CharField('Repository subdirectory', max_length=40, blank=True, help_text='Subdirectory within the repository where the layer is located, if not in the root (usually only used if the repository contains more than one layer)') vcs_last_fetch = models.DateTimeField('Last successful fetch', blank=True, null=True) vcs_last_rev = models.CharField('Last revision fetched', max_length=80, blank=True)layerindex/tools/import_layer.py +0
-3@@ -383,9 +383,6 @@ def main(): layerdep.layerbranch = layerbranch layerdep.dependency = core_layer layerdep.save() - layerconfparser = LayerConfParse(logger=logger) - config_data = layerconfparser.parse_layer(layerdir) - layerconfparser.shutdown() utils.add_dependencies(layerbranch, config_data, logger=logger)layerindex/update.py +1
-0@@ -213,6 +213,7 @@ def main(): layerbranch = layer.get_layerbranch(branch) if layerbranch.vcs_subdir: repodir = os.path.join(repodir, layerbranch.vcs_subdir) + config_data = layerconfparser.parse_layer(repodir) utils.add_dependencies(layerbranch, config_data, logger=logger)layerindex/update_layer.py +19
-6@@ -196,16 +196,18 @@ def main(): except recipeparse.RecipeParseError as e: logger.error(str(e)) sys.exit(1) + config_data = bb.data.createCopy(tinfoil.config_data) + tinfoil.shutdown() # Clear the default value of SUMMARY so that we can use DESCRIPTION instead if it hasn't been set - tinfoil.config_data.setVar('SUMMARY', '') + config_data.setVar('SUMMARY', '') # Clear the default value of DESCRIPTION so that we can see where it's not set - tinfoil.config_data.setVar('DESCRIPTION', '') + config_data.setVar('DESCRIPTION', '') # Clear the default value of HOMEPAGE ('unknown') - tinfoil.config_data.setVar('HOMEPAGE', '') + config_data.setVar('HOMEPAGE', '') # Set a blank value for LICENSE so that it doesn't cause the parser to die (e.g. with meta-ti - # why won't they just fix that?!) - tinfoil.config_data.setVar('LICENSE', '') + config_data.setVar('LICENSE', '') try: with transaction.atomic():@@ -244,7 +246,7 @@ def main(): layerbranch = LayerBranch() layerbranch.layer = layer layerbranch.branch = branch - layerbranch_source = layer.get_layerbranch('master') + if not layerbranch_source: layerbranch_source = layer.get_layerbranch(None) if layerbranch_source:@@ -262,6 +264,9 @@ def main(): dep.layerbranch = layerbranch dep.save() + layerbranch_source = layer.get_layerbranch('master') + + if layerbranch.vcs_subdir and not options.nocheckout: # Find latest commit in subdirectory # A bit odd to do it this way but apparently there's no other way in the GitPython API@@ -280,6 +285,14 @@ def main(): layerdir = os.path.join(repodir, layerbranch.vcs_subdir) layerdir_start = os.path.normpath(layerdir) + os.sep + + from layerconfparse import LayerConfParse + layerconfparser = LayerConfParse(logger=logger) + layer_config_data = layerconfparser.parse_layer(layerdir) + layerconfparser.shutdown() + utils.set_layerbranch_collection_version(layerbranch, layer_config_data, logger=logger) + layerbranch.save() + layerrecipes = Recipe.objects.filter(layerbranch=layerbranch) layermachines = Machine.objects.filter(layerbranch=layerbranch) layerdistributions = Distribution.objects.filter(layerbranch=layerbranch)@@ -305,7 +318,7 @@ def main(): logger.info("Collecting data for layer %s on branch %s" % (layer.name, branchdesc)) try: - config_data_copy = recipeparse.setup_layer(tinfoil.config_data, fetchdir, layerdir, layer, layerbranch) + config_data_copy = recipeparse.setup_layer(config_data, fetchdir, layerdir, layer, layerbranch) except recipeparse.RecipeParseError as e: logger.error(str(e)) sys.exit(1)layerindex/utils.py +14
-2@@ -30,8 +30,10 @@ def get_layer(layername): def get_dependency_layer(depname, version_str=None, logger=None): from layerindex.models import LayerItem, LayerBranch - # Get any LayerBranch with a layer that has a name that matches the depname - res = list(LayerBranch.objects.filter(layer__name=depname)) + # Get any LayerBranch with a layer that has a name that matches depmod, or + # a LayerBranch that has the collection name depmod. + res = list(LayerBranch.objects.filter(layer__name=depname)) + \ + list(LayerBranch.objects.filter(collection=depname)) # Nothing found, return. if len(res) == 0:@@ -104,11 +106,21 @@ def _add_dependency(var, name, layerbranch, config_data, logger=None): if logger: logger.debug('Adding %s %s to %s' % (name, dep_layer.name, layer_name)) + layerdep = LayerDependency() layerdep.layerbranch = layerbranch layerdep.dependency = dep_layer layerdep.save() +def set_layerbranch_collection_version(layerbranch, config_data, logger=None): + + layerbranch.collection = config_data.getVar('BBFILE_COLLECTIONS', True) + ver_str = "LAYERVERSION_" + if layerbranch.collection: + layerbranch.collection = layerbranch.collection.strip() + ver_str += layerbranch.collection + layerbranch.version = config_data.getVar(ver_str, True) + def setup_tinfoil(bitbakepath, enable_tracking): sys.path.insert(0, bitbakepath + '/lib') import bb.tinfoil
Re: [layerindex-web][PATCH 08/10] layerindex: Add collection and version to layerbranch
In reply to Liam R. HowlettQuoted 4 lines · On Mon, 26 Sep 2016 14:25:36 Liam R. Howlett wrote:
Collection and version will be pulled from the layer.conf if it exists and dependencies will be resolved by first checking for layers with the dependency name and then checking for collections. It is necessary to shutdown tinfoil to avoid bitbake complaining about multiple instances.
I'm not sure I understand why though, and there's not an explanation given here. What you're doing as a workaround only works by chance and I suspect it will break horribly when we do the tinfoil2 refactor in the next release (it's not expected that you'd have datastores still around and be parsing recipes when tinfoil has been shut down), so we *really* need to try to avoid shutting down like this. Can you explain what you saw?
Cheers,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
Re: [layerindex-web][PATCH 08/10] layerindex: Add collection and version to layerbranch
Quoted 6 lines · Paul Eggleton
Quoted 4 lines · On Mon, 26 Sep 2016 14:25:36 Liam R. Howlett wrote:
Collection and version will be pulled from the layer.conf if it exists and dependencies will be resolved by first checking for layers with the dependency name and then checking for collections. It is necessary to shutdown tinfoil to avoid bitbake complaining about multiple instances.
Quoted 6 lines
I'm not sure I understand why though, and there's not an explanation given here. What you're doing as a workaround only works by chance and I suspect it will break horribly when we do the tinfoil2 refactor in the next release (it's not expected that you'd have datastores still around and be parsing recipes when tinfoil has been shut down), so we *really* need to try to avoid shutting down like this. Can you explain what you saw?
I received messages about having multiple copies of bitbake running if I did not shut down tinfoil. I also hit too many files opened in the update.py loop. I have since reworked this patch to pass in the tinfoil instance to layerconfparser in this patch set. I was almost done v2 when I received your comments. I also noticed that I had shut down tinfoil before it should have been shut down - in v2, I had moved my shutdown call next to sys.exit(0). I feel much better about the way I handle this in v2.
Quoted 8 lines
Cheers,
PaulSignature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
PATCH 9/10 layerindexer: Add layer recommends support
In reply to Liam R. HowlettParse layer.conf and add dependencies that are not required from LAYERRECOMMENDS_<name>. Update the layerindex/template to support recommends. Uses bitbake parsing code & checks versions.
--- layerindex/models.py | 4 ++++ layerindex/tools/import_layer.py | 2 +- layerindex/update.py | 1 + layerindex/utils.py | 10 +++++++++- templates/layerindex/detail.html | 32 +++++++++++++++++++++----------- 5 files changed, 36 insertions(+), 13 deletions(-)
layerindex/models.py +4 -0
@@ -214,6 +214,10 @@ class LayerBranch(models.Model): def get_required(self): return self.dependencies_set.filter(required=True) + def get_recommends(self): + return self.dependencies_set.filter(required=False) + + class LayerMaintainer(models.Model): MAINTAINER_STATUS_CHOICES = ( ('A', 'Active'),
layerindex/tools/import_layer.py +1 -1
@@ -384,7 +384,7 @@ def main(): layerdep.dependency = core_layer layerdep.save() utils.add_dependencies(layerbranch, config_data, logger=logger) - + utils.add_recommends(layerbranch, config_data, logger=logger) # Get some extra meta-information readme_files = glob.glob(os.path.join(layerdir, 'README*'))
layerindex/update.py +1 -0
@@ -216,6 +216,7 @@ def main(): config_data = layerconfparser.parse_layer(repodir) utils.add_dependencies(layerbranch, config_data, logger=logger) + utils.add_recommends(layerbranch, config_data, logger=logger) layerconfparser.shutdown()
layerindex/utils.py +9 -1
@@ -64,16 +64,23 @@ def get_dependency_layer(depname, version_str=None, logger=None): def add_dependencies(layerbranch, config_data, logger=None): _add_dependency("LAYERDEPENDS", 'dependency', layerbranch, config_data, logger) +def add_recommends(layerbranch, config_data, logger=None): + _add_dependency("LAYERRECOMMENDS", 'recommends', layerbranch, config_data, logger) + def _add_dependency(var, name, layerbranch, config_data, logger=None): from layerindex.models import LayerBranch, LayerDependency layer_name = layerbranch.layer.name var_name = layer_name + if layerbranch.collection: + var_name = layerbranch.collection + + dep_list = config_data.getVar("%s_%s" % (var, var_name), True) if not dep_list: - return + return try: dep_dict = bb.utils.explode_dep_versions2(dep_list)
@@ -93,6 +100,7 @@ def _add_dependency(var, name, layerbranch, config_data, logger=None): logger.error('Error getting %s %s for %s\n%s' %(name, dep. layer_name, str(vse))) continue + # No layer found. if not dep_layer: if logger: logger.error('Cannot resolve %s %s (version %s) for %s' % (name, dep, ver_str, layer_name))
templates/layerindex/detail.html +21 -11
@@ -139,17 +139,27 @@ <div class="span4 pull-right description"> {% if layerbranch.dependencies_set.count > 0 %} - <div class="well dependency-well"> - <h3>Dependencies </h3> - <p>The {{ layeritem.name }} layer depends upon:</p> - <ul> - {% for dep in layerbranch.dependencies_set.all %} - <li><a href="{% url 'layer_item' url_branch dep.dependency.name %}">{{ dep.dependency.name }}</a></li> - {% endfor %} - </ul> - </div> <!-- end of well --> - {% endif %} - + <div class="well dependency-well"> + {% if layerbranch.get_required.count > 0 %} + <h3>Dependencies </h3> + <p>The {{ layeritem.name }} layer depends upon:</p> + <ul> + {% for dep in layerbranch.get_required %} + <li><a href="{% url 'layer_item' url_branch dep.dependency.name %}">{{ dep.dependency.name }}</a></li> + {% endfor %} + </ul> + {% endif %} <!-- end of layerbranch.get_required.count --> + {% if layerbranch.get_recommends.count > 0 %} + <h3>Recommends </h3> + <p>The {{ layeritem.name }} layer recommends:</p> + <ul> + {% for rec in layerbranch.get_recommends %} + <li><a href="{% url 'layer_item' url_branch rec.dependency.name %}">{{ rec.dependency.name }}</a></li> + {% endfor %} + </ul> + {% endif %} <!-- end of layerbranch.get_recommends.count --> + </div> <!-- end of well --> + {% endif %} <!-- end of layerbranch.dependencies_set.count --> </div> <!-- end of span4 --> </div> <!-- end of row-fluid --> </div> <!-- end of container-fluid -->
Signature · 1 line
1.9.1
PATCH 10/10 recipeparse: remove unnecessary else statement.
In reply to Liam R. HowlettCode clean up.
--- layerindex/recipeparse.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
layerindex/recipeparse.py +8 -9
@@ -142,15 +142,14 @@ def detect_file_type(path, subdir_start): if res: typename = 'machine' return (typename, None, res.group(1)) - else: - res = bbclass_re.match(subpath) - if res: - typename = 'bbclass' - return (typename, None, res.group(1)) - res = distro_conf_re.match(subpath) - if res: - typename = 'distribution' - return (typename, None, res.group(1)) + res = bbclass_re.match(subpath) + if res: + typename = 'bbclass' + return (typename, None, res.group(1)) + res = distro_conf_re.match(subpath) + if res: + typename = 'distribution' + return (typename, None, res.group(1)) if typename == 'recipe' or typename == 'bbappend': if subdir_start:
Signature · 1 line
1.9.1