diff options
author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2014-12-03 13:55:19 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-12-18 10:24:07 +0000 |
commit | 13141af70813d84b27e41d7a6e5792c748b3ae90 (patch) | |
tree | c877f075d80f586b60bb862b84bab3fd06085a14 /bitbake/lib/toaster | |
parent | 7d5cd68a7d043b9db475099c86b8b4eb6bc1c1b2 (diff) | |
download | poky-13141af70813d84b27e41d7a6e5792c748b3ae90.tar.gz |
bitbake: toasterui: refactor project layer finding logic
This is a basic refactoring of the code computing
the layer equivalence classes for a project, in order to
bring common bits of logic in a single place.
(Bitbake rev: 9bdd0a687ba74577f2c0f0b6c696433ea662d38f)
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster')
-rw-r--r-- | bitbake/lib/toaster/orm/models.py | 21 | ||||
-rwxr-xr-x | bitbake/lib/toaster/toastergui/views.py | 49 |
2 files changed, 38 insertions, 32 deletions
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py index f5c600ba9f..46b704c130 100644 --- a/bitbake/lib/toaster/orm/models.py +++ b/bitbake/lib/toaster/orm/models.py | |||
@@ -20,7 +20,7 @@ | |||
20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
21 | 21 | ||
22 | from django.db import models | 22 | from django.db import models |
23 | from django.db.models import F | 23 | from django.db.models import F, Q |
24 | from django.utils import timezone | 24 | from django.utils import timezone |
25 | 25 | ||
26 | 26 | ||
@@ -98,6 +98,25 @@ class Project(models.Model): | |||
98 | def __unicode__(self): | 98 | def __unicode__(self): |
99 | return "%s (%s, %s)" % (self.name, self.release, self.bitbake_version) | 99 | return "%s (%s, %s)" % (self.name, self.release, self.bitbake_version) |
100 | 100 | ||
101 | # returns a queryset of compatible layers for a project | ||
102 | def compatible_layerversions(self, release = None, layer_name = None): | ||
103 | if release == None: | ||
104 | release = self.release | ||
105 | # layers on the same branch or layers specifically set for this project | ||
106 | queryset = Layer_Version.objects.filter((Q(up_branch__name = release.branch_name) & Q(project = None)) | Q(project = self)) | ||
107 | if layer_name is not None: | ||
108 | # we select only a layer name | ||
109 | queryset = queryset.filter(layer__name = layer_name) | ||
110 | |||
111 | # order by layer version priority | ||
112 | queryset = queryset.filter(layer_source__releaselayersourcepriority__release = release).order_by("-layer_source__releaselayersourcepriority__priority") | ||
113 | |||
114 | return queryset | ||
115 | |||
116 | # returns a set of layer-equivalent set of layers already in project | ||
117 | def projectlayer_equivalent_set(self): | ||
118 | return [j for i in [x.layercommit.get_equivalents_wpriority(self) for x in self.projectlayer_set.all()] for j in i] | ||
119 | |||
101 | def schedule_build(self): | 120 | def schedule_build(self): |
102 | from bldcontrol.models import BuildRequest, BRTarget, BRLayer, BRVariable, BRBitbake | 121 | from bldcontrol.models import BuildRequest, BRTarget, BRLayer, BRVariable, BRBitbake |
103 | br = BuildRequest.objects.create(project = self) | 122 | br = BuildRequest.objects.create(project = self) |
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 736de784a3..434e1180b0 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py | |||
@@ -1957,20 +1957,6 @@ if toastermain.settings.MANAGED: | |||
1957 | 1957 | ||
1958 | raise Exception("Invalid HTTP method for this page") | 1958 | raise Exception("Invalid HTTP method for this page") |
1959 | 1959 | ||
1960 | # returns a queryset of compatible layers for a project | ||
1961 | def _compatible_layerversions_for_project(prj, release = None, layer_name = None): | ||
1962 | if release == None: | ||
1963 | release = prj.release | ||
1964 | # layers on the same branch or layers specifically set for this project | ||
1965 | return Layer_Version.objects.filter((Q(up_branch__name = release.branch_name) & Q(project = None)) | Q(project = prj)) | ||
1966 | |||
1967 | |||
1968 | # returns the equivalence group for all the layers currently set in the project | ||
1969 | def _project_equivalent_layerversions(prj): | ||
1970 | return reduce(lambda x, y: list(x) + list(y), | ||
1971 | # take all equivalent layers for each entry | ||
1972 | map(lambda x: x.layercommit.get_equivalents_wpriority(prj), prj.projectlayer_set.all()) , []) | ||
1973 | |||
1974 | # returns a list for most recent builds; for use in the Project page, xhr_ updates, and other places, as needed | 1960 | # returns a list for most recent builds; for use in the Project page, xhr_ updates, and other places, as needed |
1975 | def _project_recent_build_list(prj): | 1961 | def _project_recent_build_list(prj): |
1976 | return map(lambda x: { | 1962 | return map(lambda x: { |
@@ -2137,7 +2123,7 @@ if toastermain.settings.MANAGED: | |||
2137 | for i in prj.projectlayer_set.all(): | 2123 | for i in prj.projectlayer_set.all(): |
2138 | # find and add a similarly-named layer on the new branch | 2124 | # find and add a similarly-named layer on the new branch |
2139 | try: | 2125 | try: |
2140 | lv = _compatible_layerversions_for_project(prj).filter(layer__name = i.layer.name).get_equivalents_wpriority(prj)[0] | 2126 | lv = prj.compatible_layerversions(layer_name = i.layercommit.layer.name)[0] |
2141 | ProjectLayer.objects.get_or_create(project = prj, layercommit = lv) | 2127 | ProjectLayer.objects.get_or_create(project = prj, layercommit = lv) |
2142 | except IndexError: | 2128 | except IndexError: |
2143 | pass | 2129 | pass |
@@ -2185,24 +2171,25 @@ if toastermain.settings.MANAGED: | |||
2185 | 2171 | ||
2186 | # returns layers for current project release that are not in the project set, matching the name | 2172 | # returns layers for current project release that are not in the project set, matching the name |
2187 | if request.GET['type'] == "layers": | 2173 | if request.GET['type'] == "layers": |
2188 | queryset_all = _compatible_layerversions_for_project(prj).filter(layer__name__icontains=request.GET.get('value','')) | 2174 | # all layers for the current project |
2175 | queryset_all = prj.compatible_layerversions().filter(layer__name__icontains=request.GET.get('value','')) | ||
2189 | 2176 | ||
2190 | queryset_all = queryset_all.exclude(pk__in = [x.id for x in _project_equivalent_layerversions(prj)]) | 2177 | # but not layers with equivalent layers already in project |
2178 | queryset_all = queryset_all.exclude(pk__in = [x.id for x in prj.projectlayer_equivalent_set()])[:8] | ||
2191 | 2179 | ||
2192 | queryset_all = set([x.get_equivalents_wpriority(prj)[0] for x in queryset_all[:8]]) | 2180 | # and show only the selected layers for this project |
2181 | final_list = set([x.get_equivalents_wpriority(prj)[0] for x in queryset_all]) | ||
2193 | 2182 | ||
2194 | return HttpResponse(jsonfilter( { "error":"ok", "list" : map( _lv_to_dict, queryset_all) }), content_type = "application/json") | 2183 | return HttpResponse(jsonfilter( { "error":"ok", "list" : map( _lv_to_dict, final_list) }), content_type = "application/json") |
2195 | 2184 | ||
2196 | 2185 | ||
2197 | # returns layer dependencies for a layer, excluding current project layers | 2186 | # returns layer dependencies for a layer, excluding current project layers |
2198 | if request.GET['type'] == "layerdeps": | 2187 | if request.GET['type'] == "layerdeps": |
2199 | queryset_all = LayerVersionDependency.objects.filter(layer_version_id = request.GET['value']) | 2188 | queryset = prj.compatible_layerversions().exclude(pk__in = [x.id for x in prj.projectlayer_equivalent_set()]).filter( |
2200 | queryset_all = queryset_all.exclude(depends_on__in = _project_equivalent_layerversions(prj)) | 2189 | layer__name__in = [ x.depends_on.layer.name for x in LayerVersionDependency.objects.filter(layer_version_id = request.GET['value'])]) |
2201 | queryset_all.order_by("-up_id"); | 2190 | |
2191 | return HttpResponse(jsonfilter( { "error":"ok", "list" : map( _lv_to_dict, queryset) }), content_type = "application/json") | ||
2202 | 2192 | ||
2203 | return HttpResponse(jsonfilter( { "error":"ok", | ||
2204 | "list" : map( _lv_to_dict, map(lambda x: x.depends_on.get_equivalents_wpriority(prj)[0], queryset_all)) | ||
2205 | }), content_type = "application/json") | ||
2206 | 2193 | ||
2207 | 2194 | ||
2208 | # returns layer versions that would be deleted on the new release__pk | 2195 | # returns layer versions that would be deleted on the new release__pk |
@@ -2212,7 +2199,7 @@ if toastermain.settings.MANAGED: | |||
2212 | 2199 | ||
2213 | retval = [] | 2200 | retval = [] |
2214 | for i in prj.projectlayer_set.all(): | 2201 | for i in prj.projectlayer_set.all(): |
2215 | lv = _compatible_layerversions_for_project(prj, release = Release.objects.get(pk=request.GET['value'])) | 2202 | lv = prj.compatible_layerversions(release = Release.objects.get(pk=request.GET['value'])).filter(layer__name = i.layercommit.layer.name) |
2216 | # there is no layer_version with the new release id, and the same name | 2203 | # there is no layer_version with the new release id, and the same name |
2217 | if lv.count() < 1: | 2204 | if lv.count() < 1: |
2218 | retval.append(i) | 2205 | retval.append(i) |
@@ -2225,7 +2212,7 @@ if toastermain.settings.MANAGED: | |||
2225 | # returns targets provided by current project layers | 2212 | # returns targets provided by current project layers |
2226 | if request.GET['type'] == "targets": | 2213 | if request.GET['type'] == "targets": |
2227 | queryset_all = Recipe.objects.all() | 2214 | queryset_all = Recipe.objects.all() |
2228 | queryset_all = queryset_all.filter(layer_version__in = reduce(lambda x, y: list(x) + list(y), map(lambda x: x.layercommit.get_equivalents_wpriority(prj), prj.projectlayer_set.all()), [])) | 2215 | queryset_all = queryset_all.filter(layer_version__in = prj.projectlayer_equivalent_set()) |
2229 | return HttpResponse(jsonfilter({ "error":"ok", | 2216 | return HttpResponse(jsonfilter({ "error":"ok", |
2230 | "list" : map ( lambda x: {"id": x.pk, "name": x.name, "detail":"[" + x.layer_version.layer.name+ (" | " + x.layer_version.up_branch.name + "]" if x.layer_version.up_branch is not None else "]")}, | 2217 | "list" : map ( lambda x: {"id": x.pk, "name": x.name, "detail":"[" + x.layer_version.layer.name+ (" | " + x.layer_version.up_branch.name + "]" if x.layer_version.up_branch is not None else "]")}, |
2231 | queryset_all.filter(name__icontains=request.GET.get('value',''))[:8]), | 2218 | queryset_all.filter(name__icontains=request.GET.get('value',''))[:8]), |
@@ -2235,7 +2222,8 @@ if toastermain.settings.MANAGED: | |||
2235 | if request.GET['type'] == "machines": | 2222 | if request.GET['type'] == "machines": |
2236 | queryset_all = Machine.objects.all() | 2223 | queryset_all = Machine.objects.all() |
2237 | if 'project_id' in request.session: | 2224 | if 'project_id' in request.session: |
2238 | queryset_all = queryset_all.filter(layer_version__layer__in = map(lambda x: x.layercommit.layer, ProjectLayer.objects.filter(project_id=request.session['project_id']))) | 2225 | queryset_all = queryset_all.filter(layer_version__in = prj.projectlayer_equivalent_set()) |
2226 | |||
2239 | return HttpResponse(jsonfilter({ "error":"ok", | 2227 | return HttpResponse(jsonfilter({ "error":"ok", |
2240 | "list" : map ( lambda x: {"id": x.pk, "name": x.name, "detail":"[" + x.layer_version.layer.name+ (" | " + x.layer_version.up_branch.name + "]" if x.layer_version.up_branch is not None else "]")}, | 2228 | "list" : map ( lambda x: {"id": x.pk, "name": x.name, "detail":"[" + x.layer_version.layer.name+ (" | " + x.layer_version.up_branch.name + "]" if x.layer_version.up_branch is not None else "]")}, |
2241 | queryset_all.filter(name__icontains=request.GET.get('value',''))[:8]), | 2229 | queryset_all.filter(name__icontains=request.GET.get('value',''))[:8]), |
@@ -2283,14 +2271,13 @@ if toastermain.settings.MANAGED: | |||
2283 | 2271 | ||
2284 | prj = Project.objects.get(pk = request.session['project_id']) | 2272 | prj = Project.objects.get(pk = request.session['project_id']) |
2285 | 2273 | ||
2286 | queryset_all = _compatible_layerversions_for_project(prj) | 2274 | queryset_all = prj.compatible_layerversions() |
2287 | 2275 | ||
2288 | queryset_all = _get_queryset(Layer_Version, queryset_all, filter_string, search_term, ordering_string, '-layer__name') | 2276 | queryset_all = _get_queryset(Layer_Version, queryset_all, filter_string, search_term, ordering_string, '-layer__name') |
2289 | 2277 | ||
2290 | objects_all= list(set([x.get_equivalents_wpriority(prj)[0] for x in queryset_all[:pagesize]])) | ||
2291 | 2278 | ||
2292 | # retrieve the objects that will be displayed in the table; layers a paginator and gets a page range to display | 2279 | # retrieve the objects that will be displayed in the table; layers a paginator and gets a page range to display |
2293 | layer_info = _build_page_range(Paginator(objects_all, request.GET.get('count', 10)),request.GET.get('page', 1)) | 2280 | layer_info = _build_page_range(Paginator(queryset_all, request.GET.get('count', 10)),request.GET.get('page', 1)) |
2294 | 2281 | ||
2295 | 2282 | ||
2296 | context = { | 2283 | context = { |