Main scripts in scripts/ folder updated to use Python3
I went through the scripts detailed in scripts/README and updated them to use
Python3. I used the Python "Future" module to provide suggestions, then
manually went through and applied the changes. The "Future" module gives
suggestions to allow for cross-compatibility between Python2/3, but since it
was expressed that only Python3 needed to be supported, I left all that out.
The issue is detailed here:
https://github.com/cloudius-systems/osv/issues/1056
---
scripts/export_manifest.py | 14 +-
scripts/firecracker.py | 4 +--
scripts/gen-rofs-img.py| 18 ++--
scripts/loader.py | 57 ++
scripts/metadata.py| 6 ++--
scripts/mkbootfs.py| 7 ++---
scripts/module.py | 4 +--
scripts/setup.py | 10 +++
scripts/test.py| 6 ++--
scripts/tests/testing.py | 4 +--
scripts/upload_manifest.py | 12 ++--
11 files changed, 65 insertions(+), 77 deletions(-)
diff --git a/scripts/export_manifest.py b/scripts/export_manifest.py
index 5e8fb4e7..370b1f29 100755
--- a/scripts/export_manifest.py
+++ b/scripts/export_manifest.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
import optparse, os, shutil
from manifest_common import add_var, expand, unsymlink, read_manifest,
defines, strip_file
@@ -8,7 +8,7 @@ from manifest_common import add_var, expand, unsymlink,
read_manifest, defines,
# support for links in OSv, e.g., /etc/mnttab: ->/proc/mounts.
def export_package(manifest, dest):
abs_dest = os.path.abspath(dest)
-print "[INFO] exporting into directory %s" % abs_dest
+print("[INFO] exporting into directory %s" % abs_dest)
# Remove and create the base directory where we are going to put all
package files.
if os.path.exists(abs_dest):
@@ -39,7 +39,7 @@ def export_package(manifest, dest):
os.makedirs(target_dir)
os.symlink(link_source, name)
-print "[INFO] added link %s -> %s" % (name, link_source)
+print("[INFO] added link %s -> %s" % (name, link_source))
else:
# If it is a symlink, then resolve it add to the list of host
symlinks to be created later
@@ -58,23 +58,23 @@ def export_package(manifest, dest):
hostname = strip_file(hostname)
shutil.copy(hostname, name)
-print "[INFO] exported %s" % name
+print("[INFO] exported %s" % name)
elif os.path.isdir(hostname):
# If hostname is a dir, it is only a request to create the
folder on guest. Nothing to copy.
if not os.path.exists(name):
os.makedirs(name)
-print "[INFO] created dir %s" % name
+print("[INFO] created dir %s" % name)
else:
# Inform the user that the rule cannot be applied. For
example, this happens for links in OSv.
-print "[ERR] unable to export %s" % hostname
+print("[ERR] unable to export %s" % hostname)
for link_source, name in host_symlinks:
target_dir = os.path.dirname(name)
if not os.path.exists(target_dir):
os.makedirs(target_dir)
os.symlink(link_source, name)
-print "[INFO] added link %s -> %s" % (name, link_source)
+print("[INFO] added link %s -> %s" % (name, link_source))
def main():
make_option = optparse.make_option
diff --git a/scripts/firecracker.py b/scripts/firecracker.py
index 3f21081d..5c98b0ee 100755
--- a/scripts/firecracker.py
+++ b/scripts/firecracker.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# pip install requests-unixsocket
import sys
@@ -182,7 +182,7 @@ def find_firecracker(dirname):
if not os.path.exists(firecracker_path):
url_base =
'https://github.com/firecracker-microvm/firecracker/releases/download'
download_url = '%s/%s/firecracker-%s' % (url_base,
firecracker_version, firecracker_version)
-answer = raw_input("Firecracker executable has not been found under
%s. "
+answer = input("Firecracker executable has not been found under %s. "
"Would you like to download it from %s and place it
under %s? [y|n]" %
(firecracker_path, download_url, firecracker_path))
if answer.capitalize() != 'Y':
diff --git a/scripts/gen-rofs-img.py b/scripts/gen-rofs-img.py
index e825c639..8904a870 100755
--- a/scripts/gen-rofs-img.py
+++ b/scripts/gen-rofs-img.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
#
# Copyright (c) 2015 Carnegie Mellon University.
@@ -218,13 +218,13 @@ def write_dir(fp, manifest, dirpath, parent_dir):
inode.data_offset = symlinks_count
inode.count = 1
next_symlink(val[2:],manifest)
-print 'Link %s to %s' % (dirpath +