test suite reviews and discussions
 help / color / Atom feed
From: xinfengx <xinfengx.zhao@intel.com>
To: dts@dpdk.org
Cc: xinfengx <xinfengx.zhao@intel.com>
Subject: [dts] [next][PATCH V1 5/5] tools: modify dts tools to support python3
Date: Mon, 13 Jan 2020 06:18:31 +0800
Message-ID: <20200112221831.12192-6-xinfengx.zhao@intel.com> (raw)
In-Reply-To: <20200112221831.12192-1-xinfengx.zhao@intel.com>

Signed-off-by: xinfengx <xinfengx.zhao@intel.com>
---
 tools/dump_case.py |  5 ++---
 tools/parse_opt.py | 51 +++++++++++++++++++++++-----------------------
 tools/setup.py     | 31 ++++++++++++++--------------
 3 files changed, 42 insertions(+), 45 deletions(-)

diff --git a/tools/dump_case.py b/tools/dump_case.py
index cb866fc..22c79d2 100755
--- a/tools/dump_case.py
+++ b/tools/dump_case.py
@@ -1,4 +1,3 @@
-#!/usr/bin/python
 import sys
 import os
 import re
@@ -88,8 +87,8 @@ def load_cases():
         suite_func_list[suite] = func_cases
         suite_perf_list[suite] = perf_cases 
 
-    print pprint(suite_func_list)
-    print pprint(suite_perf_list)
+    print(pprint(suite_func_list))
+    print(pprint(suite_perf_list))
 
 
 if __name__ == '__main__':
diff --git a/tools/parse_opt.py b/tools/parse_opt.py
index e433d3f..c1bc02d 100755
--- a/tools/parse_opt.py
+++ b/tools/parse_opt.py
@@ -1,4 +1,3 @@
-#!/usr/bin/python
 import sys
 import os.path
 import re
@@ -20,14 +19,14 @@ class Option(object):
     def __init__(self, **args):
         self.args = args
 
-        if 'prompt' in args.keys():
+        if 'prompt' in list(args.keys()):
             self.prompt = args['prompt'] + ': '
         else:
             self.prompt = "Please input value: "
-        if 'type' in args.keys():
+        if 'type' in list(args.keys()):
             opt_type = args['type']
             if opt_type not in OPTION_TYPES:
-                print RED('Invalid option type!!!')
+                print(RED('Invalid option type!!!'))
                 raise ValueError
             else:
                 self.opt_type = opt_type
@@ -36,14 +35,14 @@ class Option(object):
         if self.opt_type == 'bool':
             self.prompt += '[Yes/No]'
 
-        if 'help' in args.keys():
+        if 'help' in list(args.keys()):
             self.help_msg = args['help']
         else:
             self.help_msg = ''
-        if 'options' in args.keys():
+        if 'options' in list(args.keys()):
             self.opts = args['options']
 
-        if 'default' in args.keys():
+        if 'default' in list(args.keys()):
             self.default_value = args['default']
             self.prompt += ' Default is [%s]' % self.default_value
         else:
@@ -56,8 +55,8 @@ class Option(object):
 
     def check_args(self):
         if self.opt_type == 'choice':
-            if 'options' not in self.args.keys():
-                print RED("Choice option request options list!!!")
+            if 'options' not in list(self.args.keys()):
+                print(RED("Choice option request options list!!!"))
                 return False
 
             if type(self.opts) != list:
@@ -68,23 +67,23 @@ class Option(object):
     def __print_options(self):
         index = 0
         for opt in self.opts:
-            print GREEN("%2d: %s" % (index, str(opt)))
+            print(GREEN("%2d: %s" % (index, str(opt))))
             index += 1
 
     def parse_input(self):
         parse_done = False
 
-        print GREEN(self.help_msg)
+        print(GREEN(self.help_msg))
 
         while not parse_done:
             try:
                 if self.opt_type == 'choice' or self.opt_type == 'multichoice':
                     self.__print_options()
 
-                input_val = raw_input(self.prompt)
+                input_val = input(self.prompt)
                 if input_val == '':
                     input_val = self.default_value
-                    print GREEN("Chose default [%s]" % input_val)
+                    print(GREEN("Chose default [%s]" % input_val))
 
                 if self.opt_type == 'int':
                     self.value = int(input_val)
@@ -102,12 +101,12 @@ class Option(object):
                     try:
                         index = int(input_val)
                     except:
-                        print RED("Invalid option index!!!")
+                        print(RED("Invalid option index!!!"))
                         raise ValueError
 
                     if index >= len(self.opts):
-                        print RED("Choice index should be 0-%d!!!"
-                                  % len(self.opts))
+                        print(RED("Choice index should be 0-%d!!!"
+                                  % len(self.opts)))
                         raise ValueError
                     self.value = self.opts[index]
                     self.choice = index
@@ -126,8 +125,8 @@ class Option(object):
                                 start = int(indexs[0])
                                 end = int(indexs[1])
                                 if end <= start:
-                                    print RED("Choice end number must be "
-                                              "larger than start number!!!")
+                                    print(RED("Choice end number must be "
+                                              "larger than start number!!!"))
                                     raise ValueError
 
                                 for index in range(start, end + 1):
@@ -140,12 +139,12 @@ class Option(object):
                         sel_indexs = list(set(sorted(sel_indexs)))
                         for index in sel_indexs:
                             if index >= len(self.opts):
-                                print RED("Choice index should be 0-%d!!!"
-                                          % len(self.opts))
+                                print(RED("Choice index should be 0-%d!!!"
+                                          % len(self.opts)))
                             sel_options.append(self.opts[index])
                         self.value = sel_options
                     except:
-                        print RED("Invalid option!!!")
+                        print(RED("Invalid option!!!"))
                         raise ValueError
 
                 elif self.opt_type == 'ip':
@@ -158,7 +157,7 @@ class Option(object):
 
             except Exception as e:
                 if type(e) is ValueError:
-                    print "Options parse failure"
+                    print("Options parse failure")
                     continue
 
             parse_done = True
@@ -173,21 +172,21 @@ if __name__ == "__main__":
               'type': 'string', 'help': 'help message',
               'default': 'DEFAULT'}
     string_opt = Option(**option)
-    print string_opt.parse_input()
+    print(string_opt.parse_input())
     option = {'prompt': 'bool option', 'type': 'bool',
               'help': 'bool option [Yes/No] only',
               'default': 'No'}
     bool_opt = Option(**option)
-    print bool_opt.parse_input()
+    print(bool_opt.parse_input())
     option = {'prompt': 'choice option', 'type': 'choice',
               'help': 'choice option in [1, 2 ,3]',
               'options': ['option1', 'option2', 'option3'],
               'default': '0'}
     choice_opt = Option(**option)
-    print choice_opt.parse_input()
+    print(choice_opt.parse_input())
     option = {'prompt': 'multichoice option', 'type': 'multichoice',
               'help': 'mutli choice option in [1, 2 ,3]',
               'options': ['option1', 'option2', 'option3'],
               'default': '0'}
     multichoice_opt = Option(**option)
-    print multichoice_opt.parse_input()
+    print(multichoice_opt.parse_input())
diff --git a/tools/setup.py b/tools/setup.py
index c6c72bc..c0852f2 100755
--- a/tools/setup.py
+++ b/tools/setup.py
@@ -1,10 +1,9 @@
-#!/usr/bin/python
 import sys
 import os
 import parse_opt
 import re
 import time
-import ConfigParser
+import configparser
 
 exec_file = os.path.realpath(__file__)
 DTS_PATH = exec_file.replace('/tools/setup.py', '')
@@ -86,7 +85,7 @@ def config_crbs():
     global perf_execution
 
     print ('============================================================')
-    print "Setting DUT and Tester crb information"
+    print("Setting DUT and Tester crb information")
     ip_option = {'prompt': 'DUT IP address',
                  'type': 'ip',
                  'help': 'Please input ip address of DUT crb',
@@ -185,7 +184,7 @@ def load_execution(file_name):
     global suites
     global nic_type
 
-    config = ConfigParser.SafeConfigParser()
+    config = configparser.SafeConfigParser()
     config.read(file_name)
     section = config.sections()[0]
     parameters = config.get(section, 'parameters').split(':')
@@ -216,9 +215,9 @@ def config_execution():
     global nic_type
 
     print ('============================================================')
-    print "Setting execution plan"
+    print("Setting execution plan")
     if not dut_ip:
-        print RED("Need to configure 'DUT&Tester crb' first!!!")
+        print(RED("Need to configure 'DUT&Tester crb' first!!!"))
         return False
     # default execution
     driver_name = 'igb_uio'
@@ -260,7 +259,7 @@ def config_execution():
         suites = opt.parse_input()
 
     nics = ['cfg']
-    nics += NICS.keys()
+    nics += list(NICS.keys())
     nic_option = {'prompt': 'Choose one of nics',
                   'type': 'choice',
                   'help': 'Choose one of dpdk support NIC',
@@ -334,11 +333,11 @@ def config_ixia():
     global ixia_ports
 
     print ('============================================================')
-    print 'Setting IXIA port for performance validation'
+    print('Setting IXIA port for performance validation')
     ixia_ports = []
     if ixia is None or ixia == '':
-        print RED("Performance request configure IXIA group in "
-                  "'DUT&Tester crb' first!!!")
+        print(RED("Performance request configure IXIA group in "
+                  "'DUT&Tester crb' first!!!"))
         return False
 
     version_option = {'prompt': 'IXIA Server version',
@@ -408,7 +407,7 @@ def config_ports():
     print ('============================================================')
     print ("Manually configure DUT port mapping")
     if not dut_ip:
-        print RED("Need to configuure 'DUT&Tester crb' first!!!")
+        print(RED("Need to configuure 'DUT&Tester crb' first!!!"))
         return False
 
     while add_more:
@@ -420,7 +419,7 @@ def config_ports():
         dut_addr = opt.parse_input()
         m = re.match(pci_regex, dut_addr)
         if not m:
-            print RED("Pci address should follow Domain+BDF format!!!")
+            print(RED("Pci address should follow Domain+BDF format!!!"))
             continue
 
         if ixia and ixia != '':
@@ -442,7 +441,7 @@ def config_ports():
             test_addr = opt.parse_input()
             m = re.match(pci_regex, test_addr)
             if not m:
-                print RED("Pci address should follow Domain+BDF format!!!")
+                print(RED("Pci address should follow Domain+BDF format!!!"))
                 continue
 
         dut_port = {}
@@ -475,7 +474,7 @@ def write_ports_cfg():
     content += separator
 
     for port in dut_ports:
-        pci_addr = port.keys()[0]
+        pci_addr = list(port.keys())[0]
         test_addr = port[pci_addr]
         content += '    pci=%s,peer=%s;' % (pci_addr, test_addr)
         content += separator
@@ -508,7 +507,7 @@ def get_next_opt():
 
 def run_dts():
     print ('============================================================')
-    print "Ready to run DTS"
+    print("Ready to run DTS")
     git_option = {'prompt': 'Whether pull latest git code',
                   'type': 'bool',
                   'help': 'If need input "Yes", otherwise ' +
@@ -583,7 +582,7 @@ def main():
             config_done = True
             run_dts()
 
-        print GREEN("Waiting for preparation ready...")
+        print(GREEN("Waiting for preparation ready..."))
         time.sleep(2)
         get_next_opt()
 
-- 
2.17.1


  parent reply index

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-12 22:18 [dts] [next][PATCH V1 0/5] dts: modify dts " xinfengx
2020-01-12 22:18 ` [dts] [next][PATCH V1 1/5] framework: modify dts framework " xinfengx
2020-01-12 22:18 ` [dts] [next][PATCH V1 2/5] tests: modify test suites " xinfengx
2020-01-12 22:18 ` [dts] [next][PATCH V1 3/5] dep: modify dts dep " xinfengx
2020-01-12 22:18 ` [dts] [next][PATCH V1 4/5] nics: modify dts nics " xinfengx
2020-01-12 22:18 ` xinfengx [this message]
2020-01-16  5:47 ` [dts] [next][PATCH V1 0/5] dts: modify dts " Tu, Lijuan

Reply instructions:

You may reply publically 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=20200112221831.12192-6-xinfengx.zhao@intel.com \
    --to=xinfengx.zhao@intel.com \
    --cc=dts@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

test suite reviews and discussions

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/dts/0 dts/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 dts dts/ http://inbox.dpdk.org/dts \
		dts@dpdk.org
	public-inbox-index dts


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dts


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