From 62f0a3edbc311f4cc82a11363dba37469cc842dd Mon Sep 17 00:00:00 2001 From: tangkaiyuan Date: Wed, 27 Apr 2022 14:22:28 +0800 Subject: [PATCH] upgrade to python 3.x Change-Id: I4040efd6ea2dc8546f4c10c0267e3baa2f2618b2 Signed-off-by: tangkaiyuan --- ivi/inst.apk.py | 14 +++++++------- ivi/inst.wgt.py | 16 ++++++++-------- ivi/inst.xpk.py | 16 ++++++++-------- mobile/tct-behavior-tests/inst.apk.py | 18 +++++++++--------- mobile/tct-behavior-tests/inst.wgt.py | 26 +++++++++++++------------- mobile/tct-behavior-tests/inst.xpk.py | 22 +++++++++++----------- mobile/tct-behavior-tests/pack.py | 8 ++++---- tools/build/pack.py | 8 ++++---- tools/coverage/stats.py | 30 +++++++++++++++--------------- tools/xml/csv2xml.py | 8 ++++---- tools/xml/xml2csv.py | 12 ++++++------ tools/xml/xmlverifier.py | 6 +++--- tv/tct-behavior-tests/inst.apk.py | 18 +++++++++--------- tv/tct-behavior-tests/inst.wgt.py | 22 +++++++++++----------- tv/tct-behavior-tests/inst.xpk.py | 22 +++++++++++----------- tv/tct-behavior-tests/pack.py | 8 ++++---- wearable/tct-behavior-tests/inst.apk.py | 18 +++++++++--------- wearable/tct-behavior-tests/inst.wgt.py | 22 +++++++++++----------- wearable/tct-behavior-tests/inst.xpk.py | 22 +++++++++++----------- wearable/tct-behavior-tests/pack.py | 8 ++++---- 20 files changed, 162 insertions(+), 162 deletions(-) diff --git a/ivi/inst.apk.py b/ivi/inst.apk.py index 472790c..7d549d5 100755 --- a/ivi/inst.apk.py +++ b/ivi/inst.apk.py @@ -16,7 +16,7 @@ ADB_CMD = "adb" def doCMD(cmd): # Do not need handle timeout in this short script - print "-->> \"%s\"" % cmd + print ("-->> \"%s\"" % cmd) output = [] cmd_proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) @@ -27,8 +27,8 @@ def doCMD(cmd): if not cmd.endswith("&"): while True: - line = cmd_proc.stdout.readline().strip('\n') - print line + line = cmd_proc.stdout.readline().decode("UTF-8").strip('\n') + print (line) if not line or line.find("daemon started") >= 0: break output.append(line) @@ -78,8 +78,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: @@ -90,11 +90,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/ivi/inst.wgt.py b/ivi/inst.wgt.py index 989b152..8dc8654 100755 --- a/ivi/inst.wgt.py +++ b/ivi/inst.wgt.py @@ -20,7 +20,7 @@ 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_proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) @@ -31,8 +31,8 @@ def doCMD(cmd): if not cmd.endswith("&"): while True: - line = cmd_proc.stdout.readline().strip("\r\n") - print line + line = cmd_proc.stdout.readline().decode("UTF-8").strip("\r\n") + print (line) if not line or line.find("daemon started") >= 0: break output.append(line) @@ -173,8 +173,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: @@ -193,7 +193,7 @@ def main(): PARAMETERS.mode = "SSH" if not PARAMETERS.device: - print "No device provided" + print ("No device provided") sys.exit(1) user_info = getUSERID() @@ -203,10 +203,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/ivi/inst.xpk.py b/ivi/inst.xpk.py index e030f80..a43f0d0 100755 --- a/ivi/inst.xpk.py +++ b/ivi/inst.xpk.py @@ -20,7 +20,7 @@ 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_proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) @@ -31,8 +31,8 @@ def doCMD(cmd): if not cmd.endswith("&"): while True: - line = cmd_proc.stdout.readline().strip("\r\n") - print line + line = cmd_proc.stdout.readline().decode("UTF-8").strip("\r\n") + print (line) if not line or line.find("daemon started") >= 0: break output.append(line) @@ -173,8 +173,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: @@ -193,7 +193,7 @@ def main(): PARAMETERS.mode = "SSH" if not PARAMETERS.device: - print "No device provided" + print ("No device provided") sys.exit(1) user_info = getUSERID() @@ -203,10 +203,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/mobile/tct-behavior-tests/inst.apk.py b/mobile/tct-behavior-tests/inst.apk.py index 56e4343..d153a9f 100755 --- a/mobile/tct-behavior-tests/inst.apk.py +++ b/mobile/tct-behavior-tests/inst.apk.py @@ -6,8 +6,8 @@ import glob import time import sys import subprocess -from optparse import OptionParser, make_option -import ConfigParser +from optparse import OptionParser, make_option +import configparser SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -17,7 +17,7 @@ ADB_CMD = "adb" def doCMD(cmd): # Do not need handle timeout in this short script - print "-->> \"%s\"" % cmd + print ("-->> \"%s\"" % cmd) output = [] cmd_proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) @@ -28,8 +28,8 @@ def doCMD(cmd): if not cmd.endswith("&"): while True: - line = cmd_proc.stdout.readline().strip('\n') - print line + line = cmd_proc.stdout.readline().decode("UTF-8").strip('\n') + print (line) if not line or line.find("daemon started") >= 0: break output.append(line) @@ -79,8 +79,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: @@ -91,11 +91,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/mobile/tct-behavior-tests/inst.wgt.py b/mobile/tct-behavior-tests/inst.wgt.py index 16446ab..d83b611 100755 --- a/mobile/tct-behavior-tests/inst.wgt.py +++ b/mobile/tct-behavior-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) @@ -40,10 +40,10 @@ def getInternalStorage(): shell_mgr.write_cmd('export `tzplatform-get --user ' +PARAMETERS.user+' TZ_USER_CONTENT`', '', None) INTERNAL_STORAGE=shell_mgr.write_cmd('echo $TZ_USER_CONTENT','', None) INTERNAL_STORAGE=str(INTERNAL_STORAGE[len(INTERNAL_STORAGE)-1]) - print str(INTERNAL_STORAGE) + print (str(INTERNAL_STORAGE)) except Exception as ex: - print ex + print (ex) finally: shell_mgr.close_shellpipe() @@ -53,7 +53,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)): @@ -65,7 +65,7 @@ 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_proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) @@ -76,8 +76,8 @@ def doCMD(cmd): if not cmd.endswith("&"): while True: - line = cmd_proc.stdout.readline().strip("\r\n") - print line + line = cmd_proc.stdout.readline().decode("UTF-8").strip("\r\n") + print (line) if not line or line.find("daemon started") >= 0: break output.append(line) @@ -218,8 +218,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: @@ -238,7 +238,7 @@ def main(): PARAMETERS.mode = "SSH" if not PARAMETERS.device: - print "No device provided" + print ("No device provided") sys.exit(1) userCheck() @@ -250,10 +250,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/mobile/tct-behavior-tests/inst.xpk.py b/mobile/tct-behavior-tests/inst.xpk.py index 1c47cca..0861d7a 100755 --- a/mobile/tct-behavior-tests/inst.xpk.py +++ b/mobile/tct-behavior-tests/inst.xpk.py @@ -7,8 +7,8 @@ import time import sys import subprocess import string -from optparse import OptionParser, make_option -import ConfigParser +from optparse import OptionParser, make_option +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,7 +24,7 @@ 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_proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) @@ -35,8 +35,8 @@ def doCMD(cmd): if not cmd.endswith("&"): while True: - line = cmd_proc.stdout.readline().strip("\r\n") - print line + line = cmd_proc.stdout.readline().decode("UTF-8").strip("\r\n") + print (line) if not line or line.find("daemon started") >= 0: break output.append(line) @@ -177,8 +177,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: @@ -197,7 +197,7 @@ def main(): PARAMETERS.mode = "SSH" if not PARAMETERS.device: - print "No device provided" + print ("No device provided") sys.exit(1) user_info = getUSERID() @@ -207,10 +207,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/mobile/tct-behavior-tests/pack.py b/mobile/tct-behavior-tests/pack.py index e29187a..f1f0cb4 100755 --- a/mobile/tct-behavior-tests/pack.py +++ b/mobile/tct-behavior-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: diff --git a/tools/build/pack.py b/tools/build/pack.py index e48cdc1..22bf5e2 100755 --- a/tools/build/pack.py +++ b/tools/build/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: diff --git a/tools/coverage/stats.py b/tools/coverage/stats.py index e10865f..10a22ab 100755 --- a/tools/coverage/stats.py +++ b/tools/coverage/stats.py @@ -4,7 +4,7 @@ import os import sys import re -import commands +import subprocess import glob import fnmatch import string @@ -14,8 +14,8 @@ from optparse import OptionParser def iterfindfiles (path, fnexp): for root, dirs, files in os.walk(path): - for filename in fnmatch.filter(files, fnexp): - yield os.path.join(root, filename) + for filename in fnmatch.filter(files, fnexp): + yield os.path.join(root, filename) def count_upstream (string = None, str_entry=None ): if string.find('/%s/' % str_entry) >= 0: @@ -94,9 +94,9 @@ def analy_test_file(file_path = None): p3_auto_webdriver += 1*subcase else: p3_manual += 1*subcase - except Exception, e: - print "Got error when analy test files: %s" % e - print file_path + except Exception as e: + print ("Got error when analy test files: %s" % e) + print (file_path) p0_number = p0_auto + p0_manual p1_number = p1_auto + p1_manual @@ -125,8 +125,8 @@ def get_upstream(file_path): n_upstream += 1 if element not in exist_upstream : exist_upstream.append(element) - except Exception, e: - print e + except Exception as e: + print (e) upstream = "" for element in exist_upstream: @@ -151,8 +151,8 @@ def get_case_status(file_path): fp.write(content) fp.write("\n") fp.close() - except Exception, e: - print "Got error when get case status: %s" % e + except Exception as e: + print ("Got error when get case status: %s" % e) def init_result_file(): title = "Suite_name,Total,Total_auto,Total_auto_webdriver,Total_manual,P0,P0_auto,P0_auto_webdriver,P0_manual,P1,P1_auto,\ @@ -166,8 +166,8 @@ Integrated_Upstream_TCs,Upstream_Resource" fp.write(title) fp.write("\n") fp.close() - except Exception, e: - print "Got error when init analy file : %s" % e + except Exception as e: + print ("Got error when init analy file : %s" % e) def main(): try: @@ -184,7 +184,7 @@ def main(): init_result_file() if len(sys.argv) == 1: - sys.argv.append("-h") + sys.argv.append("-h") (PARAMETERS, args) = opts_parser.parse_args() if PARAMETERS.suitesdir: for filename in iterfindfiles("%s" % PARAMETERS.suitesdir, "tests.full.xml"): @@ -193,8 +193,8 @@ def main(): if PARAMETERS.xmlfile: get_case_status(PARAMETERS.xmlfile) except Exception as e: - print "Got error: %s, exit" % e + print ("Got error: %s, exit" % e) if __name__ == '__main__': - main() + main() diff --git a/tools/xml/csv2xml.py b/tools/xml/csv2xml.py index 4447e4d..bdfdb20 100755 --- a/tools/xml/csv2xml.py +++ b/tools/xml/csv2xml.py @@ -65,11 +65,11 @@ class ColorFormatter(logging.Formatter): def csv2full(csv_path, split_sign): if not os.path.isfile(csv_path): - print '%s is not a file' % csv_path + print ('%s is not a file' % csv_path) return name, ext = os.path.splitext(csv_path) if not ext == '.csv': - print '%s is not a csv' % csv_path + print ('%s is not a csv' % csv_path) return LOG.info("+Convert csv to xml start ...") csv_file = file(csv_path, 'rb') @@ -139,7 +139,7 @@ def echo_about(): This function will print the user guide and stop toolkit. """ about = 'csv2xml V1.0\n-c | Convert csv file to tests.full.xml and tests.xml\n' - print about + print (about) sys.exit() def main(): @@ -161,7 +161,7 @@ def main(): elif sys_name == 'Linux': split_sign = '/' if len(sys.argv) != 3: - print 'Error: No enough argv!' + print ('Error: No enough argv!') echo_about() else: {'-c': lambda : csv2full(sys.argv[2], split_sign)}[sys.argv[1]]() diff --git a/tools/xml/xml2csv.py b/tools/xml/xml2csv.py index 07de9c3..5a6d3ba 100755 --- a/tools/xml/xml2csv.py +++ b/tools/xml/xml2csv.py @@ -65,16 +65,16 @@ class ColorFormatter(logging.Formatter): def xml2csv(xml_path, split_sign): if not os.path.isfile(xml_path): - print '%s is not a file' % xml_path + print ('%s is not a file' % xml_path) return name, ext = os.path.splitext(xml_path) if not ext == '.xml': - print '%s is not a xml' % xml_path + print ('%s is not a xml' % xml_path) return if not name.split(split_sign)[-1] == 'tests.full': - print name - print '%s is not tests.full.xml' % xml_path + print (name) + print ('%s is not tests.full.xml' % xml_path) return LOG.info("+Convert xml to csv start ...") folder = os.path.dirname(xml_path) @@ -152,7 +152,7 @@ def echo_about(): This function will print the user guide and stop toolkit. """ about = 'xml2csv V1.0\n-c | Convert tests.full.xml to csv file\n' - print about + print (about) sys.exit() def main(): @@ -174,7 +174,7 @@ def main(): elif sys_name == 'Linux': split_sign = '/' if len(sys.argv) != 3: - print 'Error: No enough argv!' + print ('Error: No enough argv!') echo_about() else: { diff --git a/tools/xml/xmlverifier.py b/tools/xml/xmlverifier.py index 4165ec9..9794b2c 100755 --- a/tools/xml/xmlverifier.py +++ b/tools/xml/xmlverifier.py @@ -72,7 +72,7 @@ def verify_xml(xml_dir, split_sign): else: name, ext = os.path.splitext(xml_dir) if not ext == '.xml': - print '%s is not a xml' % xml_path + print ('%s is not a xml' % xml_path) return else: verify_path(xml_dir, split_sign) @@ -143,7 +143,7 @@ def echo_about(): This function will print the user guide and stop toolkit. """ about = 'xmlverifier V1.0\n-v | Verify case path, id, purpose and set type are right\n' - print about + print (about) sys.exit() def main(): @@ -165,7 +165,7 @@ def main(): elif sys_name == 'Linux': split_sign = '/' if len(sys.argv) != 3: - print 'Error: No enough argv!' + print ('Error: No enough argv!') echo_about() else: {'-v': lambda : verify_xml(sys.argv[2], split_sign)}[sys.argv[1]]() diff --git a/tv/tct-behavior-tests/inst.apk.py b/tv/tct-behavior-tests/inst.apk.py index 56e4343..d153a9f 100755 --- a/tv/tct-behavior-tests/inst.apk.py +++ b/tv/tct-behavior-tests/inst.apk.py @@ -6,8 +6,8 @@ import glob import time import sys import subprocess -from optparse import OptionParser, make_option -import ConfigParser +from optparse import OptionParser, make_option +import configparser SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -17,7 +17,7 @@ ADB_CMD = "adb" def doCMD(cmd): # Do not need handle timeout in this short script - print "-->> \"%s\"" % cmd + print ("-->> \"%s\"" % cmd) output = [] cmd_proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) @@ -28,8 +28,8 @@ def doCMD(cmd): if not cmd.endswith("&"): while True: - line = cmd_proc.stdout.readline().strip('\n') - print line + line = cmd_proc.stdout.readline().decode("UTF-8").strip('\n') + print (line) if not line or line.find("daemon started") >= 0: break output.append(line) @@ -79,8 +79,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: @@ -91,11 +91,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/tv/tct-behavior-tests/inst.wgt.py b/tv/tct-behavior-tests/inst.wgt.py index 2b1ecaa..5e3a0aa 100755 --- a/tv/tct-behavior-tests/inst.wgt.py +++ b/tv/tct-behavior-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)): @@ -48,7 +48,7 @@ def askpolicyremoving(): return doCMD(cmd) def doCMD(cmd): # Do not need handle timeout in this short script, let tool do it - print "-->> \"%s\"" % cmd + print ("-->> \"%s\"" % cmd) output = [] cmd_proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) @@ -59,8 +59,8 @@ def doCMD(cmd): if not cmd.endswith("&"): while True: - line = cmd_proc.stdout.readline().strip("\r\n") - print line + line = cmd_proc.stdout.readline().decode("UTF-8").strip("\r\n") + print (line) if not line or line.find("daemon started") >= 0: break output.append(line) @@ -201,8 +201,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: @@ -221,7 +221,7 @@ def main(): PARAMETERS.mode = "SSH" if not PARAMETERS.device: - print "No device provided" + print ("No device provided") sys.exit(1) userCheck() @@ -233,10 +233,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/tv/tct-behavior-tests/inst.xpk.py b/tv/tct-behavior-tests/inst.xpk.py index 1c47cca..0861d7a 100755 --- a/tv/tct-behavior-tests/inst.xpk.py +++ b/tv/tct-behavior-tests/inst.xpk.py @@ -7,8 +7,8 @@ import time import sys import subprocess import string -from optparse import OptionParser, make_option -import ConfigParser +from optparse import OptionParser, make_option +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,7 +24,7 @@ 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_proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) @@ -35,8 +35,8 @@ def doCMD(cmd): if not cmd.endswith("&"): while True: - line = cmd_proc.stdout.readline().strip("\r\n") - print line + line = cmd_proc.stdout.readline().decode("UTF-8").strip("\r\n") + print (line) if not line or line.find("daemon started") >= 0: break output.append(line) @@ -177,8 +177,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: @@ -197,7 +197,7 @@ def main(): PARAMETERS.mode = "SSH" if not PARAMETERS.device: - print "No device provided" + print ("No device provided") sys.exit(1) user_info = getUSERID() @@ -207,10 +207,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/tv/tct-behavior-tests/pack.py b/tv/tct-behavior-tests/pack.py index e29187a..f1f0cb4 100755 --- a/tv/tct-behavior-tests/pack.py +++ b/tv/tct-behavior-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: diff --git a/wearable/tct-behavior-tests/inst.apk.py b/wearable/tct-behavior-tests/inst.apk.py index 56e4343..d153a9f 100755 --- a/wearable/tct-behavior-tests/inst.apk.py +++ b/wearable/tct-behavior-tests/inst.apk.py @@ -6,8 +6,8 @@ import glob import time import sys import subprocess -from optparse import OptionParser, make_option -import ConfigParser +from optparse import OptionParser, make_option +import configparser SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -17,7 +17,7 @@ ADB_CMD = "adb" def doCMD(cmd): # Do not need handle timeout in this short script - print "-->> \"%s\"" % cmd + print ("-->> \"%s\"" % cmd) output = [] cmd_proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) @@ -28,8 +28,8 @@ def doCMD(cmd): if not cmd.endswith("&"): while True: - line = cmd_proc.stdout.readline().strip('\n') - print line + line = cmd_proc.stdout.readline().decode("UTF-8").strip('\n') + print (line) if not line or line.find("daemon started") >= 0: break output.append(line) @@ -79,8 +79,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: @@ -91,11 +91,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/wearable/tct-behavior-tests/inst.wgt.py b/wearable/tct-behavior-tests/inst.wgt.py index 1e80823..da2a425 100755 --- a/wearable/tct-behavior-tests/inst.wgt.py +++ b/wearable/tct-behavior-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,7 +49,7 @@ 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_proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) @@ -60,8 +60,8 @@ def doCMD(cmd): if not cmd.endswith("&"): while True: - line = cmd_proc.stdout.readline().strip("\r\n") - print line + line = cmd_proc.stdout.readline().decode("UTF-8").strip("\r\n") + print (line) if not line or line.find("daemon started") >= 0: break output.append(line) @@ -202,8 +202,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: @@ -222,7 +222,7 @@ def main(): PARAMETERS.mode = "SSH" if not PARAMETERS.device: - print "No device provided" + print ("No device provided") sys.exit(1) userCheck() @@ -234,10 +234,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/wearable/tct-behavior-tests/inst.xpk.py b/wearable/tct-behavior-tests/inst.xpk.py index 1c47cca..0861d7a 100755 --- a/wearable/tct-behavior-tests/inst.xpk.py +++ b/wearable/tct-behavior-tests/inst.xpk.py @@ -7,8 +7,8 @@ import time import sys import subprocess import string -from optparse import OptionParser, make_option -import ConfigParser +from optparse import OptionParser, make_option +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,7 +24,7 @@ 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_proc = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) @@ -35,8 +35,8 @@ def doCMD(cmd): if not cmd.endswith("&"): while True: - line = cmd_proc.stdout.readline().strip("\r\n") - print line + line = cmd_proc.stdout.readline().decode("UTF-8").strip("\r\n") + print (line) if not line or line.find("daemon started") >= 0: break output.append(line) @@ -177,8 +177,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: @@ -197,7 +197,7 @@ def main(): PARAMETERS.mode = "SSH" if not PARAMETERS.device: - print "No device provided" + print ("No device provided") sys.exit(1) user_info = getUSERID() @@ -207,10 +207,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/wearable/tct-behavior-tests/pack.py b/wearable/tct-behavior-tests/pack.py index e29187a..f1f0cb4 100755 --- a/wearable/tct-behavior-tests/pack.py +++ b/wearable/tct-behavior-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: -- 2.7.4