Soft Patch Panel
 help / color / mirror / Atom feed
From: Yasufumi Ogawa <yasufum.o@gmail.com>
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH 27/29] tools/sppc: python3 support for sppc build tool
Date: Tue, 25 Feb 2020 19:34:44 +0900
Message-ID: <20200225103446.8243-28-yasufum.o@gmail.com> (raw)
In-Reply-To: <20200225103446.8243-1-yasufum.o@gmail.com>

Although python2 support was dropped in SPP itself, it is still
remained in SPP container tools. This update is to make the tools run
with python3.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 tools/sppc/build/main.py | 81 +++++++++++++++++++++-------------------
 1 file changed, 43 insertions(+), 38 deletions(-)

diff --git a/tools/sppc/build/main.py b/tools/sppc/build/main.py
index 023ec82..c0d02d2 100755
--- a/tools/sppc/build/main.py
+++ b/tools/sppc/build/main.py
@@ -1,8 +1,7 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2018 Nippon Telegraph and Telephone Corporation
 
-from __future__ import absolute_import
 import argparse
 import os
 import subprocess
@@ -86,22 +85,22 @@ def parse_args():
 
 
 def create_env_sh(dst_dir, rte_sdk, target, target_dir):
-    """Create config file for DPDK environment variables
+    """Create config file for DPDK environment variables.
 
     Create 'env.sh' which defines $RTE_SDK and $RTE_TARGET inside a
     container to be referredd from 'run.sh' and Dockerfile.
     """
-    contents = "export RTE_SDK=%s\n" % rte_sdk
-    contents += "export RTE_TARGET=%s\n" % env.RTE_TARGET
+    contents = "export RTE_SDK={:s}\n".format(rte_sdk)
+    contents += "export RTE_TARGET={:s}\n".format(env.RTE_TARGET)
     if target == 'pktgen':
-        contents += "export PKTGEN_DIR=%s" % target_dir
+        contents += "export PKTGEN_DIR={:s}".format(target_dir)
     elif target == 'spp':
-        contents += "export SPP_DIR=%s" % target_dir
+        contents += "export SPP_DIR={:s}".format(target_dir)
     elif target == 'suricata':
-        contents += "export SURICATA_DIR=%s" % target_dir
+        contents += "export SURICATA_DIR={:s}".format(target_dir)
 
     try:
-        f = open('%s/env.sh' % dst_dir, 'w')
+        f = open('{:s}/env.sh'.format(dst_dir), 'w')
         f.write(contents)
         f.close()
     except IOError:
@@ -112,7 +111,7 @@ def main():
     args = parse_args()
 
     if args.target is not None:
-        dockerfile_dir = '%s/%s/%s' % (  # Dockerfile is contained here
+        dockerfile_dir = '{:s}/{:s}/{:s}'.format(  # Dockerfile is here
             work_dir, args.dist_name, args.target)
         # Container image name, for exp 'sppc/dpdk-ubuntu:18.04'
         container_image = common.container_img_name(
@@ -124,7 +123,7 @@ def main():
         exit()
 
     # Decide which of Dockerfile with given base image version
-    dockerfile = '%s/Dockerfile.%s' % (dockerfile_dir, args.dist_ver)
+    dockerfile = '{:s}/Dockerfile.{:s}'.format(dockerfile_dir, args.dist_ver)
 
     # Overwrite container's name if it is given.
     if args.container_image is not None:
@@ -132,22 +131,22 @@ def main():
 
     # Setup branches if user specifies.
     if args.dpdk_branch is not None:
-        dpdk_branch = "-b %s" % args.dpdk_branch
+        dpdk_branch = "-b {:s}".format(args.dpdk_branch)
     else:
         dpdk_branch = ''
 
     if args.pktgen_branch is not None:
-        pktgen_branch = "-b %s" % args.pktgen_branch
+        pktgen_branch = "-b {:s}".format(args.pktgen_branch)
     else:
         pktgen_branch = ''
 
     if args.spp_branch is not None:
-        spp_branch = "-b %s" % args.spp_branch
+        spp_branch = "-b {:s}".format(args.spp_branch)
     else:
         spp_branch = ''
 
     if args.suricata_branch is not None:
-        suricata_branch = "-b %s" % args.suricata_branch
+        suricata_branch = "-b {:s}".format(args.suricata_branch)
     else:
         suricata_branch = ''
 
@@ -160,11 +159,11 @@ def main():
 
     # NOTE: Suricata has sub-directory as project root.
     suricata_ver = '4.1.4'
-    suricata_dir = '{}/suricata-{}'.format(
+    suricata_dir = '{:s}/suricata-{:s}'.format(
             args.suricata_repo.split('/')[-1].split('.')[0], suricata_ver)
 
     # RTE_SDK is decided with DPDK's dir.
-    rte_sdk = '%s/%s' % (env.HOMEDIR, dpdk_dir)
+    rte_sdk = '{:s}/{:s}'.format(env.HOMEDIR, dpdk_dir)
 
     # Check for just creating env.sh, or run docker build.
     if args.only_envsh is True:
@@ -174,13 +173,14 @@ def main():
             elif args.target == 'spp':
                 create_env_sh(dockerfile_dir, rte_sdk, args.target, spp_dir)
             elif args.target == 'suricata':
-                create_env_sh(dockerfile_dir, rte_sdk, args.target, suricata_dir)
+                create_env_sh(dockerfile_dir, rte_sdk, args.target,
+                              suricata_dir)
             elif args.target == 'dpdk':
                 create_env_sh(dockerfile_dir, rte_sdk, args.target, dpdk_dir)
-            print("Info: '%s/env.sh' created." % dockerfile_dir)
+            print("Info: '{:s}/env.sh' created.".format(dockerfile_dir))
             exit()
         else:
-            print("Info: Nothin done because you gave %s with %s." % (
+            print("Info: Nothin done because you gave {:s} with {:s}.".format(
                 '--only-envsh', '--dry-run'))
             exit()
     else:
@@ -205,35 +205,40 @@ def main():
     for opt in env_opts:
         if opt in os.environ.keys():
             docker_cmd += [
-                '--build-arg', '%s=%s' % (opt, os.environ[opt]), '\\']
+                    '--build-arg', '{:s}={:s}'.
+                    format(opt, os.environ[opt]), '\\']
 
     docker_cmd += [
-        '--build-arg', 'home_dir=%s' % env.HOMEDIR, '\\',
-        '--build-arg', 'rte_sdk=%s' % rte_sdk, '\\',
-        '--build-arg', 'rte_target=%s' % env.RTE_TARGET, '\\',
-        '--build-arg', 'dpdk_repo=%s' % args.dpdk_repo, '\\',
-        '--build-arg', 'dpdk_branch=%s' % dpdk_branch, '\\']
+        '--build-arg', 'home_dir={:s}'.format(env.HOMEDIR), '\\',
+        '--build-arg', 'rte_sdk={:s}'.format(rte_sdk), '\\',
+        '--build-arg', 'rte_target={:s}'.format(env.RTE_TARGET), '\\',
+        '--build-arg', 'dpdk_repo={:s}'.format(args.dpdk_repo), '\\',
+        '--build-arg', 'dpdk_branch={:s}'.format(dpdk_branch), '\\']
 
     if args.target == 'pktgen':
         docker_cmd += [
-            '--build-arg', 'pktgen_repo=%s' % args.pktgen_repo, '\\',
-            '--build-arg', 'pktgen_branch=%s' % pktgen_branch, '\\',
-            '--build-arg', 'pktgen_dir=%s' % pktgen_dir, '\\']
+                '--build-arg', 'pktgen_repo={:s}'.format(
+                    args.pktgen_repo), '\\',
+                '--build-arg', 'pktgen_branch={:s}'.format(
+                    pktgen_branch), '\\',
+                '--build-arg', 'pktgen_dir={:s}'.format(pktgen_dir), '\\']
     elif args.target == 'spp':
         docker_cmd += [
-            '--build-arg', 'spp_repo=%s' % args.spp_repo, '\\',
-            '--build-arg', 'spp_branch=%s' % spp_branch, '\\',
-            '--build-arg', 'spp_dir=%s' % spp_dir, '\\']
+                '--build-arg', 'spp_repo={:s}'.format(args.spp_repo), '\\',
+                '--build-arg', 'spp_branch={:s}'.format(spp_branch), '\\',
+                '--build-arg', 'spp_dir={:s}'.format(spp_dir), '\\']
     elif args.target == 'suricata':
         docker_cmd += [
-            '--build-arg', 'suricata_repo=%s' % args.suricata_repo, '\\',
-            '--build-arg', 'suricata_branch=%s' % suricata_branch, '\\',
-            '--build-arg', 'suricata_dir=%s' % suricata_dir, '\\']
+                '--build-arg', 'suricata_repo={:s}'.format(
+                    args.suricata_repo), '\\',
+                '--build-arg', 'suricata_branch={:s}'.format(
+                    suricata_branch), '\\',
+                '--build-arg', 'suricata_dir={:s}'.format(suricata_dir), '\\']
 
     docker_cmd += [
-        '-f', '%s' % dockerfile, '\\',
-        '-t', container_image, '\\',
-        dockerfile_dir]
+            '-f', '{:s}'.format(dockerfile), '\\',
+            '-t', container_image, '\\',
+            dockerfile_dir]
 
     common.print_pretty_commands(docker_cmd)
 
-- 
2.17.1


  parent reply	other threads:[~2020-02-25 10:35 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-25 10:34 [spp] [PATCH 00/29] Update SPP Container tools Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 01/29] tools/sppc: update options for assigning devices Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 02/29] tools/sppc: update dev options of l2fwd Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 03/29] tools/sppc: add container name option Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 04/29] tools/sppc: update l2fwd app for " Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 05/29] tools/sppc: update dev options of l3fwd Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 06/29] tools/sppc: update dev options of l3fwd-acl Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 07/29] tools/sppc: update dev options of testpmd Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 08/29] tools/sppc: update dev options of pktgen Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 09/29] tools/sppc: update dev options of load-balancer Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 10/29] tools/sppc: version checker for container DPDK ver Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 11/29] tools/sppc: check DPDK ver in load-balancer Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 12/29] tools/sppc: setup spp_pri opts in app_helper Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 13/29] tools/sppc: define file prefix for SPP Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 14/29] tools/sppc: update dev options of spp_primary Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 15/29] tools/sppc: setup with docker opts in SPP pri Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 16/29] tools/sppc: update calling setup_docker_opts() Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 17/29] tools/sppc: update dev options of helloworld Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 18/29] tools/sppc: update dev options of suricata Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 19/29] tools/sppc: update dev options of spp_nfv Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 20/29] tools/sppc: change to gen EAL opts with app name Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 21/29] tools/sppc: remove nouse variable Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 22/29] bin: remove sock files created by docker Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 23/29] tools/sppc: skip checking rule file if dry run Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 24/29] docs: revise examples in sppc Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 25/29] docs: update versions in " Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 26/29] docs: update old example in spp_primary container Yasufumi Ogawa
2020-02-25 10:34 ` Yasufumi Ogawa [this message]
2020-02-25 10:34 ` [spp] [PATCH 28/29] docs: update app container help msg Yasufumi Ogawa
2020-02-25 10:34 ` [spp] [PATCH 29/29] docs: update howto define app container guide Yasufumi Ogawa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200225103446.8243-28-yasufum.o@gmail.com \
    --to=yasufum.o@gmail.com \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Soft Patch Panel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/spp/0 spp/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 spp spp/ https://inbox.dpdk.org/spp \
		spp@dpdk.org
	public-inbox-index spp

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.spp


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git