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_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_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