This is the third and possibly last batch of the python 3 upgrade changes.

Following scripts have either been adapted to version 3 or
verified that they need to be changed by all 3 patches:

./modules/httpserver-api/json2code.py
./modules/httpserver-api/tests/api/testenv.py 
./modules/httpserver-api/tests/api/testfile.py
./modules/httpserver-api/tests/api/testfs.py 
./modules/httpserver-api/tests/api/testjolokia.py
./modules/httpserver-api/tests/api/testjvm.py
./modules/httpserver-api/tests/api/testnetwork.py
./modules/httpserver-api/tests/api/testos.py 
./modules/httpserver-api/tests/api/testtrace.py 
./modules/httpserver-api/tests/basetest.py
./modules/httpserver-api/tests/testhttpserver-api.py
./modules/httpserver-html5-gui/tests/static/teststatic.py
./modules/httpserver-html5-gui/tests/testhttpserver.py
./modules/openjdk8-from-host/module.py
./scripts/export_manifest.py
./scripts/firecracker.py
./scripts/freq.py
./scripts/gen-rofs-img.py
./scripts/imgedit.py
./scripts/libosv.py
./scripts/loader.py
./scripts/manifest_common.py
./scripts/memory_analyzer.py
./scripts/metadata.py
./scripts/mkbootfs.py
./scripts/nbd_client.py
./scripts/osv/client.py
./scripts/osv/debug.py
./scripts/osv/modules/api.py
./scripts/osv/modules/filemap.py
./scripts/osv/modules/resolve.py
./scripts/osv/prof.py
./scripts/osv/trace.py
./scripts/osv/tree.py
./scripts/prof.py
./scripts/run.py
./scripts/setup.py
./scripts/tester.py
./scripts/test.py
./scripts/tests/test_app.py
./scripts/tests/test_app_with_test_script.py
./scripts/tests/test_http_app_with_curl_and_ab.py
./scripts/tests/testing.py
./scripts/tests/test_net.py
./scripts/tests/test_tracing.py
./scripts/top.py
./scripts/trace.py
./scripts/upload_manifest.py
./tests/tst-tcp-hash-cli.py

Following relevant python files have been left out from the
upgrade and possibly never will be upgraded:

./bsd/scripts/init-order.py
./bsd/sys/xen/interface/foreign/mkchecker.py
./bsd/sys/xen/interface/foreign/mkheader.py
./bsd/sys/xen/interface/foreign/structs.py
./scripts/benchs/zfs_mount.py
./scripts/ec2-gc.py
./scripts/ec2-make-ami.py
./scripts/ec2-simulator.py
./scripts/post-processing/scheduler/histo.py
./scripts/post-processing/scheduler/trace_sched_timings.py
./scripts/silentant.py
./scripts/tester.py
./scripts/test-ruby.py

Fixes #1056

Signed-off-by: Waldemar Kozaczuk <[email protected]>
---
 .../tests/testhttpserver.py                    |  4 +++-
 scripts/osv/modules/api.py                     |  6 +-----
 scripts/osv/modules/resolve.py                 |  6 +++---
 tests/tst-tcp-hash-cli.py                      | 18 +++++++++---------
 4 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/modules/httpserver-html5-gui/tests/testhttpserver.py 
b/modules/httpserver-html5-gui/tests/testhttpserver.py
index b48daeb0..4f5c8324 100755
--- a/modules/httpserver-html5-gui/tests/testhttpserver.py
+++ b/modules/httpserver-html5-gui/tests/testhttpserver.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 import sys
 import argparse
 import os
@@ -17,6 +17,8 @@ parser.add_argument('--run_script', help='path to the run 
image script', default
 parser.add_argument('--cmd', help='the command to execute')
 parser.add_argument('--use_sudo', help='Use sudo with -n option instead of 
port forwarding', action='store_true')
 parser.add_argument('--jsondir', help='location of the json files', 
default=os.path.join(module_base, '../httpserver-api/api-doc/listings/'))
+parser.add_argument('--test_image', help='the path to the test image')
+parser.add_argument('--hypervisor', action="store", default="qemu", 
help="choose hypervisor to run: qemu, firecracker")
 client.Client.add_arguments(parser)
 
 if __name__ == '__main__':
diff --git a/scripts/osv/modules/api.py b/scripts/osv/modules/api.py
index 9a91fdf9..03b2b5f7 100644
--- a/scripts/osv/modules/api.py
+++ b/scripts/osv/modules/api.py
@@ -47,11 +47,7 @@ class java_app(object):
         return []
 
 def get_string_object():
-    import sys
-    if sys.version < '3':
-        return basestring
-    else:
-        return str
+    return str
 
 def _to_args_list(text_or_list):
     if not text_or_list:
diff --git a/scripts/osv/modules/resolve.py b/scripts/osv/modules/resolve.py
index 17871d59..5d5c82f7 100644
--- a/scripts/osv/modules/resolve.py
+++ b/scripts/osv/modules/resolve.py
@@ -57,7 +57,7 @@ def get_required_modules():
     according to dependency graph
 
     """
-    return list(unique(_modules.values()))
+    return list(unique(list(_modules.values())))
 
 def _is_direct(module_config):
     return module_config["type"] == "direct-dir"
@@ -87,7 +87,7 @@ def find_module_config(module_name):
 def all_module_directories():
     config = read_config()
 
-    for module_name, module_config in config["modules"].items():
+    for module_name, module_config in list(config["modules"].items()):
         if module_name == "repositories":
             for repo in config["modules"]["repositories"]:
                 repo_path = os.path.expandvars(repo)
@@ -127,7 +127,7 @@ def 
require_if_other_module_present(module_name,other_module_name):
 
 def resolve_required_modules_if_other_is_present():
     required_module_names = set()
-    for module_name in _modules_to_be_added_if_other_module_present.keys():
+    for module_name in 
list(_modules_to_be_added_if_other_module_present.keys()):
         # If module is present then add modules that should be required 
implictly
         if( _modules.get(module_name)):
             modules_to_be_added = 
_modules_to_be_added_if_other_module_present[module_name]
diff --git a/tests/tst-tcp-hash-cli.py b/tests/tst-tcp-hash-cli.py
index 270c0942..cf81184f 100755
--- a/tests/tst-tcp-hash-cli.py
+++ b/tests/tst-tcp-hash-cli.py
@@ -1,6 +1,6 @@
-#!/bin/env python2
+#!/usr/bin/env python3
 import socket
-from Queue import Queue
+from queue import Queue
 from threading import Thread
 import sys
 
@@ -16,7 +16,7 @@ class Worker(Thread):
         while True:
             func, args, kargs = self.tasks.get()
             try: func(*args, **kargs)
-            except Exception, e: print e
+            except Exception as e: print(e)
             self.tasks.task_done()
 
 class ThreadPool:
@@ -67,16 +67,16 @@ if __name__ == "__main__":
         nthreads = int(sys.argv[1])
         connections = int(sys.argv[2])
     except:
-        print "Usage: ./tst-tcp-hash-cli.py <nthreads> <connections>"
+        print("Usage: ./tst-tcp-hash-cli.py <nthreads> <connections>")
         sys.exit()
 
     #data = range(0, (4096**2)*2, 11)
-    data = range(0,4096, 11)
-    data = map(lambda x: chr(x % 256), data)
+    data = list(range(0,4096, 11))
+    data = [chr(x % 256) for x in data]
     expected = hash_function(data)
 
-    print "Sending %d bytes requests, expected hash: %d" % (len(data), 
expected)
-    print "Creating %d threads and making %d connections, please wait..." % 
(nthreads, connections)
+    print("Sending %d bytes requests, expected hash: %d" % (len(data), 
expected))
+    print("Creating %d threads and making %d connections, please wait..." % 
(nthreads, connections))
 
     drops = 0
     hash_errors = 0
@@ -88,6 +88,6 @@ if __name__ == "__main__":
     pool.wait_completion()
 
     # FIXME: these metrics may not be accurate as I didn't use locks and 
interfere with the test
-    print "Test completed with %d drops and %d hash errors" % (drops, 
hash_errors)
+    print("Test completed with %d drops and %d hash errors" % (drops, 
hash_errors))
 
 
-- 
2.20.1

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/20200217232231.18298-2-jwkozaczuk%40gmail.com.

Reply via email to