From: chen Date: Thu, 26 May 2022 06:35:48 +0000 (+0800) Subject: [common][mltrain][upgrade mltrain to python3x] X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f084bde63d3bf279cb625ac6cb0de99ae259daac;p=test%2Ftct%2Fweb%2Fapi.git [common][mltrain][upgrade mltrain to python3x] Change-Id: Ia747b345e46a5b4e26f07ca56485c2d38da63858 Signed-off-by: chen --- diff --git a/common/tct-mltrain-tizen-tests/inst.apk.py b/common/tct-mltrain-tizen-tests/inst.apk.py index d5f9fbb96..d636bee03 100755 --- a/common/tct-mltrain-tizen-tests/inst.apk.py +++ b/common/tct-mltrain-tizen-tests/inst.apk.py @@ -7,7 +7,7 @@ import time import sys import subprocess from optparse import OptionParser, make_option -import ConfigParser +import configparser SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -17,14 +17,14 @@ ADB_CMD = "adb" def doCMD(cmd): # Do not need handle timeout in this short script, let tool do it - print "-->> \"%s\"" % cmd + print ("-->> \"%s\"" % cmd) output = [] cmd_return_code = 1 cmd_proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) while True: - output_line = cmd_proc.stdout.readline().strip("\r\n") + output_line = cmd_proc.stdout.readline().decode("UTF-8").strip("\r\n") cmd_return_code = cmd_proc.poll() if output_line == '' and cmd_return_code != None: break @@ -77,8 +77,8 @@ def main(): "-u", dest="buninstpkg", action="store_true", help="Uninstall package") global PARAMETERS (PARAMETERS, args) = opts_parser.parse_args() - except Exception, e: - print "Got wrong option: %s, exit ..." % e + except Exception as e: + print ("Got wrong option: %s, exit ..." % e) sys.exit(1) if not PARAMETERS.device: @@ -89,11 +89,11 @@ def main(): break if not PARAMETERS.device: - print "No device found" + print ("No device found") sys.exit(1) if PARAMETERS.binstpkg and PARAMETERS.buninstpkg: - print "-i and -u are conflict" + print ("-i and -u are conflict") sys.exit(1) if PARAMETERS.buninstpkg: diff --git a/common/tct-mltrain-tizen-tests/inst.wgt.py b/common/tct-mltrain-tizen-tests/inst.wgt.py index aa684ed0c..7a5f5ec09 100755 --- a/common/tct-mltrain-tizen-tests/inst.wgt.py +++ b/common/tct-mltrain-tizen-tests/inst.wgt.py @@ -8,7 +8,7 @@ import sys import subprocess import string from optparse import OptionParser, make_option -import ConfigParser +import configparser SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -16,7 +16,7 @@ PKG_NAME = os.path.basename(SCRIPT_DIR) PARAMETERS = None #XW_ENV = "export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/5000/dbus/user_bus_socket" TCT_CONFIG_FILE = "/opt/tools/TCT_CONFIG" -tct_parser = ConfigParser.ConfigParser() +tct_parser = configparser.ConfigParser() tct_parser.read(TCT_CONFIG_FILE) SRC_DIR = tct_parser.get('DEVICE', 'DEVICE_SUITE_TARGET_30') PKG_SRC_DIR = "%s/tct/opt/%s" % (SRC_DIR, PKG_NAME) @@ -37,7 +37,7 @@ def askpolicyremoving(): if file.endswith(".wgt"): pkg_id = getPKGID(os.path.basename(os.path.splitext(file)[0])) - print pkg_id + print (pkg_id) print (os.getcwd()) print (os.path.dirname(os.path.realpath(__file__)) ) if not doRemoteCopy("%s/askpolicy.sh" % SCRIPT_DIR, "%s" % (SRC_DIR)): @@ -49,14 +49,14 @@ def askpolicyremoving(): def doCMD(cmd): # Do not need handle timeout in this short script, let tool do it - print "-->> \"%s\"" % cmd + print ("-->> \"%s\"" % cmd) output = [] cmd_return_code = 1 cmd_proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) while True: - output_line = cmd_proc.stdout.readline().strip("\r\n") + output_line = cmd_proc.stdout.readline().decode("UTF-8").strip("\r\n") cmd_return_code = cmd_proc.poll() if output_line == '' and cmd_return_code != None: break @@ -183,7 +183,7 @@ def instPKGs(): action_status = False if not doRemoteCopy("%s/media/*" % SCRIPT_DIR, "%s/Documents" % SRC_DIR): - action_status = False + action_status = False for item in glob.glob("%s/*" % SCRIPT_DIR): if item.endswith(".wgt"): continue @@ -213,8 +213,8 @@ def main(): "-a", dest="user", action="store", help="User name") global PARAMETERS (PARAMETERS, args) = opts_parser.parse_args() - except Exception, e: - print "Got wrong option: %s, exit ..." % e + except Exception as e: + print ("Got wrong option: %s, exit ..." % e) sys.exit(1) if not PARAMETERS.user: @@ -233,7 +233,7 @@ def main(): PARAMETERS.mode = "SSH" if not PARAMETERS.device: - print "No device provided" + print ("No device provided") sys.exit(1) userCheck() @@ -245,10 +245,10 @@ def main(): userid = user_info[1][0] XW_ENV = "export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/%s/dbus/user_bus_socket"%str(userid) else: - print "[Error] cmd commands error : %s"%str(user_info[1]) + print ("[Error] cmd commands error : %s" % str(user_info[1])) sys.exit(1) if PARAMETERS.binstpkg and PARAMETERS.buninstpkg: - print "-i and -u are conflict" + print ("-i and -u are conflict") sys.exit(1) if PARAMETERS.buninstpkg: diff --git a/common/tct-mltrain-tizen-tests/inst.xpk.py b/common/tct-mltrain-tizen-tests/inst.xpk.py index f70351a9b..ace8cbba9 100755 --- a/common/tct-mltrain-tizen-tests/inst.xpk.py +++ b/common/tct-mltrain-tizen-tests/inst.xpk.py @@ -8,7 +8,7 @@ import sys import subprocess import string from optparse import OptionParser, make_option -import ConfigParser +import configparser SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -16,7 +16,7 @@ PKG_NAME = os.path.basename(SCRIPT_DIR) PARAMETERS = None #XW_ENV = "export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/5000/dbus/user_bus_socket" TCT_CONFIG_FILE = "/opt/tools/TCT_CONFIG" -tct_parser = ConfigParser.ConfigParser() +tct_parser = configparser.ConfigParser() tct_parser.read(TCT_CONFIG_FILE) SRC_DIR = tct_parser.get('DEVICE', 'DEVICE_SUITE_TARGET_30') PKG_SRC_DIR = "%s/tct/opt/%s" % (SRC_DIR, PKG_NAME) @@ -24,14 +24,14 @@ PKG_SRC_DIR = "%s/tct/opt/%s" % (SRC_DIR, PKG_NAME) def doCMD(cmd): # Do not need handle timeout in this short script, let tool do it - print "-->> \"%s\"" % cmd + print ("-->> \"%s\"" % cmd) output = [] cmd_return_code = 1 cmd_proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) while True: - output_line = cmd_proc.stdout.readline().strip("\r\n") + output_line = cmd_proc.stdout.readline().decode("UTF-8").strip("\r\n") cmd_return_code = cmd_proc.poll() if output_line == '' and cmd_return_code != None: break @@ -183,8 +183,8 @@ def main(): "-a", dest="user", action="store", help="User name") global PARAMETERS (PARAMETERS, args) = opts_parser.parse_args() - except Exception, e: - print "Got wrong option: %s, exit ..." % e + except Exception as e: + print ("Got wrong option: %s, exit ..." % e) sys.exit(1) if not PARAMETERS.user: @@ -203,7 +203,7 @@ def main(): PARAMETERS.mode = "SSH" if not PARAMETERS.device: - print "No device provided" + print ("No device provided") sys.exit(1) user_info = getUSERID() @@ -213,10 +213,10 @@ def main(): userid = user_info[1][0] XW_ENV = "export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/%s/dbus/user_bus_socket"%str(userid) else: - print "[Error] cmd commands error : %s"%str(user_info[1]) + print ("[Error] cmd commands error : %s" % str(user_info[1])) sys.exit(1) if PARAMETERS.binstpkg and PARAMETERS.buninstpkg: - print "-i and -u are conflict" + print ("-i and -u are conflict") sys.exit(1) if PARAMETERS.buninstpkg: diff --git a/common/tct-mltrain-tizen-tests/pack.py b/common/tct-mltrain-tizen-tests/pack.py index e29187a0b..f1f0cb470 100755 --- a/common/tct-mltrain-tizen-tests/pack.py +++ b/common/tct-mltrain-tizen-tests/pack.py @@ -40,10 +40,10 @@ import logging import zipfile import signal import subprocess +import imp from optparse import OptionParser -reload(sys) -sys.setdefaultencoding('utf8') +imp.reload(sys) TOOL_VERSION = "v0.1" VERSION_FILE = "VERSION" @@ -363,7 +363,7 @@ def doCMDWithOutput(cmd, time_out=DEFAULT_CMD_TIMEOUT): cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) while True: - output_line = cmd_proc.stdout.readline().strip("\r\n") + output_line = cmd_proc.stdout.readline().decode("UTF-8").strip("\r\n") cmd_return_code = cmd_proc.poll() elapsed_time = time.time() - pre_time if cmd_return_code is None: @@ -938,7 +938,7 @@ def main(): sys.exit(1) if BUILD_PARAMETERS.bversion: - print "Version: %s" % TOOL_VERSION + LOG.info("Version: %s" % TOOL_VERSION) sys.exit(0) if not BUILD_PARAMETERS.srcdir: