diff options
Diffstat (limited to 'bitbake/lib/toaster/toastergui/views.py')
| -rwxr-xr-x | bitbake/lib/toaster/toastergui/views.py | 107 |
1 files changed, 102 insertions, 5 deletions
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 434e1180b0..ec055d392a 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py | |||
| @@ -30,6 +30,7 @@ from orm.models import Task_Dependency, Recipe_Dependency, Package, Package_File | |||
| 30 | from orm.models import Target_Installed_Package, Target_File, Target_Image_File, BuildArtifact | 30 | from orm.models import Target_Installed_Package, Target_File, Target_Image_File, BuildArtifact |
| 31 | from django.views.decorators.cache import cache_control | 31 | from django.views.decorators.cache import cache_control |
| 32 | from django.core.urlresolvers import reverse | 32 | from django.core.urlresolvers import reverse |
| 33 | from django.core.exceptions import MultipleObjectsReturned | ||
| 33 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger | 34 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger |
| 34 | from django.http import HttpResponseBadRequest, HttpResponseNotFound | 35 | from django.http import HttpResponseBadRequest, HttpResponseNotFound |
| 35 | from django.utils import timezone | 36 | from django.utils import timezone |
| @@ -2016,8 +2017,9 @@ if toastermain.settings.MANAGED: | |||
| 2016 | "name" : x.layercommit.layer.name, | 2017 | "name" : x.layercommit.layer.name, |
| 2017 | "giturl": x.layercommit.layer.vcs_url, | 2018 | "giturl": x.layercommit.layer.vcs_url, |
| 2018 | "url": x.layercommit.layer.layer_index_url, | 2019 | "url": x.layercommit.layer.layer_index_url, |
| 2019 | "layerdetailurl": reverse("layerdetails", args=(x.layercommit.layer.pk,)), | 2020 | "layerdetailurl": reverse("layerdetails", args=(x.layercommit.pk,)), |
| 2020 | "branch" : { "name" : x.layercommit.up_branch.name, "layersource" : x.layercommit.up_branch.layer_source.name}}, | 2021 | # This branch name is actually the release |
| 2022 | "branch" : { "name" : x.layercommit.commit, "layersource" : x.layercommit.up_branch.layer_source.name}}, | ||
| 2021 | prj.projectlayer_set.all().order_by("id")), | 2023 | prj.projectlayer_set.all().order_by("id")), |
| 2022 | "targets" : map(lambda x: {"target" : x.target, "task" : x.task, "pk": x.pk}, prj.projecttarget_set.all()), | 2024 | "targets" : map(lambda x: {"target" : x.target, "task" : x.task, "pk": x.pk}, prj.projecttarget_set.all()), |
| 2023 | "freqtargets": freqtargets, | 2025 | "freqtargets": freqtargets, |
| @@ -2164,7 +2166,7 @@ if toastermain.settings.MANAGED: | |||
| 2164 | 2166 | ||
| 2165 | 2167 | ||
| 2166 | def _lv_to_dict(x): | 2168 | def _lv_to_dict(x): |
| 2167 | return {"id": x.pk, "name": x.layer.name, | 2169 | return {"id": x.pk, "name": x.layer.name, "tooltip": x.layer.vcs_url+" | "+x.commit, |
| 2168 | "detail": "(" + x.layer.vcs_url + (")" if x.up_branch == None else " | "+x.up_branch.name+")"), | 2170 | "detail": "(" + x.layer.vcs_url + (")" if x.up_branch == None else " | "+x.up_branch.name+")"), |
| 2169 | "giturl": x.layer.vcs_url, "layerdetailurl" : reverse('layerdetails', args=(x.pk,))} | 2171 | "giturl": x.layer.vcs_url, "layerdetailurl" : reverse('layerdetails', args=(x.pk,))} |
| 2170 | 2172 | ||
| @@ -2174,8 +2176,9 @@ if toastermain.settings.MANAGED: | |||
| 2174 | # all layers for the current project | 2176 | # all layers for the current project |
| 2175 | queryset_all = prj.compatible_layerversions().filter(layer__name__icontains=request.GET.get('value','')) | 2177 | queryset_all = prj.compatible_layerversions().filter(layer__name__icontains=request.GET.get('value','')) |
| 2176 | 2178 | ||
| 2177 | # but not layers with equivalent layers already in project | 2179 | # 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] | 2180 | if not request.GET.has_key('include_added'): |
| 2181 | queryset_all = queryset_all.exclude(pk__in = [x.id for x in prj.projectlayer_equivalent_set()])[:8] | ||
| 2179 | 2182 | ||
| 2180 | # and show only the selected layers for this project | 2183 | # and show only the selected layers for this project |
| 2181 | final_list = set([x.get_equivalents_wpriority(prj)[0] for x in queryset_all]) | 2184 | final_list = set([x.get_equivalents_wpriority(prj)[0] for x in queryset_all]) |
| @@ -2243,6 +2246,100 @@ if toastermain.settings.MANAGED: | |||
| 2243 | return HttpResponse(jsonfilter({"error":str(e) + "\n" + traceback.format_exc()}), content_type = "application/json") | 2246 | return HttpResponse(jsonfilter({"error":str(e) + "\n" + traceback.format_exc()}), content_type = "application/json") |
| 2244 | 2247 | ||
| 2245 | 2248 | ||
| 2249 | def xhr_importlayer(request): | ||
| 2250 | if (not request.POST.has_key('vcs_url') or | ||
| 2251 | not request.POST.has_key('name') or | ||
| 2252 | not request.POST.has_key('git_ref') or | ||
| 2253 | not request.POST.has_key('project_id')): | ||
| 2254 | return HttpResponse(jsonfilter({"error": "Missing parameters; requires vcs_url, name, git_ref and project_id"}), content_type = "application/json") | ||
| 2255 | |||
| 2256 | # Rudimentary check for any possible html tags | ||
| 2257 | if "<" in request.POST: | ||
| 2258 | return HttpResponse(jsonfilter({"error": "Invalid character <"}), content_type = "application/json") | ||
| 2259 | |||
| 2260 | prj = Project.objects.get(pk=request.POST['project_id']) | ||
| 2261 | |||
| 2262 | # Strip trailing/leading whitespace from all values | ||
| 2263 | # put into a new dict because POST one is immutable | ||
| 2264 | post_data = dict() | ||
| 2265 | for key,val in request.POST.iteritems(): | ||
| 2266 | post_data[key] = val.strip() | ||
| 2267 | |||
| 2268 | |||
| 2269 | # We need to know what release the current project is so that we | ||
| 2270 | # can set the imported layer's up_branch_id | ||
| 2271 | prj_branch_name = Release.objects.get(pk=prj.release_id).branch_name | ||
| 2272 | up_branch, branch_created = Branch.objects.get_or_create(name=prj_branch_name, layer_source_id=LayerSource.TYPE_IMPORTED) | ||
| 2273 | |||
| 2274 | layer_source = LayerSource.objects.get(sourcetype=LayerSource.TYPE_IMPORTED) | ||
| 2275 | try: | ||
| 2276 | layer, layer_created = Layer.objects.get_or_create(name=post_data['name']) | ||
| 2277 | except MultipleObjectsReturned: | ||
| 2278 | return HttpResponse(jsonfilter({"error": "hint-layer-exists"}), content_type = "application/json") | ||
| 2279 | |||
| 2280 | if layer: | ||
| 2281 | if layer_created: | ||
| 2282 | layer.layer_source = layer_source | ||
| 2283 | layer.vcs_url = post_data['vcs_url'] | ||
| 2284 | if post_data.has_key('summary'): | ||
| 2285 | layer.summary = layer.description = post_data['summary'] | ||
| 2286 | |||
| 2287 | layer.up_date = timezone.now() | ||
| 2288 | layer.save() | ||
| 2289 | else: | ||
| 2290 | # We have an existing layer by this name, let's see if the git | ||
| 2291 | # url is the same, if it is then we can just create a new layer | ||
| 2292 | # version for this layer. Otherwise we need to bail out. | ||
| 2293 | if layer.vcs_url != post_data['vcs_url']: | ||
| 2294 | return HttpResponse(jsonfilter({"error": "hint-layer-exists-with-different-url" , "current_url" : layer.vcs_url, "current_id": layer.id }), content_type = "application/json") | ||
| 2295 | |||
| 2296 | |||
| 2297 | layer_version, version_created = Layer_Version.objects.get_or_create(layer_source=layer_source, layer=layer, project=prj, up_branch_id=up_branch.id,branch=post_data['git_ref'], commit=post_data['git_ref'], dirpath=post_data['dir_path']) | ||
| 2298 | |||
| 2299 | if layer_version: | ||
| 2300 | if not version_created: | ||
| 2301 | return HttpResponse(jsonfilter({"error": "hint-layer-version-exists", "existing_layer_version": layer_version.id }), content_type = "application/json") | ||
| 2302 | |||
| 2303 | layer_version.up_date = timezone.now() | ||
| 2304 | layer_version.save() | ||
| 2305 | |||
| 2306 | # Add the dependencies specified for this new layer | ||
| 2307 | if (post_data.has_key("layer_deps") and | ||
| 2308 | version_created and | ||
| 2309 | len(post_data["layer_deps"]) > 0): | ||
| 2310 | for layer_dep_id in post_data["layer_deps"].split(","): | ||
| 2311 | |||
| 2312 | layer_dep_obj = Layer_Version.objects.get(pk=layer_dep_id) | ||
| 2313 | LayerVersionDependency.objects.get_or_create(layer_version=layer_version, depends_on=layer_dep_obj) | ||
| 2314 | # Now add them to the project, we could get an execption | ||
| 2315 | # if the project now contains the exact | ||
| 2316 | # dependency already (like modified on another page) | ||
| 2317 | try: | ||
| 2318 | ProjectLayer.objects.get_or_create(layercommit=layer_dep_obj, project=prj) | ||
| 2319 | except: | ||
| 2320 | pass | ||
| 2321 | |||
| 2322 | |||
| 2323 | # If an old layer version exists in our project then remove it | ||
| 2324 | for prj_layers in ProjectLayer.objects.filter(project=prj): | ||
| 2325 | dup_layer_v = Layer_Version.objects.filter(id=prj_layers.layercommit_id, layer_id=layer.id) | ||
| 2326 | if len(dup_layer_v) >0 : | ||
| 2327 | prj_layers.delete() | ||
| 2328 | |||
| 2329 | # finally add the imported layer (version id) to the project | ||
| 2330 | ProjectLayer.objects.create(layercommit=layer_version, project=prj,optional=1) | ||
| 2331 | |||
| 2332 | else: | ||
| 2333 | # We didn't create a layer version so back out now and clean up. | ||
| 2334 | if layer_created: | ||
| 2335 | layer.delete() | ||
| 2336 | |||
| 2337 | return HttpResponse(jsonfilter({"error": "Uncaught error: Could not create layer version"}), content_type = "application/json") | ||
| 2338 | |||
| 2339 | |||
| 2340 | return HttpResponse(jsonfilter({"error": "ok"}), content_type = "application/json") | ||
| 2341 | |||
| 2342 | |||
| 2246 | 2343 | ||
| 2247 | def importlayer(request): | 2344 | def importlayer(request): |
| 2248 | template = "importlayer.html" | 2345 | template = "importlayer.html" |
