def cancleinstall_through_setting(self, sn): ''' :param sn: :param flag: :return: ''' try: co.reboot_device(sn) time.sleep(5) if co.wait_hu_recovery(sn) == 0: if co.cancleinstall_through_setting(sn, SL.ActiveUpgrade) == 0: return 0 else: logger.log_error("cancle upgrade failed", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 else: logger.log_error("wait hu recovery fail",\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 except Exception as e: logger.log_error("%s" %(e),\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1
def check_reboot_and_enter_installui_and_cancle(self, sn): ''' :param sn: :param flag: :return: ''' try: co.reboot_device(sn) time.sleep(5) if co.wait_hu_recovery(sn) == 0: if co.alway_send_signal(sn, SL.ActiveUpgrade) == 0: if co.cancle_install_through_ui(sn) == 0: return 0 else : return 1 else: logger.log_error("can not find install ui", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 else: logger.log_error("wait hu recovery fail",\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 except Exception as e: logger.log_error("%s" %(e),\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1
def check_reboot_and_enter_installui(self, sn): ''' :param sn: :param flag: :return: ''' try: # co.reboot_device(sn) co.reboot_device(sn) # co.wait_hu_recovery(sn) time.sleep(5) if co.wait_hu_recovery(sn) == 0: if co.alway_send_signal(sn, SL.ActiveUpgrade) == 0: return 0 else: pcan = SC.PCAN() pcan.poweron_and_clean() return 1 else: logger.log_error("wait hu recovery fail", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 except Exception as e: logger.log_error("%s" % (e), \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1
def current_mcu_and_mpu_size(self, sn, flag): try: if self.get_mcu_and_mpu_name(sn, flag) != 'None': if flag == mcu_flag: str_msg = "ls -al %s/%s |%s awk '{print $5}'" % ( tbox_mcu, self.get_mcu_and_mpu_name(sn, flag), busybox) elif flag == mpu_flag: str_msg = "ls -al %s/%s |%s awk '{print $5}'" % ( tbox_mpu, self.get_mcu_and_mpu_name(sn, flag), busybox) cmd = 'adb -s %s shell "%s"' % (sn, str_msg) if int(co.removal(subprocess.check_output(cmd)).strip()) >= 0: logger.log_debug("has downloaded %s package size: %s" % (flag,co.removal(subprocess.check_output(cmd))), \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return co.removal(subprocess.check_output(cmd)).strip() else: logger.log_debug("can not find package size ,may be has download well", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 else: logger.log_error("can not find %s name" %(flag),sys._getframe().f_code.co_filename, \ sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 except Exception as e: logger.log_error("%s" %e,sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,\ sys._getframe().f_lineno) return 1
def get_requestdata_to_file(self, sn): ''' request json file :param sn: :return: ''' try: global logcat_object logcat_object = co.Set_Logcat_Message(sn) filelist = package.update_fota_package() platform_information.set_device("tbox") platform_information.set_vin_version(filelist[5]) platform_information.set_sw_version_new(filelist[7]) platform_information.set_sw_version_old(filelist[7]) platform_information.set_mcu_version(filelist[8]) data_json = platform_information.temporary_get_port_data(platform_information.get_vin_version(), platform_information.get_device(), \ platform_information.get_sw_version_old(),\ platform_information.get_mcu_version()) header = platform_information.get_header( platform_information.get_vin_version()) # print(header) # print(data_json) co.post_request(sn, header, data_json) return co.post_request_to_file(sn, header, data_json) except Exception as e: logger.log_error("%s" % (e), sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1
def check_break_point_resume_tbox(self, sn, flag): ''' funciton: break point resume through disable/enable network :param sn: :return: ''' funlist = [co.disable_network,co.enable_network] co.delete_file(sn) time.sleep(5) value_list = [] # package.flash_through_system(sn) try: if package.update_system_through_fastboot(retry_times) == 0 and co.start_fota_daemon(sn) == 0: # if co.start_fota_daemon(sn) == 0: time.sleep(5) if self.get_requestdata_to_file(sn) == 1: logger.log_error("may be has no network",\ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 expect_size = int(co.get_packagesize_from_json_file(sn,flag)) while True: actual_size = co.check_package_size(sn,flag) logger.log_info("current actual download size is :%s\n\t\texpect download size is :%s" %(actual_size,expect_size),\ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) value_list.append(int(actual_size)) if actual_size is not None and int(actual_size) < expect_size: for fun in funlist: if fun(sn): time.sleep(random.randint(60,100)) elif actual_size is None : return 1 if int(actual_size) == expect_size: logger.log_info("check break point resume with network successfully",\ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 0 if len(value_list) >= 5: i = 0 while i <= len(value_list) - 2: if value_list[i] == value_list[i + 1]: i = i + 1 else: break if i == len(value_list) - 1: logger.error("package size can not change,and package always is :%s" %(actual_size), \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno ) return 1 else: logger.log_error("flash system failed or start fota module failed", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 except Exception as e: logger.log_error("%s" %(e),\ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1
def check_install_and_sendsignal(self, sn, flag): ''' function: check active upgrade :param sn: :return: ''' co.delete_file(sn) time.sleep(5) # package.flash_through_system(sn) try: if package.update_system_through_fastboot(retry_times) == 0 and co.start_fota_daemon(sn) == 0: # if co.start_fota_daemon(sn) == 0: time.sleep(5) if self.get_requestdata_to_file(sn) == 1: logger.log_error("maybe has no network",\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 if co.check_package_exist(sn,flag) == 0: try: expect_size = int(co.get_packagesize_from_json_file(sn,flag)) while True: actual_size = co.check_package_size(sn,flag,30) if int(actual_size) == expect_size: break if co.send_signal(sn, SL.ActiveUpgrade) == 0: time.sleep(20) if co.wait_hu_recovery(sn) == 0: if self.check_system_version(sn) == 0: if co.alway_send_signal(sn,SL.ActiveUpgrade) == 1: return 0 else: logger.log_error("expect no ui show,but ui has show",\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 else: return 1 else: logger.log_error("can not enter system",\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 else: return 1 except Exception as e: logger.log_error("%s" %(e),\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 else: logger.log_error("can not find pakcage",\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 else: return 1 except Exception as e: logger.log_error("%s" %(e),\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1
def upgrade_through_setting(self, sn, flag): co.delete_file(sn) time.sleep(5) try: if package.update_system_through_fastboot(retry_times) == 0 and co.start_fota_daemon(sn) == 0: # if co.start_fota_daemon(sn) == 0: time.sleep(5) if self.get_requestdata_to_file(sn) == 1: logger.log_error("maybe has no network", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 if co.check_package_exist(sn, flag) == 0: try: expect_size = int(co.get_packagesize_from_json_file(sn, flag)) while True: actual_size = co.check_package_size(sn, flag, 30) if int(actual_size) == expect_size: break if co.activeupgrade_through_setting(sn, SL.ActiveUpgrade) == 0: time.sleep(20) if co.wait_hu_recovery(sn) == 0: if self.check_system_version(sn) == 0: pcan = SC.PCAN() pcan.poweron_and_clean() return 0 else: pcan = SC.PCAN() pcan.poweron_and_clean() return 1 else: pcan = SC.PCAN() pcan.poweron_and_clean() logger.log_error("can not enter system", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 else: pcan = SC.PCAN() pcan.poweron_and_clean() return 1 except Exception as e: logger.log_error("%s" % (e), \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 else: logger.log_error("can not find pakcage", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 else: return 1 except Exception as e: logger.log_error("%s" % (e), \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1
def test(): logger.log_info("start tbox active upgrade test", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) co.ADB_SN().check_adb_device_isalive() sn = tbox_common.check_sn_status() count_pass = 0 count_fail = 0 Result = tbox_common.check_activeupgrade(sn, "mcu", "mpu") if Result == 0: count_pass = count_pass + 1 logger.Current_Result(count_fail + count_pass, count_pass, count_fail, os.path.basename(__file__).strip('.py')) return 0 elif Result == 1: co.ADB_SN().check_adb_device_isalive() co.open_tbox_adb() time.sleep(10) tb_c.Tbox_Information.modify_tbox_config(sn) count_fail = count_fail + 1 scp = co.Set_Screencap_Message(sn) # co.Get_Logcat_Message(sn, co.logcat_object) co.Get_Screencap_Message(sn, scp) co.Get_libHU_Message(sn) logger.Current_Result(count_fail + count_pass, count_pass, count_fail, os.path.basename(__file__).strip('.py')) return 1
def check_package_upgradeprogress(self,sn,flag): ''' function:check full package upgrade progress :param sn: :param flag: :return: ''' co.delete_file(sn) time.sleep(5) try: # package.flash_through_system(sn) if package.update_system_through_fastboot(retry_times) == 0 and co.start_fota_daemon(sn) == 0: # if co.start_fota_daemon(sn) == 0: time.sleep(5) if self.get_requestdata_to_file(sn) == 1: logger.log_error("may be has not network", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 if co.check_package_exist(sn,flag) == 0: time.sleep(5) if package.check_download_progress(sn,flag) == 0 and self.check_libHu_fota(sn): time.sleep(5) co.reboot_device(sn) time.sleep(2) co.wait_hu_recovery(sn) if self.check_system_version(sn) == 0: logger.log_info("upgrade system success",\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 0 elif self.check_system_version(sn) == 1: logger.log_error("upgrade system failed",\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 else: logger.log_error("download failed or install failed",\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 else: logger.log_error("can not find %s" %(co.get_packagename_from_json_file(sn,flag)),\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 else: logger.log_error("flash system failed or start fota module failed",\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 except Exception as e: logger.log_error("%s" %(e),\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1
def check_delete_updatedirectory(self, sn, flag): ''' function: check delete /update directory and reboot system :param sn: :return: ''' try: if package.update_system_through_fastboot(retry_times) == 0 and co.start_fota_daemon(sn) == 0: # if co.start_fota_daemon(sn) == 0: time.sleep(5) if self.get_requestdata_to_file(sn) == 1: logger.log_error("maybe has no network",\ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 if co.check_package_exist(sn, flag) == 0: expect_size = int(co.get_packagesize_from_json_file(sn, flag)) while True: actual_size = co.check_package_size(sn, flag, 30) if int(actual_size) == expect_size: break while True: if check_message.check_libHUfota_exist(sn): time.sleep(random.randint(5,10)) co.delete_file(sn) time.sleep(random.randint(5,10)) co.reboot_device(sn) return co.wait_hu_recovery(sn) else : logger.log_error("can not find libHUfota log", \ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 else: logger.log_error("check delete updated directory failed",\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 else: logger.log_error("flash system failed or start fota module failed", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 except Exception as e: logger.log_error("%s" %(e),\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1
def get_mcu_and_mpu_size(self, sn, flag, delay_time=300): ''' get mcu and mpu size :param flag: :return: ''' if flag == mpu_flag: # print("antony@@@debug") str_msg = "%s sed 's/.*file_size.\{2\}\([0-9]*\).*file_size.*/\\1/' %s" % ( busybox, json_name) elif flag == mcu_flag: str_msg = "%s sed 's/.*file_size.*file_size.\{2\}\([0-9]*\).*/\\1/' %s" % ( busybox, json_name) cmd = 'adb -s %s shell "if [ -f %s ]; then %s;fi"' % (sn, json_name, str_msg) while True: try: if co.removal(subprocess.check_output(cmd)): logger.log_debug("will download %s package name is %s" % (flag,co.removal(subprocess.check_output(cmd))), \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return co.removal(subprocess.check_output(cmd)) delay_time = delay_time - 1 if delay_time >= 0: logger.log_debug("wait ...", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) time.sleep(2) else: logger.log_error("Client receive fail,can not find data.json file", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return None except Exception as e: logger.log_error("%s" %(e), \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return None
def check_package_exist(self, sn, flag, delay_time=300): ''' get mcu or mpu package size :param flag: :return: ''' package_name = self.get_mcu_and_mpu_name(sn, flag) if flag == mcu_flag: cmd = 'adb -s %s shell "ls -al %s/%s |%s wc -l 2>&1"' % ( sn, tbox_mcu, package_name, busybox) elif flag == mpu_flag: cmd = 'adb -s %s shell "ls -al %s/%s |%s wc -l 2>&1"' % ( sn, tbox_mpu, package_name, busybox) while True: try: print(co.removal(subprocess.check_output(cmd).strip())) if '1' in co.removal(subprocess.check_output(cmd).strip()): logger.log_debug("%s exists and downloading ..." % (package_name), \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 0 delay_time = delay_time - 1 if delay_time >= 0: logger.log_debug("wait a minute...", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) time.sleep(2) else: logger.log_error("can not find %s," % (package_name), \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 except Exception as e: logger.log_error("%s" % (e), \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1
def check_data_json(self,sn,delay_time): ''' function: return data.json if exist :param sn: :return: ''' if self.prepare_old_system(sn) == 0: co.delete_file(sn) time.sleep(5) co.reboot_device(sn) time.sleep(2) co.wait_hu_recovery(sn) return co.check_json_file(sn,delay_time)
def check_ping_value(cls, sn): ''' function: check ping value :return: ''' try: filelist = package.update_fota_package() if co.removal( subprocess.check_output( 'adb -s %s shell "ping -c 3 %s >/dev/null 2>&1 ;echo $?"' % (sn, filelist[10]), shell=True, stderr=subprocess.PIPE)).strip() == '0': return 0 else: return 1 except Exception as e: return 1
def get_requestdata_to_file(self,sn): try: filelist = package.update_fota_package() platform_information.set_device("hu") # platform_information.set_vin_version(platform_information.get_vin_verbose(sn)) platform_information.set_vin_version(filelist[5]) platform_information.set_sw_version_new(filelist[2]) platform_information.set_sw_version_old(filelist[3]) platform_information.set_mcu_version(filelist[6]) data_json = platform_information.temporary_get_port_data(platform_information.get_vin_version(), platform_information.get_device(), \ platform_information.get_sw_version_old(),\ platform_information.get_mcu_version()) header = platform_information.get_header(platform_information.get_vin_version()) print(header) print(data_json) return co.post_request_to_file(sn,header,data_json) except Exception as e: logger.log_error("%s" %(e),sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1
def prepare_activeupgrade_environment(self, sn, flag_mcu, flag_mpu): ''' function: check active upgrade :param sn: :return: ''' co.delete_file(sn) co.reboot_device(sn) co.wait_hu_recovery(sn) self.check_hu_network(sn) # time.sleep(5) try: if self.get_requestdata_to_file(sn) == 1: logger.log_error("maybe has no network", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 pcan = SC.PCAN() pcan.poweron_and_clean() if self.mcu_mpu_download_status( sn, flag_mpu) == 0 and self.mcu_mpu_download_status( sn, flag_mcu) == 0: try: if co.check_md5_status(sn) == 0: return 0 else: return 1 except Exception as e: logger.log_error("%s" % (e), \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 else: logger.log_error("can not find pakcage", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 except Exception as e: logger.log_error("%s" % (e), \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1
def prepare_activeupgrade_environment(self,sn, flag): ''' function: check active upgrade :param sn: :return: ''' co.delete_file(sn) time.sleep(5) try: if package.update_system_through_fastboot(retry_times) == 0 and co.start_fota_daemon(sn) == 0: # if co.start_fota_daemon(sn) == 0: time.sleep(5) if self.get_requestdata_to_file(sn) == 1: logger.log_error("maybe has no network",\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 if co.check_package_exist(sn,flag) == 0: try: expect_size = int(co.get_packagesize_from_json_file(sn,flag)) while True: actual_size = co.check_package_size(sn,flag,30) if int(actual_size) == expect_size: break return 0 except Exception as e: logger.log_error("%s" %(e),\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 else: logger.log_error("can not find pakcage",\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 else: return 1 except Exception as e: logger.log_error("%s" %(e),\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1
import requests from bs4 import BeautifulSoup import os import sys import uiautomator2 as u2 import subprocess from log import logger as loger import threading import re,sys import random from atexit import register from Common_Public import Common as co from Common_Public import Signal_List as SL from Common_Public import Signal_Common as SC action = ["check_sn_status","upgrade_udisk_package","check slience package download and install","reboot and check version","install old package"] package = co.Install_Package() adb_sn = co.ADB_SN() prepare_ui = co.Prepare_Ui() check_message = co.Check_message() platform_information = co.Platform_Information() logger = loger.Current_Module() retry_times = 5 class hu_common(object): def __init__(self): pass def check_sn_status(self): ''' function:check device status :return: sn serial number
def __init__(self, fun): self.serial_child = co.Serial() # self.serial_child.set_serialport() # self.ser = serial.Serial(self.serial_child.get_serialport(), self.serial_child.get_serial_baudrate()) package = co.Install_Package() self.fun = fun
def upgrade_through_setting(self, sn, flag_mcu, flag_mpu): co.delete_file(sn) co.reboot_device(sn) co.wait_hu_recovery(sn) self.check_hu_network(sn) # time.sleep(5) try: if self.get_requestdata_to_file(sn) == 1: logger.log_error("maybe has no network", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 pcan = SC.PCAN() pcan.poweron_and_clean() if self.mcu_mpu_download_status( sn, flag_mpu) == 0 and self.mcu_mpu_download_status( sn, flag_mcu) == 0: try: if co.check_md5_status(sn) == 0: if co.activeupgrade_through_setting( sn, SL.ActiveUpgrade, tbox_flag) == 0: time.sleep(20) if co.wait_hu_recovery(sn) == 0: while True: if Tbox_Information.check_ping_value( sn) == 0: co.open_tbox_adb() time.sleep(5) break Tbox_Information.copy_version_to_hu(sn) if Tbox_Information.check_system_version( sn) == 0: Tbox_Information.modify_tbox_config(sn) pcan = SC.PCAN() pcan.poweron_and_clean() return 0 else: Tbox_Information.modify_tbox_config(sn) pcan = SC.PCAN() pcan.poweron_and_clean() return 1 else: pcan = SC.PCAN() pcan.poweron_and_clean() logger.log_error("can not enter system", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 else: pcan = SC.PCAN() pcan.poweron_and_clean() return 1 else: logger.log_error("check md5 value failed", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 except Exception as e: logger.log_error("%s" % (e), \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 else: logger.log_error("can not find pakcage", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 except Exception as e: logger.log_error("%s" % (e), \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1
def test(): logger.log_info("start tbox active upgrade reboot test", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) co.ADB_SN().check_adb_device_isalive() sn = tbox_common.check_sn_status() count_pass = 0 count_fail = 0 if tbox_common.prepare_activeupgrade_environment(sn, "mcu", "mpu") == 0: Result = tbox_common.cancleinstall_through_setting(sn) if Result == 0: count_pass = count_pass + 1 # scp = co.Set_Screencap_Message(sn) # # co.Get_Logcat_Message(sn, co.logcat_object) # co.Get_Screencap_Message(sn, scp) # co.Get_libHU_Message(sn) logger.Current_Result(count_fail + count_pass, count_pass, count_fail, os.path.basename(__file__).strip('.py')) return 0 elif Result == 1: co.ADB_SN().check_adb_device_isalive() co.open_tbox_adb() time.sleep(10) tb_c.Tbox_Information.modify_tbox_config(sn) count_fail = count_fail + 1 scp = co.Set_Screencap_Message(sn) # co.Get_Logcat_Message(sn, co.logcat_object) co.Get_Screencap_Message(sn, scp) co.Get_libHU_Message(sn) logger.Current_Result(count_fail + count_pass, count_pass, count_fail, os.path.basename(__file__).strip('.py')) return 1 else: count_fail = count_fail + 1 scp = co.Set_Screencap_Message(sn) # co.Get_Logcat_Message(sn, co.logcat_object) co.Get_Screencap_Message(sn, scp) co.Get_libHU_Message(sn) logger.Current_Result(count_fail + count_pass, count_pass, count_fail, os.path.basename(__file__).strip('.py')) logger.log_error("prepare environemnt fail", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) return 1 # def test(date_time = None, loop_count = None): # # logger.log_info("start active upgrade reboot test", \ # sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name, sys._getframe().f_lineno) # count_pass = 0 # count_fail = 0 # sn = tbox_common.check_sn_status() # if date_time == None and loop_count == None: # logger.log_error("has no right argument",\ # sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) # sys.exit(-1) # elif date_time != None and loop_count == None: # current_time = int(time.time()) # loop_time = current_time + date_time*3600 # time.sleep(1) # if tbox_common.prepare_activeupgrade_environment(sn, "mcu", "mpu") == 0: # while current_time <= loop_time: # Result = tbox_common.cancleinstall_through_setting(sn) # if Result == 0: # count_pass = count_pass + 1 # scp = co.Set_Screencap_Message(sn) # # co.Get_Logcat_Message(sn, co.logcat_object) # co.Get_Screencap_Message(sn, scp) # co.Get_libHU_Message(sn) # logger.Current_Result(count_fail + count_pass, count_pass, count_fail, # os.path.basename(__file__).strip('.py')) # elif Result == 1: # count_fail = count_fail + 1 # scp = co.Set_Screencap_Message(sn) # # co.Get_Logcat_Message(sn, co.logcat_object) # co.Get_Screencap_Message(sn, scp) # co.Get_libHU_Message(sn) # logger.Current_Result(count_fail + count_pass, count_pass, count_fail, # os.path.basename(__file__).strip('.py')) # current_time = int(time.time()) # else: # count_fail = count_fail + 1 # scp = co.Set_Screencap_Message(sn) # # co.Get_Logcat_Message(sn, co.logcat_object) # co.Get_Screencap_Message(sn, scp) # co.Get_libHU_Message(sn) # logger.Current_Result(count_fail + count_pass, count_pass, count_fail, # os.path.basename(__file__).strip('.py')) # logger.log_error("prepare environemnt fail",\ # sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) # elif date_time == None and loop_count != None: # time.sleep(1) # if tbox_common.prepare_activeupgrade_environment(sn, "mcu", "mpu") == 0: # while loop_count > 0: # Result = tbox_common.cancleinstall_through_setting(sn) # if Result == 0: # count_pass = count_pass + 1 # logger.Current_Result(count_fail + count_pass, count_pass, count_fail, # os.path.basename(__file__).strip('.py')) # # print(count_pass) # elif Result == 1: # count_fail = count_fail + 1 # scp = co.Set_Screencap_Message(sn) # # co.Get_Logcat_Message(sn, co.logcat_object) # co.Get_Screencap_Message(sn, scp) # co.Get_libHU_Message(sn) # logger.Current_Result(count_fail + count_pass, count_pass, count_fail, # os.path.basename(__file__).strip('.py')) # loop_count = loop_count - 1 # else: # count_fail = count_fail + 1 # scp = co.Set_Screencap_Message(sn) # # co.Get_Logcat_Message(sn, co.logcat_object) # co.Get_Screencap_Message(sn, scp) # co.Get_libHU_Message(sn) # logger.Current_Result(count_fail + count_pass, count_pass, count_fail, # os.path.basename(__file__).strip('.py')) # loop_count = loop_count - 1 # logger.log_error("prepare environemnt fail",\ # sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) # print ("summary:\n") # logger.Total_Result(count_fail + count_pass,count_pass,count_fail,os.path.basename(__file__).strip('.py'))
def check_md5_file(self,sn, flag): ''' function: check md5 file :param sn: :return: ''' co.delete_file(sn) time.sleep(5) # package.flash_through_system(sn) try: if package.update_system_through_fastboot(retry_times) == 0 and co.start_fota_daemon(sn) == 0: # if co.start_fota_daemon(sn) == 0: time.sleep(5) if self.get_requestdata_to_file(sn) == 1: logger.log_error("maybe has no network",\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 if co.check_package_exist(sn,flag) == 0: try: sign_value = co.get_md5_value_from_datafile(sn,flag) package_name = co.get_packagename_from_json_file(sn,flag) expect_size = int(co.get_packagesize_from_json_file(sn,flag)) while True: time.sleep(random.randint(20,60)) co.reboot_device(sn) co.wait_hu_recovery(sn) actual_size = co.check_package_size(sn,flag,30) if int(actual_size) == expect_size: break if co.get_md5_value(sn, package_name, "hu_package.zip") == sign_value: return 0 else: return 1 except Exception as e: logger.log_error("%s" %(e),\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 else: return 1 except Exception as e: logger.log_error("%s" %(e),\ sys._getframe().f_code.co_filename,sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1
def check_break_point_resume_with_reboot(self, sn, flag): ''' function : break point resume through reboot :param sn: :return: ''' co.delete_file(sn) time.sleep(5) value_list = [] try: # package.flash_through_system(sn) if package.update_system_through_fastboot(retry_times) == 0 and co.start_fota_daemon(sn) == 0: # if co.start_fota_daemon(sn) == 0: time.sleep(5) if self.get_requestdata_to_file(sn) == 1: logger.log_error("maybe has no network",\ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) if co.check_package_exist(sn,flag) == 0: expect_size = int(co.get_packagesize_from_json_file(sn,flag)) while True: actual_size = co.check_package_size(sn,flag,30) value_list.append(int(actual_size)) # print(actual_size) if actual_size is not None and int(actual_size) < expect_size: time.sleep(random.randint(60,100)) co.reboot_device(sn) co.wait_hu_recovery(sn) # co.start_fota_daemon(sn) elif actual_size is None and co.check_package_exist(sn,flag,30) == 1: return 1 if int(actual_size) == expect_size: co.start_fota_daemon(sn) logger.log_info("check break point resume with network successfully",\ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 0 if len(value_list) >=5 : i=0 while i <= len(value_list) -2: if value_list[i] == value_list[i+1]: i = i + 1 else : break if i == len(value_list) -1: logger.error("package size can not change,and package always is :%s" % (actual_size), \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 else: logger.log_error("can not find package", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 else: logger.log_error("flash system failed or start fota module failed", \ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1 except Exception as e: logger.log_error("%s" %(e),\ sys._getframe().f_code.co_filename, sys._getframe().f_code.co_name,sys._getframe().f_lineno) return 1
tbox_message = "/update/tbox/" tbox_verison = "/data/version.txt" # tbox_verison = "/wm/update/version.txt" version_file = "/update/version.txt" tbox_update_log = "/update/log/." # tbox_update_log = "/wm/update/log/." json_name = "/update/data.json" tbox_mcu = "/update/package/tbox/mcu" tbox_mpu = "/update/package/tbox/mpu" mcu_flag = "mcu" mpu_flag = "mpu" logcat_object = None logger = loger.Current_Module() retry_time = 5 package = co.Install_Package() platform_information = co.Platform_Information() adb_sn = co.ADB_SN() class Tbox_Information(object): def __init__(self, fun): self.serial_child = co.Serial() # self.serial_child.set_serialport() # self.ser = serial.Serial(self.serial_child.get_serialport(), self.serial_child.get_serial_baudrate()) package = co.Install_Package() self.fun = fun def __enter__(self): self.serial_child.set_serialport() ser = serial.Serial(self.serial_child.get_serialport(),