Преглед на файлове

bitbake: toaster: use 'in' instead of has_key

Dictionary method has_key is deprecated in python 2 and absent
in python 3.

Used '<key> in <dict>' statement to make the code working on
both python 2 and python 3.

[YOCTO #9584]

(Bitbake rev: 3d7ad7ba0d1a6f688ae885817c049f2a8ced11b5)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Ed Bartosh преди 9 години
родител
ревизия
3249e33251
променени са 3 файла, в които са добавени 16 реда и са изтрити 16 реда
  1. 14 14
      bitbake/lib/toaster/toastergui/views.py
  2. 1 1
      bitbake/lib/toaster/toastermain/settings.py
  3. 1 1
      bitbake/lib/toaster/toastermain/urls.py

+ 14 - 14
bitbake/lib/toaster/toastergui/views.py

@@ -2235,10 +2235,10 @@ if True:
 
 
     def xhr_importlayer(request):
-        if (not request.POST.has_key('vcs_url') or
-            not request.POST.has_key('name') or
-            not request.POST.has_key('git_ref') or
-            not request.POST.has_key('project_id')):
+        if ('vcs_url' not in request.POST or
+            'name' not in request.POST or
+            'git_ref' not in request.POST or
+            'project_id' not in request.POST):
           return HttpResponse(jsonfilter({"error": "Missing parameters; requires vcs_url, name, git_ref and project_id"}), content_type = "application/json")
 
         layers_added = [];
@@ -2294,7 +2294,7 @@ if True:
                 layer_version.save()
 
                 # Add the dependencies specified for this new layer
-                if (post_data.has_key("layer_deps") and
+                if ('layer_deps' in post_data and
                     version_created and
                     len(post_data["layer_deps"]) > 0):
                     for layer_dep_id in post_data["layer_deps"].split(","):
@@ -2348,7 +2348,7 @@ if True:
         def error_response(error):
             return HttpResponse(jsonfilter({"error": error}), content_type = "application/json")
 
-        if not request.POST.has_key("layer_version_id"):
+        if "layer_version_id" not in request.POST:
             return error_response("Please specify a layer version id")
         try:
             layer_version_id = request.POST["layer_version_id"]
@@ -2357,26 +2357,26 @@ if True:
             return error_response("Cannot find layer to update")
 
 
-        if request.POST.has_key("vcs_url"):
+        if "vcs_url" in request.POST:
             layer_version.layer.vcs_url = request.POST["vcs_url"]
-        if request.POST.has_key("dirpath"):
+        if "dirpath" in request.POST:
             layer_version.dirpath = request.POST["dirpath"]
-        if request.POST.has_key("commit"):
+        if "commit" in request.POST:
             layer_version.commit = request.POST["commit"]
-        if request.POST.has_key("up_branch"):
+        if "up_branch" in request.POST:
             layer_version.up_branch_id = int(request.POST["up_branch"])
 
-        if request.POST.has_key("add_dep"):
+        if "add_dep" in request.POST:
             lvd = LayerVersionDependency(layer_version=layer_version, depends_on_id=request.POST["add_dep"])
             lvd.save()
 
-        if request.POST.has_key("rm_dep"):
+        if "rm_dep" in request.POST:
             rm_dep = LayerVersionDependency.objects.get(layer_version=layer_version, depends_on_id=request.POST["rm_dep"])
             rm_dep.delete()
 
-        if request.POST.has_key("summary"):
+        if "summary" in request.POST:
             layer_version.layer.summary = request.POST["summary"]
-        if request.POST.has_key("description"):
+        if "description" in request.POST:
             layer_version.layer.description = request.POST["description"]
 
         try:

+ 1 - 1
bitbake/lib/toaster/toastermain/settings.py

@@ -321,7 +321,7 @@ currentdir = os.path.dirname(__file__)
 for t in os.walk(os.path.dirname(currentdir)):
     modulename = os.path.basename(t[0])
     #if we have a virtualenv skip it to avoid incorrect imports
-    if os.environ.has_key('VIRTUAL_ENV') and os.environ['VIRTUAL_ENV'] in t[0]:
+    if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]:
         continue
 
     if ("views.py" in t[2] or "models.py" in t[2]) and not modulename in INSTALLED_APPS:

+ 1 - 1
bitbake/lib/toaster/toastermain/urls.py

@@ -71,7 +71,7 @@ import os
 currentdir = os.path.dirname(__file__)
 for t in os.walk(os.path.dirname(currentdir)):
     #if we have a virtualenv skip it to avoid incorrect imports
-    if os.environ.has_key('VIRTUAL_ENV') and os.environ['VIRTUAL_ENV'] in t[0]:
+    if 'VIRTUAL_ENV' in os.environ and os.environ['VIRTUAL_ENV'] in t[0]:
         continue
 
     if "urls.py" in t[2] and t[0] != currentdir: