Move repo subdirectory to layerbranch

So it turns out that one or two layers have changed in structure between
branches, so we need to be able to specify this on a per-branch basis.
Good times...

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2013-03-19 22:35:46 +00:00
parent ee9176a8c5
commit 0a1215e59e
6 changed files with 40 additions and 19 deletions

View File

@ -46,12 +46,13 @@ LayerMaintainerFormSet = inlineformset_factory(LayerBranch, LayerMaintainer, for
class EditLayerForm(forms.ModelForm): class EditLayerForm(forms.ModelForm):
# Additional form fields # 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) 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'}) captcha = CaptchaField(label='Verification', help_text='Please enter the letters displayed for verification purposes', error_messages={'invalid':'Incorrect entry, please try again'})
class Meta: class Meta:
model = LayerItem 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): def __init__(self, user, layerbranch, *args, **kwargs):
super(self.__class__, self).__init__(*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')] self.fields['deps'].initial = [l.pk for l in LayerItem.objects.filter(name='openembedded-core')]
if user.is_authenticated(): if user.is_authenticated():
del self.fields['captcha'] 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 self.was_saved = False
def checked_deps(self): def checked_deps(self):

View File

@ -41,7 +41,6 @@ class LayerItem(models.Model):
layer_type = models.CharField(max_length=1, choices=LAYER_TYPE_CHOICES) 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') summary = models.CharField(max_length=200, help_text='One-line description of the layer')
description = models.TextField() 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_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_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') 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): class LayerBranch(models.Model):
layer = models.ForeignKey(LayerItem) layer = models.ForeignKey(LayerItem)
branch = models.ForeignKey(Branch) 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_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_rev = models.CharField('Last revision fetched', max_length=80, blank=True)
vcs_last_commit = models.DateTimeField('Last commit date', blank=True, null=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): def _handle_url_path(self, base_url, path):
if base_url: if base_url:
if self.layer.vcs_subdir: if self.vcs_subdir:
extra_path = self.layer.vcs_subdir + '/' + path extra_path = self.vcs_subdir + '/' + path
else: else:
extra_path = path extra_path = path
url = base_url.replace('%branch%', self.branch.name) url = base_url.replace('%branch%', self.branch.name)

View File

@ -263,9 +263,14 @@ def main():
if not core_layer: if not core_layer:
logger.error("Unable to find core layer %s in database; check CORE_LAYER_NAME setting" % settings.CORE_LAYER_NAME) logger.error("Unable to find core layer %s in database; check CORE_LAYER_NAME setting" % settings.CORE_LAYER_NAME)
sys.exit(1) 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_urldir = sanitise_path(core_layer.vcs_url)
core_repodir = os.path.join(fetchdir, core_urldir) 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 checkout origin/%s" % options.branch, core_repodir)
out = runcmd("git clean -f -x", core_repodir) out = runcmd("git clean -f -x", core_repodir)
# The directory above where this script exists should contain our conf/layer.conf, # The directory above where this script exists should contain our conf/layer.conf,
@ -319,22 +324,25 @@ def main():
transaction.rollback() transaction.rollback()
continue 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) layerbranch = layer.get_layerbranch(options.branch)
if not layerbranch: if not layerbranch:
# LayerBranch doesn't exist for this branch, create it # LayerBranch doesn't exist for this branch, create it
layerbranch = LayerBranch() layerbranch = LayerBranch()
layerbranch.layer = layer layerbranch.layer = layer
layerbranch.branch = branch layerbranch.branch = branch
layerbranch_master = layer.get_layerbranch('master')
if layerbranch_master:
layerbranch.vcs_subdir = layerbranch_master.vcs_subdir
layerbranch.save() 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 layerdir_start = os.path.normpath(layerdir) + os.sep
layerrecipes = Recipe.objects.filter(layerbranch=layerbranch) layerrecipes = Recipe.objects.filter(layerbranch=layerbranch)
layermachines = Machine.objects.filter(layerbranch=layerbranch) layermachines = Machine.objects.filter(layerbranch=layerbranch)
@ -365,7 +373,12 @@ def main():
for dep in layerbranch.dependencies_set.all(): for dep in layerbranch.dependencies_set.all():
depurldir = sanitise_path(dep.dependency.vcs_url) depurldir = sanitise_path(dep.dependency.vcs_url)
deprepodir = os.path.join(fetchdir, depurldir) 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) parse_layer_conf(deplayerdir, config_data_copy)
config_data_copy.delVar('LAYERDIR') config_data_copy.delVar('LAYERDIR')
@ -381,8 +394,8 @@ def main():
if diff: if diff:
# Apply git changes to existing recipe list # Apply git changes to existing recipe list
if layer.vcs_subdir: if layerbranch.vcs_subdir:
subdir_start = os.path.normpath(layer.vcs_subdir) + os.sep subdir_start = os.path.normpath(layerbranch.vcs_subdir) + os.sep
else: else:
subdir_start = "" subdir_start = ""

View File

@ -99,6 +99,7 @@ def edit_layer_view(request, template_name, slug=None):
with transaction.commit_on_success(): with transaction.commit_on_success():
form.save() form.save()
layerbranch.layer = layeritem layerbranch.layer = layeritem
layerbranch.vcs_subdir = form.cleaned_data['vcs_subdir']
layerbranch.save() layerbranch.save()
maintainerformset.save() maintainerformset.save()
if slug: if slug:

View File

@ -95,9 +95,9 @@
{% endif %} {% endif %}
</p> </p>
{% if layeritem.vcs_subdir %} {% if layerbranch.vcs_subdir %}
<h4>Subdirectory</h4> <h4>Subdirectory</h4>
<p><span data-toggle="tooltip" title="Select subdirectory"><i class="icon-circle-arrow-right selectallicon" for="vcs_subdir" id="vcs_subdir_select"></i></span><span id="vcs_subdir" class="copyable">{{ layeritem.vcs_subdir }}</span> <p><span data-toggle="tooltip" title="Select subdirectory"><i class="icon-circle-arrow-right selectallicon" for="vcs_subdir" id="vcs_subdir_select"></i></span><span id="vcs_subdir" class="copyable">{{ layerbranch.vcs_subdir }}</span>
{% if layerbranch.tree_url %} {% if layerbranch.tree_url %}
<span class="label label-info"> <span class="label label-info">
<a href="{{ layerbranch.tree_url }}">web subdirectory</a> <a href="{{ layerbranch.tree_url }}">web subdirectory</a>

View File

@ -100,7 +100,7 @@
</tr> </tr>
<tr> <tr>
<th>Repository subdirectory</th> <th>Repository subdirectory</th>
<td>{{ layeritem.vcs_subdir }}</td> <td>{{ layerbranch.vcs_subdir }}</td>
</tr> </tr>
<tr> <tr>
<th>Repo web interface</th> <th>Repo web interface</th>