From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DE8E8A04F0; Mon, 13 Jan 2020 08:38:59 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CDAD11D607; Mon, 13 Jan 2020 08:38:59 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 6D0D01D627 for ; Mon, 13 Jan 2020 08:38:57 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jan 2020 23:38:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,428,1571727600"; d="scan'208";a="397082438" Received: from unknown (HELO dpdk-xinfengx-dut.sh.intel.com) ([10.67.117.16]) by orsmga005.jf.intel.com with ESMTP; 12 Jan 2020 23:38:56 -0800 From: xinfengx To: dts@dpdk.org Cc: xinfengx Date: Mon, 13 Jan 2020 06:18:31 +0800 Message-Id: <20200112221831.12192-6-xinfengx.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200112221831.12192-1-xinfengx.zhao@intel.com> References: <20200112221831.12192-1-xinfengx.zhao@intel.com> Subject: [dts] [next][PATCH V1 5/5] tools: modify dts tools to support python3 X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dts-bounces@dpdk.org Sender: "dts" Signed-off-by: xinfengx --- 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