From ef627d0ab8f5cf2fc72005393e76047cb623ff3d Mon Sep 17 00:00:00 2001 From: Michael Wood Date: Thu, 21 Jul 2016 14:43:27 +0100 Subject: bitbake: toaster: Replace references to LayerSource models Replace references to the now deprecated layersource models across Toaster with the new enums for layer source types. (Bitbake rev: 48c09c62eb979d840132e58144f0d81ffee675b1) Signed-off-by: Michael Wood Signed-off-by: Elliot Smith Signed-off-by: Richard Purdie --- bitbake/lib/toaster/bldcontrol/tests.py | 19 -------- bitbake/lib/toaster/orm/models.py | 8 ++++ .../tests/browser/test_layerdetails_page.py | 3 -- bitbake/lib/toaster/toastergui/api.py | 6 +-- .../toaster/toastergui/static/js/layerdetails.js | 2 +- .../toaster/toastergui/templates/layerdetails.html | 16 +++---- bitbake/lib/toaster/toastergui/views.py | 56 +++++++++++++++------- 7 files changed, 57 insertions(+), 53 deletions(-) (limited to 'bitbake/lib/toaster') diff --git a/bitbake/lib/toaster/bldcontrol/tests.py b/bitbake/lib/toaster/bldcontrol/tests.py index 32985c3280..475ac0a16f 100644 --- a/bitbake/lib/toaster/bldcontrol/tests.py +++ b/bitbake/lib/toaster/bldcontrol/tests.py @@ -139,22 +139,3 @@ class RunBuildsCommandTests(TestCase): self.assertTrue(br.state == BuildRequest.REQ_INPROGRESS, "Request is not updated") # no more selections possible here self.assertRaises(IndexError, command._selectBuildRequest) - - -class UtilityTests(TestCase): - def test_reduce_path(self): - from bldcontrol.management.commands.loadconf import _reduce_canon_path, _get_id_for_sourcetype - - self.assertTrue( _reduce_canon_path("/") == "/") - self.assertTrue( _reduce_canon_path("/home/..") == "/") - self.assertTrue( _reduce_canon_path("/home/../ana") == "/ana") - self.assertTrue( _reduce_canon_path("/home/../ana/..") == "/") - self.assertTrue( _reduce_canon_path("/home/ana/mihai/../maria") == "/home/ana/maria") - - def test_get_id_for_sorucetype(self): - from bldcontrol.management.commands.loadconf import _reduce_canon_path, _get_id_for_sourcetype - self.assertTrue( _get_id_for_sourcetype("layerindex") == 1) - self.assertTrue( _get_id_for_sourcetype("local") == 0) - self.assertTrue( _get_id_for_sourcetype("imported") == 2) - with self.assertRaises(Exception): - _get_id_for_sourcetype("unknown") diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index 1daec9c25a..34ea28c270 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py @@ -1287,6 +1287,14 @@ class LayerSource(object): (TYPE_BUILD, "build"), ) + def types_dict(): + """ Turn the TYPES enums into a simple dictionary """ + dictionary = {} + for key in LayerSource.__dict__: + if "TYPE" in key: + dictionary[key] = getattr(LayerSource, key) + return dictionary + class Layer(models.Model): diff --git a/bitbake/lib/toaster/tests/browser/test_layerdetails_page.py b/bitbake/lib/toaster/tests/browser/test_layerdetails_page.py index fb1007f289..71c5c12d18 100644 --- a/bitbake/lib/toaster/tests/browser/test_layerdetails_page.py +++ b/bitbake/lib/toaster/tests/browser/test_layerdetails_page.py @@ -49,9 +49,6 @@ class TestLayerDetailsPage(SeleniumTestCase): # project to add new custom images to self.project = Project.objects.create(name='foo', release=release) - layer_source = LayerSource.objects.create( - sourcetype=LayerSource.TYPE_IMPORTED) - name = "meta-imported" vcs_url = "git://example.com/meta-imported" subdir = "/layer" diff --git a/bitbake/lib/toaster/toastergui/api.py b/bitbake/lib/toaster/toastergui/api.py index 112ce58914..414afce1d0 100644 --- a/bitbake/lib/toaster/toastergui/api.py +++ b/bitbake/lib/toaster/toastergui/api.py @@ -147,7 +147,7 @@ class XhrLayer(View): layer_version = Layer_Version.objects.get( id=kwargs['layerversion_id'], project=kwargs['pid'], - layer_source__sourcetype=LayerSource.TYPE_IMPORTED) + layer_source=LayerSource.TYPE_IMPORTED) except Layer_Version.DoesNotExist: return error_response("Cannot find imported layer to update") @@ -159,8 +159,6 @@ class XhrLayer(View): if "commit" in request.POST: layer_version.commit = request.POST["commit"] layer_version.branch = request.POST["commit"] - if "up_branch" in request.POST: - layer_version.up_branch_id = int(request.POST["up_branch"]) if "summary" in request.POST: layer_version.layer.summary = request.POST["summary"] if "description" in request.POST: @@ -193,7 +191,7 @@ class XhrLayer(View): layer_version = Layer_Version.objects.get( id=kwargs['layerversion_id'], project=kwargs['pid'], - layer_source__sourcetype=LayerSource.TYPE_IMPORTED) + layer_source=LayerSource.TYPE_IMPORTED) except Layer_Version.DoesNotExist: return error_response("Cannot find imported layer to delete") diff --git a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js index 683486e53b..0d4240b354 100644 --- a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js +++ b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js @@ -366,7 +366,7 @@ function layerDetailsPageInit (ctx) { if ($(this).is("dt")) { var dd = $(this).next("dd"); if (!dd.children("form:visible")|| !dd.find(".current-value").html()){ - if (ctx.layerVersion.sourceId == 3){ + if (ctx.layerVersion.layer_source == ctx.layerSourceTypes.TYPE_IMPORTED){ /* There's no current value and the layer is editable * so show the "Not set" and hide the delete icon */ diff --git a/bitbake/lib/toaster/toastergui/templates/layerdetails.html b/bitbake/lib/toaster/toastergui/templates/layerdetails.html index 4b51d1a39c..029c93b978 100644 --- a/bitbake/lib/toaster/toastergui/templates/layerdetails.html +++ b/bitbake/lib/toaster/toastergui/templates/layerdetails.html @@ -36,7 +36,7 @@ {# If this is not an imported layer then hide the edit ui #} - {% if not layerversion.layer_source_id or layerversion.layer_source.sourcetype != layerversion.layer_source.TYPE_IMPORTED %} + {% if layerversion.layer_source != layer_source.TYPE_IMPORTED %}