Repository: cyberbotics/webots
Issue: web_component_supervisor.py is not working with Python3

The `web_component_supervisor.py` controller should be updated to work with Python3.

Changed files:
scripts/web_component_studio/controllers/web_component_studio_supervisor/web_component_studio_supervisor.py
scripts/preferences_cleaner/preferences_cleaner.py
scripts/web_component_studio/web_component_studio.py

diff --git a/scripts/preferences_cleaner/preferences_cleaner.py b/scripts/preferences_cleaner/preferences_cleaner.py
index af83fc23f..fde9af14c 100755
--- a/scripts/preferences_cleaner/preferences_cleaner.py
+++ b/scripts/preferences_cleaner/preferences_cleaner.py
@@ -21,7 +21,7 @@ import platform
 import sys
 
 # Due to the use of pathlib and winreg.
-assert sys.version_info >= (3, 5), 'At least Python 3.5 is required to run this script.'
+assert sys.version_info >= (3, 5), 'Python 3.5 or later is required to run this script.'
 
 
 def cleanupLinuxPreferences():
diff --git a/scripts/web_component_studio/controllers/web_component_studio_supervisor/web_component_studio_supervisor.py b/scripts/web_component_studio/controllers/web_component_studio_supervisor/web_component_studio_supervisor.py
index 365185915..b3ef3b9f7 100644
--- a/scripts/web_component_studio/controllers/web_component_studio_supervisor/web_component_studio_supervisor.py
+++ b/scripts/web_component_studio/controllers/web_component_studio_supervisor/web_component_studio_supervisor.py
@@ -20,6 +20,7 @@ import glob
 import os
 import shutil
 from lxml import etree
+from functools import cmp_to_key
 
 
 def _cmp(a, b):
@@ -82,7 +83,7 @@ with open(targetMetaFile) as f:
             break
     assert robotData, 'Failed to simplified the JSON supervisor.'
     # - sort the device list per interesting category type.
-    robotData['devices'] = sorted(robotData['devices'], cmp=_compareDevice)
+    robotData['devices'] = sorted(robotData['devices'], key=cmp_to_key(_compareDevice))
     # - rewrite the json file.
     with open(targetMetaFile, 'w') as f:
         json.dump(robotData, f, indent=2)
diff --git a/scripts/web_component_studio/web_component_studio.py b/scripts/web_component_studio/web_component_studio.py
index e168f4a12..c1add91a5 100755
--- a/scripts/web_component_studio/web_component_studio.py
+++ b/scripts/web_component_studio/web_component_studio.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # Copyright 1996-2019 Cyberbotics Ltd.
 #
@@ -16,17 +16,25 @@
 
 """Create a web component scene foreach component of the components.json file."""
 
-import json
-import os
-from shutil import copyfile
+import sys
+assert sys.version_info >= (3, 5), 'Python 3.5 or later is required to run this script.'
+
+import json  # noqa
+import os  # noqa
+
+from shutil import copyfile  # noqa
+from inspect import currentframe, getframeinfo  # noqa
+from pathlib import Path  # noqa
 
-# Paths.
-WORLD = 'worlds/web_component_studio.wbt'
-TEMPLATE = 'worlds/web_component_studio_template.wbt'
-ROBOTS = 'components.json'
 WEBOTS_HOME = os.getenv('WEBOTS_HOME')
 assert WEBOTS_HOME, 'WEBOTS_HOME is undefined'
 
+# Paths.
+scriptdir = Path(getframeinfo(currentframe()).filename).resolve().parent
+WORLD = scriptdir / 'worlds' / 'web_component_studio.wbt'
+TEMPLATE = scriptdir / 'worlds' / 'web_component_studio_template.wbt'
+ROBOTS = scriptdir / 'components.json'
+
 
 def search_and_replace(filename, fromString, toString):
     """Search and replace string in a file."""
@@ -39,7 +47,7 @@ def search_and_replace(filename, fromString, toString):
 
 def run_webots():
     """Run Webots on WORLD with right flags."""
-    os.system(WEBOTS_HOME + '/webots --enable-x3d-meta-file-export --mode=fast --minimize ' + WORLD)
+    os.system(WEBOTS_HOME + '/webots --enable-x3d-meta-file-export --mode=fast --minimize %s' % WORLD)
 
 
 # Script logics.