From 975d2927d158ce52d03bc1f4464282b846826026 Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Wed, 13 Feb 2019 16:32:04 +1300 Subject: [PATCH] Record patch application order and use as default sorting Patches often need to be applied in a specific order. For OE recipes we were always storing the Patch objects correct order as they are refreshed every time the recipe itself is refreshed, however for other distro comparisons, import_otherdistro.py attempts to preserve existing records, adds new ones and then deletes whatever is left over, which may result in the order getting messed up over time. To avoid this issue, record the order next to the patch and set the model meta-info to use this to sort Patch queries by default. Signed-off-by: Paul Eggleton --- .../migrations/0027_patch_apply_order.py | 24 +++++++++++++++++++ layerindex/models.py | 2 ++ layerindex/tools/import_otherdistro.py | 5 ++-- layerindex/update_layer.py | 7 +++--- 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 layerindex/migrations/0027_patch_apply_order.py diff --git a/layerindex/migrations/0027_patch_apply_order.py b/layerindex/migrations/0027_patch_apply_order.py new file mode 100644 index 0000000..efd775c --- /dev/null +++ b/layerindex/migrations/0027_patch_apply_order.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.16 on 2019-02-13 02:42 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('layerindex', '0026_incfile'), + ] + + operations = [ + migrations.AddField( + model_name='patch', + name='apply_order', + field=models.IntegerField(blank=True, null=True), + ), + migrations.AlterModelOptions( + name='patch', + options={'ordering': ['recipe', 'apply_order'], 'verbose_name_plural': 'Patches'}, + ), + ] diff --git a/layerindex/models.py b/layerindex/models.py index f577df7..4c17c75 100644 --- a/layerindex/models.py +++ b/layerindex/models.py @@ -559,9 +559,11 @@ class Patch(models.Model): src_path = models.CharField(max_length=255) status = models.CharField(max_length=1, choices=PATCH_STATUS_CHOICES, default='U') status_extra = models.CharField(max_length=255, blank=True) + apply_order = models.IntegerField(blank=True, null=True) class Meta: verbose_name_plural = 'Patches' + ordering = ['recipe', 'apply_order'] def vcs_web_url(self): url = self.recipe.layerbranch.file_url(self.path) diff --git a/layerindex/tools/import_otherdistro.py b/layerindex/tools/import_otherdistro.py index 1b43bb2..fa41bfa 100755 --- a/layerindex/tools/import_otherdistro.py +++ b/layerindex/tools/import_otherdistro.py @@ -272,7 +272,7 @@ def update_recipe_file(path, recipe, repodir, raiseexceptions=False): elif key == 'license': recipe.license = expand(value) elif key.startswith('patch'): - patches.append(expand(value)) + patches.append((int(key[5:] or '0'), expand(value))) elif key.startswith('source'): sources.append(expand(value)) @@ -280,10 +280,11 @@ def update_recipe_file(path, recipe, repodir, raiseexceptions=False): recipe.save() saved_patches = [] - for patchfn in patches: + for index, patchfn in patches: patchpath = os.path.join(os.path.relpath(os.path.dirname(path), repodir), patchfn) patch, _ = Patch.objects.get_or_create(recipe=recipe, path=patchpath) patch.src_path = patchfn + patch.apply_order = index patch.save() saved_patches.append(patch.id) recipe.patch_set.exclude(id__in=saved_patches).delete() diff --git a/layerindex/update_layer.py b/layerindex/update_layer.py index 2fc9d82..7f3e922 100644 --- a/layerindex/update_layer.py +++ b/layerindex/update_layer.py @@ -56,7 +56,7 @@ def split_recipe_fn(path): pv = "1.0" return (pn, pv) -def collect_patch(recipe, patchfn, layerdir_start, stop_on_error): +def collect_patch(recipe, patchfn, index, layerdir_start, stop_on_error): from django.db import DatabaseError from layerindex.models import Patch @@ -64,6 +64,7 @@ def collect_patch(recipe, patchfn, layerdir_start, stop_on_error): patchrec.recipe = recipe patchrec.path = os.path.relpath(patchfn, layerdir_start) patchrec.src_path = os.path.relpath(patchrec.path, recipe.filepath) + patchrec.apply_order = index try: patchrec.read_status_from_file(patchfn, logger) patchrec.save() @@ -87,11 +88,11 @@ def collect_patches(recipe, envdata, layerdir_start, stop_on_error): Patch.objects.filter(recipe=recipe).delete() patches = oe.recipeutils.get_recipe_patches(envdata) - for patch in patches: + for i, patch in enumerate(patches): if not patch.startswith(layerdir_start): # Likely a remote patch, skip it continue - collect_patch(recipe, patch, layerdir_start, stop_on_error) + collect_patch(recipe, patch, i, layerdir_start, stop_on_error) def update_recipe_file(tinfoil, data, path, recipe, layerdir_start, repodir, stop_on_error, skip_patches=False): from django.db import DatabaseError