diff --git a/layerindex/forms.py b/layerindex/forms.py index 4eb9434..dd6ebf1 100644 --- a/layerindex/forms.py +++ b/layerindex/forms.py @@ -46,12 +46,13 @@ LayerMaintainerFormSet = inlineformset_factory(LayerBranch, LayerMaintainer, for class EditLayerForm(forms.ModelForm): # Additional form fields + vcs_subdir = forms.CharField(label='Repository subdirectory', max_length=40, required=False, 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)') deps = forms.ModelMultipleChoiceField(label='Other layers this layer depends upon', queryset=LayerItem.objects.all(), required=False) captcha = CaptchaField(label='Verification', help_text='Please enter the letters displayed for verification purposes', error_messages={'invalid':'Incorrect entry, please try again'}) class Meta: model = LayerItem - fields = ('name', 'layer_type', 'summary', 'description', 'vcs_url', 'vcs_subdir', 'vcs_web_url', 'vcs_web_tree_base_url', 'vcs_web_file_base_url', 'usage_url', 'mailing_list_url') + fields = ('name', 'layer_type', 'summary', 'description', 'vcs_url', 'vcs_web_url', 'vcs_web_tree_base_url', 'vcs_web_file_base_url', 'usage_url', 'mailing_list_url') def __init__(self, user, layerbranch, *args, **kwargs): super(self.__class__, self).__init__(*args, **kwargs) @@ -63,6 +64,12 @@ class EditLayerForm(forms.ModelForm): self.fields['deps'].initial = [l.pk for l in LayerItem.objects.filter(name='openembedded-core')] if user.is_authenticated(): del self.fields['captcha'] + # Ensure repo subdir appears after repo URL + field_order = self.fields.keyOrder + field_order.pop(field_order.index('vcs_subdir')) + name_pos = field_order.index('vcs_url') + 1 + field_order.insert(name_pos, 'vcs_subdir') + self.fields['vcs_subdir'].initial = layerbranch.vcs_subdir self.was_saved = False def checked_deps(self): diff --git a/layerindex/models.py b/layerindex/models.py index 35febf1..4fd0855 100644 --- a/layerindex/models.py +++ b/layerindex/models.py @@ -41,7 +41,6 @@ class LayerItem(models.Model): layer_type = models.CharField(max_length=1, choices=LAYER_TYPE_CHOICES) summary = models.CharField(max_length=200, help_text='One-line description of the layer') description = models.TextField() - 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_url = models.CharField('Repository URL', max_length=200, help_text='Fetch/clone URL of the repository') vcs_web_url = models.URLField('Repository web interface URL', blank=True, help_text='URL of the web interface for browsing the repository, if any') vcs_web_tree_base_url = models.CharField('Repository web interface tree base URL', max_length=200, blank=True, help_text='Base URL for the web interface for browsing directories within the repository, if any') @@ -91,6 +90,7 @@ class LayerItem(models.Model): class LayerBranch(models.Model): layer = models.ForeignKey(LayerItem) branch = models.ForeignKey(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) vcs_last_commit = models.DateTimeField('Last commit date', blank=True, null=True) @@ -106,8 +106,8 @@ class LayerBranch(models.Model): def _handle_url_path(self, base_url, path): if base_url: - if self.layer.vcs_subdir: - extra_path = self.layer.vcs_subdir + '/' + path + if self.vcs_subdir: + extra_path = self.vcs_subdir + '/' + path else: extra_path = path url = base_url.replace('%branch%', self.branch.name) diff --git a/layerindex/update.py b/layerindex/update.py index f4bda98..7f1e91f 100755 --- a/layerindex/update.py +++ b/layerindex/update.py @@ -263,9 +263,14 @@ def main(): if not core_layer: logger.error("Unable to find core layer %s in database; check CORE_LAYER_NAME setting" % settings.CORE_LAYER_NAME) sys.exit(1) + core_layerbranch = core_layer.get_layerbranch(options.branch) + if core_layerbranch: + core_subdir = core_layerbranch.vcs_subdir + else: + core_subdir = 'meta' core_urldir = sanitise_path(core_layer.vcs_url) core_repodir = os.path.join(fetchdir, core_urldir) - core_layerdir = os.path.join(core_repodir, core_layer.vcs_subdir) + core_layerdir = os.path.join(core_repodir, core_subdir) out = runcmd("git checkout origin/%s" % options.branch, core_repodir) out = runcmd("git clean -f -x", core_repodir) # The directory above where this script exists should contain our conf/layer.conf, @@ -319,22 +324,25 @@ def main(): transaction.rollback() continue - if layer.vcs_subdir: - # Find latest commit in subdirectory - # A bit odd to do it this way but apparently there's no other way in the GitPython API - for commit in repo.iter_commits('origin/%s' % options.branch, paths=layer.vcs_subdir): - topcommit = commit - break - layerbranch = layer.get_layerbranch(options.branch) if not layerbranch: # LayerBranch doesn't exist for this branch, create it layerbranch = LayerBranch() layerbranch.layer = layer layerbranch.branch = branch + layerbranch_master = layer.get_layerbranch('master') + if layerbranch_master: + layerbranch.vcs_subdir = layerbranch_master.vcs_subdir layerbranch.save() - layerdir = os.path.join(repodir, layer.vcs_subdir) + if layerbranch.vcs_subdir: + # Find latest commit in subdirectory + # A bit odd to do it this way but apparently there's no other way in the GitPython API + for commit in repo.iter_commits('origin/%s' % options.branch, paths=layerbranch.vcs_subdir): + topcommit = commit + break + + layerdir = os.path.join(repodir, layerbranch.vcs_subdir) layerdir_start = os.path.normpath(layerdir) + os.sep layerrecipes = Recipe.objects.filter(layerbranch=layerbranch) layermachines = Machine.objects.filter(layerbranch=layerbranch) @@ -365,7 +373,12 @@ def main(): for dep in layerbranch.dependencies_set.all(): depurldir = sanitise_path(dep.dependency.vcs_url) deprepodir = os.path.join(fetchdir, depurldir) - deplayerdir = os.path.join(deprepodir, dep.dependency.vcs_subdir) + deplayerbranch = dep.dependency.get_layerbranch(options.branch) + if not deplayerbranch: + logger.error('Dependency %s of layer %s does not have branch record for branch %s' % (dep.dependency.name, layer.name, options.branch)) + transaction.rollback() + continue + deplayerdir = os.path.join(deprepodir, deplayerbranch.vcs_subdir) parse_layer_conf(deplayerdir, config_data_copy) config_data_copy.delVar('LAYERDIR') @@ -381,8 +394,8 @@ def main(): if diff: # Apply git changes to existing recipe list - if layer.vcs_subdir: - subdir_start = os.path.normpath(layer.vcs_subdir) + os.sep + if layerbranch.vcs_subdir: + subdir_start = os.path.normpath(layerbranch.vcs_subdir) + os.sep else: subdir_start = "" diff --git a/layerindex/views.py b/layerindex/views.py index 64523c3..121046a 100644 --- a/layerindex/views.py +++ b/layerindex/views.py @@ -99,6 +99,7 @@ def edit_layer_view(request, template_name, slug=None): with transaction.commit_on_success(): form.save() layerbranch.layer = layeritem + layerbranch.vcs_subdir = form.cleaned_data['vcs_subdir'] layerbranch.save() maintainerformset.save() if slug: diff --git a/templates/layerindex/detail.html b/templates/layerindex/detail.html index 6cd69e6..2df242f 100644 --- a/templates/layerindex/detail.html +++ b/templates/layerindex/detail.html @@ -95,9 +95,9 @@ {% endif %}

- {% if layeritem.vcs_subdir %} + {% if layerbranch.vcs_subdir %}

Subdirectory

-

{{ layeritem.vcs_subdir }} +

{{ layerbranch.vcs_subdir }} {% if layerbranch.tree_url %} web subdirectory diff --git a/templates/layerindex/reviewdetail.html b/templates/layerindex/reviewdetail.html index 933ed1e..7a4cd4d 100644 --- a/templates/layerindex/reviewdetail.html +++ b/templates/layerindex/reviewdetail.html @@ -100,7 +100,7 @@ Repository subdirectory - {{ layeritem.vcs_subdir }} + {{ layerbranch.vcs_subdir }} Repo web interface