diff --git a/DeployDevice/.gitignore b/DeployDevice/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..7e99e367f8443d86e5e8825b9fda39dfbb39630d
--- /dev/null
+++ b/DeployDevice/.gitignore
@@ -0,0 +1 @@
+*.pyc
\ No newline at end of file
diff --git a/DeployDevice/.idea/.gitignore b/DeployDevice/.idea/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/DeployDevice/.idea/DeployDevice.iml b/DeployDevice/.idea/DeployDevice.iml
new file mode 100644
index 0000000000000000000000000000000000000000..df67690278a39e0d8d6338209d810dabe441ac23
--- /dev/null
+++ b/DeployDevice/.idea/DeployDevice.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DeployDevice/.idea/inspectionProfiles/profiles_settings.xml b/DeployDevice/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000000000000000000000000000000000000..105ce2da2d6447d11dfe32bfb846c3d5b199fc99
--- /dev/null
+++ b/DeployDevice/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DeployDevice/.idea/misc.xml b/DeployDevice/.idea/misc.xml
new file mode 100644
index 0000000000000000000000000000000000000000..a2e120dcc86d18fdcb6ccfbe56c5d0b0dcd7c04a
--- /dev/null
+++ b/DeployDevice/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/DeployDevice/.idea/modules.xml b/DeployDevice/.idea/modules.xml
new file mode 100644
index 0000000000000000000000000000000000000000..eacc3898b9f883d4b6aa074354127f71dba2880b
--- /dev/null
+++ b/DeployDevice/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DeployDevice/.idea/vcs.xml b/DeployDevice/.idea/vcs.xml
new file mode 100644
index 0000000000000000000000000000000000000000..94a25f7f4cb416c083d265558da75d457237d671
--- /dev/null
+++ b/DeployDevice/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DeployDevice/.idea/workspace.xml b/DeployDevice/.idea/workspace.xml
new file mode 100644
index 0000000000000000000000000000000000000000..eca8e184488cfa26ce21671cab69599d3212e18c
--- /dev/null
+++ b/DeployDevice/.idea/workspace.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1643100752781
+
+
+ 1643100752781
+
+
+
+
\ No newline at end of file
diff --git a/DeployDevice/OAT.xml b/DeployDevice/OAT.xml
new file mode 100644
index 0000000000000000000000000000000000000000..9857f5e54aca51dcabd9758b9a293a9aef196747
--- /dev/null
+++ b/DeployDevice/OAT.xml
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/DeployDevice/doc/ReadMe b/DeployDevice/doc/ReadMe
new file mode 100644
index 0000000000000000000000000000000000000000..aa6221d9d1dece2e551fb6c393747dc83ded0ee6
--- /dev/null
+++ b/DeployDevice/doc/ReadMe
@@ -0,0 +1,41 @@
+一、代码规范:
+ module_name, 模块名, 如果模块里面没有定义类,直接引用方法,则采用ModuleName方式命名
+ package_name, 包名
+ ClassName, 类名
+ method_name, 方法名
+ ExceptionName, 异常
+ function_name, 函数
+ GLOBAL_VAR_NAME, 全局变量
+ instance_var_name, 实例
+ function_parameter_name, 参数名
+ local_var_name, 局部变量名
+
+二、 代码架构:
+
+
+三、 目录结构:
+ EnvServiceInBlue/src
+ aw:原子方法。目录以及文件名采用首字母大写的驼峰字符串
+ exception: 异常处理类,以及错误码信息等
+ function: 核心功能代码,制作业务的最基础功能,不串联整个业务流程
+ send_data: 数据发送相关
+ func 每个独立功能服务,升级和部署都是独立的app,能串联起某项业务的整个流程
+ core 框架, 执行器,负责串联多个func
+ util 一些公共的方法
+ init.py 框架初始化的准备工作
+ Manage.py:服务入口。
+
+
+四、代码设计要求:
+ 1、 业务功能代码以及异常处理逻辑代码等都集中exception,excute,function, tools包下
+ 2、 代码编写严格按照包的划分来进行,要求excute和function两个包中的代码功能单一。
+ 3、 框架为django,要求业务功能代码完全脱离django框架能独立调用,并也可在main.py中通过django框架调用。
+ 4、 Env_tools目录下新增一个agent包,存放pika方案调用的python文件,保证能在一台代码下,支持web和pika微服务两种调用。
+
+五、代码提交命令:
+ git add -A
+ git commit -m "TicketNo:None
+ Description:说明
+ Feature or Bugfix:Feature"
+ git push origin EnvTool_master:refs/for/EnvTool_master
+
diff --git a/DeployDevice/doc/VersionInfo.txt b/DeployDevice/doc/VersionInfo.txt
new file mode 100644
index 0000000000000000000000000000000000000000..072977994109b403feb7fcaeccd45e02e63b829b
--- /dev/null
+++ b/DeployDevice/doc/VersionInfo.txt
@@ -0,0 +1 @@
+Cur=Ver20200430
\ No newline at end of file
diff --git a/DeployDevice/resource/L0/HiBurn.exe b/DeployDevice/resource/L0/HiBurn.exe
new file mode 100644
index 0000000000000000000000000000000000000000..17341be849547e72359b55a4c1fc0d0194bd6de4
Binary files /dev/null and b/DeployDevice/resource/L0/HiBurn.exe differ
diff --git a/DeployDevice/resource/L0/rebootAfterDeploy.exe b/DeployDevice/resource/L0/rebootAfterDeploy.exe
new file mode 100644
index 0000000000000000000000000000000000000000..34b5ae7e217dd493d21491823f1892cfbea4cb8a
Binary files /dev/null and b/DeployDevice/resource/L0/rebootAfterDeploy.exe differ
diff --git a/DeployDevice/resource/L0/rebootBeforeDeploy.exe b/DeployDevice/resource/L0/rebootBeforeDeploy.exe
new file mode 100644
index 0000000000000000000000000000000000000000..b227dfffba04381cbb2335438ea7f603f941add1
Binary files /dev/null and b/DeployDevice/resource/L0/rebootBeforeDeploy.exe differ
diff --git a/DeployDevice/resource/L1/dv300/flash_fastboot.xml b/DeployDevice/resource/L1/dv300/flash_fastboot.xml
new file mode 100644
index 0000000000000000000000000000000000000000..b85b896e0bc33f44b18ae0c975c7860e6566d3f0
--- /dev/null
+++ b/DeployDevice/resource/L1/dv300/flash_fastboot.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/DeployDevice/resource/L1/dv300/u-boot-hi3516dv300.bin b/DeployDevice/resource/L1/dv300/u-boot-hi3516dv300.bin
new file mode 100644
index 0000000000000000000000000000000000000000..9f5a3058c867618e43909b179d85da908c3c159b
Binary files /dev/null and b/DeployDevice/resource/L1/dv300/u-boot-hi3516dv300.bin differ
diff --git a/DeployDevice/resource/L1/dv300/update.txt b/DeployDevice/resource/L1/dv300/update.txt
new file mode 100644
index 0000000000000000000000000000000000000000..f3031416474717e7182a4f29c5dd9b43081ebd49
--- /dev/null
+++ b/DeployDevice/resource/L1/dv300/update.txt
@@ -0,0 +1,3 @@
+setenv bootargs "console=ttyAMA0,115200n8 root=emmc fstype=vfat rootaddr=10M rootsize=30M rw";
+setenv bootcmd "mmc read 0x0 0x80000000 0x800 0x4800;go 0x80000000;"
+sa;reset;
\ No newline at end of file
diff --git a/DeployDevice/resource/L1/dv300/usb-burn-vfat.xml b/DeployDevice/resource/L1/dv300/usb-burn-vfat.xml
new file mode 100644
index 0000000000000000000000000000000000000000..de2afcb8caccde7a32936e00f62db0aa296e7eb9
--- /dev/null
+++ b/DeployDevice/resource/L1/dv300/usb-burn-vfat.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/DeployDevice/resource/L1/dv300/usb-burn.xml b/DeployDevice/resource/L1/dv300/usb-burn.xml
new file mode 100644
index 0000000000000000000000000000000000000000..b85b896e0bc33f44b18ae0c975c7860e6566d3f0
--- /dev/null
+++ b/DeployDevice/resource/L1/dv300/usb-burn.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/DeployDevice/resource/L1/dv300_linux/flash_fastboot.xml b/DeployDevice/resource/L1/dv300_linux/flash_fastboot.xml
new file mode 100644
index 0000000000000000000000000000000000000000..cf550fe976ea23a592b03fa57c6cb990c1eea172
--- /dev/null
+++ b/DeployDevice/resource/L1/dv300_linux/flash_fastboot.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/DeployDevice/resource/L1/dv300_linux/u-boot-hi3516dv300.bin b/DeployDevice/resource/L1/dv300_linux/u-boot-hi3516dv300.bin
new file mode 100644
index 0000000000000000000000000000000000000000..e7087655e3981d04e8bed499cfc3d7329e1bf886
Binary files /dev/null and b/DeployDevice/resource/L1/dv300_linux/u-boot-hi3516dv300.bin differ
diff --git a/DeployDevice/resource/L1/dv300_linux/update.txt b/DeployDevice/resource/L1/dv300_linux/update.txt
new file mode 100644
index 0000000000000000000000000000000000000000..94050e9058377103fceceeb719eea8d26e8a0785
--- /dev/null
+++ b/DeployDevice/resource/L1/dv300_linux/update.txt
@@ -0,0 +1,4 @@
+setenv bootargs 'mem=128M console=ttyAMA0,115200 root=/dev/mmcblk0p3 rw rootfstype=ext4 rootwait blkdevparts=mmcblk0:1M(boot),9M(kernel),50M(rootfs),50M(userfs)';
+setenv bootcmd "mmc read 0x0 0x82000000 0x800 0x4800; bootm 0x82000000";
+save;
+reset;
\ No newline at end of file
diff --git a/DeployDevice/resource/L1/dv300_linux/usb-burn-vfat.xml b/DeployDevice/resource/L1/dv300_linux/usb-burn-vfat.xml
new file mode 100644
index 0000000000000000000000000000000000000000..91d1628bcddaf252a38c647f1d22bab16f2be125
--- /dev/null
+++ b/DeployDevice/resource/L1/dv300_linux/usb-burn-vfat.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/DeployDevice/resource/L1/dv300_linux/usb-burn.xml b/DeployDevice/resource/L1/dv300_linux/usb-burn.xml
new file mode 100644
index 0000000000000000000000000000000000000000..cf550fe976ea23a592b03fa57c6cb990c1eea172
--- /dev/null
+++ b/DeployDevice/resource/L1/dv300_linux/usb-burn.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/DeployDevice/resource/L1/dv300_shequ/update.txt b/DeployDevice/resource/L1/dv300_shequ/update.txt
new file mode 100644
index 0000000000000000000000000000000000000000..3026226ecb0001cb998a7ed0a0f34ddffed9bbcb
--- /dev/null
+++ b/DeployDevice/resource/L1/dv300_shequ/update.txt
@@ -0,0 +1,7 @@
+setenv serverip %Tftpserver_IP%;setenv ipaddr %Device_IP%;setenv ethaddr %Device_MAC%;setenv netmask %Device_Netmask%;setenv gatewayip %Device_GatewayIP%;
+mw.b 0x80000000 0xFF 0x4800;tftp 0x80000000 /dv300/OHOS_Image.bin;mmc erase 0x800 0x4800;mmc write 0 0x80000000 0x800 0x4800
+mw.b 0x80000000 0xFF 0x19000;tftp 0x80000000 /dv300/rootfs.img;mmc erase 0x5000 0x19000;mmc write 0 0x80000000 0x5000 0x19000
+mw.b 0x80000000 0xFF 0x19000;tftp 0x80000000 /dv300/userfs.img;mmc erase 0x1E000 0x19000;mmc write 0 0x80000000 0x1E000 0x19000
+setenv bootargs "console=ttyAMA0,115200n8 root=emmc fstype=vfat rootaddr=10M rootsize=50M rw";
+setenv bootcmd "mmc read 0x0 0x80000000 0x800 0x4800;go 0x80000000;"
+sa;reset;
diff --git a/DeployDevice/resource/L1/ev200/update.txt b/DeployDevice/resource/L1/ev200/update.txt
new file mode 100644
index 0000000000000000000000000000000000000000..4172ae860a4733e6d0735098ee5cf3fe7cae39f1
--- /dev/null
+++ b/DeployDevice/resource/L1/ev200/update.txt
@@ -0,0 +1,8 @@
+setenv serverip %Tftpserver_IP%;setenv ipaddr %Device_IP%;setenv ethaddr %Device_MAC%;setenv netmask %Device_Netmask%;setenv gatewayip %Device_GatewayIP%;
+sf probe 0;
+mw.b 40000000 ff 500000; tftp 40000000 /ev200/OHOS_Image.bin; sf erase 100000 500000; sf write 40000000 100000 500000;
+mw.b 40000000 ff 900000; tftp 40000000 /ev200/rootfs.img; sf erase 600000 900000; sf write 40000000 600000 900000;
+mw.b 40000000 ff 100000; tftp 40000000 /ev200/userfs.img; sf erase f00000 100000; sf write 40000000 f00000 100000;
+setenv bootargs "console=ttyAMA0,115200n8 root=flash fstype=jffs2 rw rootaddr=6M rootsize=9M";
+setenv bootcmd 'sf probe 0;sf read 0x40000000 0x100000 0x500000;go 0x40000000;'
+sa;reset;
diff --git a/DeployDevice/resource/L1/ev300/flash_fastboot.xml b/DeployDevice/resource/L1/ev300/flash_fastboot.xml
new file mode 100644
index 0000000000000000000000000000000000000000..1195ef6893d9bd649dde18276d244883aeab51a6
--- /dev/null
+++ b/DeployDevice/resource/L1/ev300/flash_fastboot.xml
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/DeployDevice/resource/L1/ev300/u-boot-hi3518ev300.bin b/DeployDevice/resource/L1/ev300/u-boot-hi3518ev300.bin
new file mode 100644
index 0000000000000000000000000000000000000000..948166e1bb31c3add12bcc4f3b06e964c779fe47
Binary files /dev/null and b/DeployDevice/resource/L1/ev300/u-boot-hi3518ev300.bin differ
diff --git a/DeployDevice/resource/L1/ev300/update.txt b/DeployDevice/resource/L1/ev300/update.txt
new file mode 100644
index 0000000000000000000000000000000000000000..3e2a59a1455e5cb90cce8b395abe32219f22cd7d
--- /dev/null
+++ b/DeployDevice/resource/L1/ev300/update.txt
@@ -0,0 +1,3 @@
+setenv bootcmd 'sf probe 0;sf read 0x40000000 0x100000 0x500000;mw 0x112c0048 1a04 1;mw 0x112c004c 1004 1;mw 0x112c0064 1004 1;mw 0x112c0060 1004 1;mw 0x112c005c 1004 1;mw 0x112c0058 1004 1;go 0x40000000';saveenv;
+setenv bootargs "console=ttyAMA0,115200n8 root=flash fstype=jffs2 rw rootaddr=6M rootsize=9M";saveenv;
+sa;reset;
\ No newline at end of file
diff --git a/DeployDevice/resource/L1/ev300/usb-burn-jffs2.xml b/DeployDevice/resource/L1/ev300/usb-burn-jffs2.xml
new file mode 100644
index 0000000000000000000000000000000000000000..b2bf3819678324321886975d61a2d748f41fe007
--- /dev/null
+++ b/DeployDevice/resource/L1/ev300/usb-burn-jffs2.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/DeployDevice/resource/L1/ev300/usb-burn.xml b/DeployDevice/resource/L1/ev300/usb-burn.xml
new file mode 100644
index 0000000000000000000000000000000000000000..30537815d3c5867bec29519d01f2244b6a332ac9
--- /dev/null
+++ b/DeployDevice/resource/L1/ev300/usb-burn.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/DeployDevice/resource/L2/dv300/Hi3516DV300-emmc.xml b/DeployDevice/resource/L2/dv300/Hi3516DV300-emmc.xml
new file mode 100644
index 0000000000000000000000000000000000000000..727354f2eb46d4c435b72f8c71a2984d85ff79be
--- /dev/null
+++ b/DeployDevice/resource/L2/dv300/Hi3516DV300-emmc.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/DeployDevice/resource/L2/dv300/flash_fastboot.xml b/DeployDevice/resource/L2/dv300/flash_fastboot.xml
new file mode 100644
index 0000000000000000000000000000000000000000..4af38fd127f3be48521b0665cfbffc8b40d810b0
--- /dev/null
+++ b/DeployDevice/resource/L2/dv300/flash_fastboot.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/DeployDevice/resource/L2/dv300/u-boot-hi3516dv300_emmc.bin b/DeployDevice/resource/L2/dv300/u-boot-hi3516dv300_emmc.bin
new file mode 100644
index 0000000000000000000000000000000000000000..606a431fa0dd4bcbd5176877af77be43df409781
Binary files /dev/null and b/DeployDevice/resource/L2/dv300/u-boot-hi3516dv300_emmc.bin differ
diff --git a/DeployDevice/resource/L2/dv300/update.txt b/DeployDevice/resource/L2/dv300/update.txt
new file mode 100644
index 0000000000000000000000000000000000000000..12e962a33a3b4bd85be3e06bd6b34af8f652b5f2
--- /dev/null
+++ b/DeployDevice/resource/L2/dv300/update.txt
@@ -0,0 +1,4 @@
+setenv bootargs 'mem=640M console=ttyAMA0,115200 mmz=anonymous,0,0xA8000000,384M clk_ignore_unused androidboot.selinux=permissive rootdelay=10 hardware=Hi3516DV300 init=/init root=/dev/ram0 rw blkdevparts=mmcblk0:1M(boot),15M(kernel),20M(updater),2M(misc),3307M(system),256M(vendor),-(userdata)';
+setenv bootcmd 'mmc read 0x0 0x82000000 0x800 0x4800; bootm 0x82000000';
+saveenv;
+reset;
\ No newline at end of file
diff --git a/DeployDevice/resource/RK3568_tool/upgrade_tool.exe b/DeployDevice/resource/RK3568_tool/upgrade_tool.exe
new file mode 100644
index 0000000000000000000000000000000000000000..61030691d5beff7b436a93cac5db7ff4a4f0360a
Binary files /dev/null and b/DeployDevice/resource/RK3568_tool/upgrade_tool.exe differ
diff --git a/DeployDevice/resource/common/cbg_start.py b/DeployDevice/resource/common/cbg_start.py
new file mode 100644
index 0000000000000000000000000000000000000000..937cc0ede638f838017560bfd49cc7a73f944777
--- /dev/null
+++ b/DeployDevice/resource/common/cbg_start.py
@@ -0,0 +1,129 @@
+#encoding=utf-8
+import os
+import platform
+import sys
+import time
+from git.repo import Repo
+from portalocker import FileLock
+
+def printLog(message):
+ now = time.localtime()
+ time_info = time.strftime("%Y-%m-%d %X", now)
+ print(time_info + " " + message)
+
+def getAllParam(param_file):
+ params_dict = {}
+ with open(param_file, 'Ur', encoding="utf-8") as file:
+ for line in file.readlines():
+ line = line.strip()
+ if len(line) != 0:
+ if line.find("=") != -1:
+ str_list = line.split('=')
+ if str_list[0].find("#") != -1:
+ continue
+ else:
+ key = str_list[0].strip()
+ value = line[len(str_list[0]) + 1:].strip()
+ if len(key) !=0 and len(value) != 0:
+ params_dict[key] = value
+
+ return params_dict
+
+def parseProjectName(server_link):
+ printLog("INFO: parse the upgrade script project name from %s" % server_link)
+ items = server_link.split("/")
+ if len(items) <= 1:
+ return None
+ project_name = items[-1].split(".")[0]
+ return project_name
+
+def downloadUpgradeScripts(server_link, upgrade_script_path, is_update_script):
+ lock_name = "EnvToolMicroService.lock"
+ lock_file_abspath = os.path.join(WORKSPACE, lock_name)
+ locked = True
+ if locked:
+ printLog("download or update the upgrade script")
+ file_lock = FileLock()
+ file_lock.lockFile(lock_file_abspath)
+ printLog("Get lock. Start to ")
+
+ if not is_update_script and os.path.exists(upgrade_script_path):
+ printLog("update_script is false,there is no need to upgrade script")
+ return True
+
+ project_branch = "master"
+ if "-b" in server_link:
+ project_branch = server_link.split(" -b ")[-1]
+ if os.path.isdir(upgrade_script_path) and os.path.isdir(os.path.join(upgrade_script_path, ".git")):
+ if is_update_script:
+ repo = Repo(upgrade_script_path)
+ repo.git.remote()
+ if not repo.git.pull():
+ shutil.rmtree(upgrade_script_path)
+ Repo.clone_from(server_link.split(" -b ")[0], to_path=upgrade_script_path,branch=project_branch)
+ printLog("pull fail, download the upgrade script")
+ return True
+ else:
+ printLog("update the upgrade script")
+ return True
+ else:
+ if os.path.isdir(upgrade_script_path):
+ shutil.rmtree(upgrade_script_path)
+ Repo.clone_from(server_link.split(" -b ")[0], to_path=upgrade_script_path,branch=project_branch)
+ printLog("download the upgrade script")
+ return True
+
+
+if __name__ == "__main__":
+ if len(sys.argv) <= 1:
+ printLog("not enough args")
+ sys.exit(-1)
+ configPath = sys.argv[1]
+ os_name = platform.system()
+ python_exe_file = None
+ current_path = os.path.abspath(os.path.dirname(__file__))
+ if os_name == "Linux":
+ WORKSPACE = r"/data/MobileUpgrade"
+ python_exe_file = "python3"
+ elif os_name == "Windows":
+ WORKSPACE = r"D:\MobileUpgrade"
+ #python_exe_file = r"D:\DeviceTestTools\python\python.exe"
+ python_exe_file = "python"
+
+ server_link = "https://gitee.com/wenjun_HW/DeployTool_DevicePloy.git"
+ param_dict = getAllParam(configPath)
+
+ if not os.path.isdir(WORKSPACE):
+ try:
+ os.makedirs(WORKSPACE)
+ except:
+ time.sleep(1)
+ pass
+
+ '''================================update or download the upgrade script================================'''
+ if param_dict.get("tool_version") == "False":
+ is_update_script = False
+ elif param_dict.get("tool_version"):
+ is_update_script = True
+ else:
+ is_update_script = False
+ printLog("is_update_script = %s" % is_update_script)
+ project_name = parseProjectName(server_link)
+ upgrade_script_path = os.path.join(WORKSPACE, project_name)
+ ret = downloadUpgradeScripts(server_link, upgrade_script_path, is_update_script)
+ if not ret:
+ printLog("ERROR: download or update script failure")
+ ret = -1
+ else:
+ '''================================upgrade the device================================'''
+ printLog("INFO: ##############start to UpgradeScripts on your pc##############")
+ excute_file = os.path.join(upgrade_script_path, "src", "controller.py")
+ command = "%s -Bu %s %s" % (python_exe_file, excute_file, configPath)
+ printLog(command)
+ ret = os.system(command)
+ printLog("INFO: ##############end to UpgradeScripts on your pc##############")
+ printLog("result is %s" % ret)
+ if ret != 0:
+ printLog("ERROR: Upgrade failure")
+ ret = -1
+ exit(ret)
\ No newline at end of file
diff --git a/DeployDevice/resource/common/oeminfo_nvm_test b/DeployDevice/resource/common/oeminfo_nvm_test
new file mode 100644
index 0000000000000000000000000000000000000000..807532f62fa3912db553197a06d32d5d5fabe4f0
Binary files /dev/null and b/DeployDevice/resource/common/oeminfo_nvm_test differ
diff --git a/DeployDevice/resource/common/portalocker.py b/DeployDevice/resource/common/portalocker.py
new file mode 100644
index 0000000000000000000000000000000000000000..08496cfa02355e430f755808b96860d3f19fd7d9
--- /dev/null
+++ b/DeployDevice/resource/common/portalocker.py
@@ -0,0 +1,97 @@
+#encoding=utf-8
+import os
+import time
+import errno
+
+class FileLockException(Exception):
+ pass
+
+class FileLock(object):
+ """ A file locking mechanism that has context-manager support so
+ you can use it in a with statement. This should be relatively cross
+ compatible as it doesn't rely on msvcrt or fcntl for the locking.
+ """
+
+
+ def __init__(self, timeout=7200, delay=30):
+ """ Prepare the file locker. Specify the file to lock and optionally
+ the maximum timeout and the delay between each attempt to lock.
+ """
+ self.is_locked = False
+ self.timeout = timeout
+ self.delay = delay
+
+ def _setLockFileName(self, file_name):
+ self.lockfile = file_name
+
+ def acquire(self):
+ """ Acquire the lock, if possible. If the lock is in use, it check again
+ every `wait` seconds. It does this until it either gets the lock or
+ exceeds `timeout` number of seconds, in which case it throws
+ an exception.
+ """
+ start_time = time.time()
+ if os.path.isfile(self.lockfile):
+ try:
+ mark_file_mtime = os.path.getmtime(self.lockfile)
+ if (start_time - mark_file_mtime > self.timeout):
+ os.remove(self.lockfile)
+ except Exception as e:
+ print("the lock file is locked by other process")
+
+ while True:
+ try:
+ #open file , other application can't open it
+ self.fd = os.open(self.lockfile, os.O_CREAT|os.O_EXCL|os.O_RDWR)
+ break
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
+ if (time.time() - start_time) >= self.timeout:
+ raise FileLockException("Timeout occured.")
+ time.sleep(self.delay)
+ self.is_locked = True
+
+
+ def release(self):
+ """ Get rid of the lock by deleting the lockfile.
+ When working in a `with` statement, this gets automatically
+ called at the end.
+ """
+ #
+ if self.is_locked :
+ os.close(self.fd)
+ os.unlink(self.lockfile)
+ self.is_locked = False
+
+ def lockFile(self, file_name):
+ """ Activated when used in the with statement.
+ Should automatically acquire a lock to be used in the with block.
+ """
+ self._setLockFileName(file_name)
+ if not self.is_locked:
+ self.acquire()
+ return self
+
+ def releaseFile(self):
+ """ Activated at the end of the with statement.
+ It automatically releases the lock if it isn't locked.
+ """
+ if self.is_locked:
+ self.release()
+
+ def __del__(self):
+ """ Make sure that the FileLock instance doesn't leave a lockfile
+ lying around.
+ """
+ self.release()
+
+
+
+#鐢ㄦ硶姣旇緝鏈夋剰鎬濓紝浣跨敤with鍏抽敭瀛椼傚with鍏抽敭瀛楁潵璇达紝FileLock绫诲厛鎵ц__enter__鍑芥暟锛岀劧鍚庯紝鎵цwith鍧楅噷鐨勯偅浜涗唬鐮侊紝鎵ц瀹屼簡涔嬪悗锛屽啀鎵ц__exit__鍑芥暟锛岀瓑浠蜂簬鐩稿綋浜庡涓嬪舰寮忥細
+#try:
+# 鎵ц __enter__鐨勫唴瀹
+# 鎵ц with_block.
+#finally:
+# 鎵ц __exit__鍐呭
+#FileLock鍦╛_enter__鍑芥暟鐙崰寮忓垱寤烘垨鎵撳紑涓涓枃浠讹紝杩欎釜鏂囦欢涓嶄細琚叾浠栫▼搴忔垨鑰呰繘绋嬪啀娆″垱寤烘垨鑰呮墦寮锛岀敱姝ゅ舰鎴恖ock锛屾墽琛屽畬浠g爜锛屽湪__exit__閲岋紝鍏抽棴骞跺垹闄ゆ枃浠
\ No newline at end of file
diff --git a/DeployDevice/resource/common/push_code.py b/DeployDevice/resource/common/push_code.py
new file mode 100644
index 0000000000000000000000000000000000000000..545dade4907fbc5e3a04b021dd03e73801a62f63
--- /dev/null
+++ b/DeployDevice/resource/common/push_code.py
@@ -0,0 +1,34 @@
+from subprocess import getstatusoutput
+import time
+import sys
+import os
+
+commit_message = 'test_message'
+commit_path = r'D:/DevicetestTools/DeployDevice/'
+print(sys.argv)
+if len(sys.argv) > 1:
+ if sys.argv[1] != '':
+ commit_message = sys.argv[1]
+if len(sys.argv) > 2:
+ commit_path = commit_path + sys.argv[2]
+print(commit_path)
+cmds = [
+ ' git config --global user.email "yangbin148@huawei.com" ',
+ ' git config --global user.name "ywx1018148"',
+ r' git add %s.' % commit_path,
+ ' git commit -m "%s"' % commit_message,
+ ' git push'
+]
+for item in cmds:
+ sta,_ = getstatusoutput(item)
+ if sta != 0:
+ print('鎻愪氦澶辫触: %s' % _)
+ print('cmd:%s' % item)
+ print('***********************')
+ print('鎻愪氦澶辫触'.center(19, '*'))
+ print('***********************')
+ sys.exit(-1)
+ time.sleep(3)
+print('***********************')
+print('鎻愪氦鎴愬姛'.center(19, '*'))
+print('***********************')
\ No newline at end of file
diff --git a/DeployDevice/resource/common/user.txt b/DeployDevice/resource/common/user.txt
new file mode 100644
index 0000000000000000000000000000000000000000..3cb46c880237244b93fa82f3c797c3fe44f3fe5d
--- /dev/null
+++ b/DeployDevice/resource/common/user.txt
@@ -0,0 +1,5 @@
+ git clone https://yangbin148%40huawei.com:sh%2C%2E%2F123@gitee.com/wenjun_HW/DeployDevice
+ git config --global user.email "yangbin148@huawei.com" | git config --global user.name "ywx1018148"
+ git add .
+ git commit -m ''
+ git push
diff --git a/DeployDevice/src/L0task1.properties b/DeployDevice/src/L0task1.properties
new file mode 100644
index 0000000000000000000000000000000000000000..25d30dee0c48de0897bccd972c67bf00398bdf4d
--- /dev/null
+++ b/DeployDevice/src/L0task1.properties
@@ -0,0 +1,4 @@
+runstage=liteOsUpgrade_L0_app
+sn=XXXXX
+isDownload=False
+upgrade_upgradeLocation=\\10.175.127.15\Z_disk\daily_build\HMF_Lite_Dev_DailyBuild\2020-05-07-04-11-34_dev_dailybuild\wifiiot_hi3861v100_liteos_riscv
diff --git a/DeployDevice/src/L1task1.properties b/DeployDevice/src/L1task1.properties
new file mode 100644
index 0000000000000000000000000000000000000000..6933dcfb1b42caf8fb3331780a362660607a0013
--- /dev/null
+++ b/DeployDevice/src/L1task1.properties
@@ -0,0 +1,11 @@
+runstage=liteOsUpgrade_L1_app
+Telnet_IP=192.168.1.233
+Telnet_Port=10047
+Device_IP=192.168.1.234
+Device_MAC=3a:82:d0:08:f4:99
+Device_Netmask=255.255.255.0
+Device_GatewayIP=192.168.0.1
+isDownload=False
+Tftpserver_IP=192.168.1.53
+upgrade_upgradeLocation=https://devrepo.devcloud.cn-north-4.huaweicloud.com/DevRepoServer/v1/files/download?filename=06b3c99656b14c629abc445065a88016/Ipcamera_with_test/20200708.6/l1.tar.gz
+flash_type=ev200
diff --git a/DeployDevice/src/aw/Common/Common.py b/DeployDevice/src/aw/Common/Common.py
new file mode 100644
index 0000000000000000000000000000000000000000..9afb747fb17bdba2dc1e8097d4fae90fe1b61c23
--- /dev/null
+++ b/DeployDevice/src/aw/Common/Common.py
@@ -0,0 +1,155 @@
+# encoding=utf-8
+
+import os
+import socket
+import subprocess
+import time
+
+from util.log_info import logger
+from aw.Common.Constant import *
+
+def copyFile(source_path, copy_path, size=1024 * 1024):
+ '''
+ #===================================================================================
+ # @Method: copyFile(self, source_path, copy_path, size=1024 * 1024)
+ # @Precondition: none
+ # @Func: 鎷疯礉鏂囦欢
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # copy_path:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # size:瀛楄妭鏁扮殑澶у皬
+ # @eg: downloadByBitComet锛"xxxx", "D:\\local\\image"锛
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ if not os.path.isfile(source_path):
+ raise Exception("%s is not file" % source_path)
+ if os.path.isdir(copy_path):
+ copy_path = os.path.join(copy_path, os.path.basename(source_path))
+ try:
+ with open(source_path, 'rb') as fr, open(copy_path, 'wb') as fw:
+ while(True):
+ data = fr.read(size)
+ if not data:
+ break
+ fw.write(data)
+ except:
+ raise Exception("Copy %s to %s failed" % (source_path, copy_path))
+
+
+def copyDirectory(src_dir, dst_dir):
+ # copy everything under into
+ if not os.path.isdir(src_dir):
+ return False
+
+ if not os.path.isdir(dst_dir):
+ try:
+ os.makedirs(dst_dir)
+ except Exception as e:
+ logger.error(e)
+
+ time.sleep(1)
+ if not os.path.isdir(dst_dir):
+ return False
+
+ logger.info("copy %s to %s" % (src_dir, dst_dir))
+ for item in os.listdir(src_dir):
+ file_path = os.path.join(src_dir, item)
+ child_path = os.path.join(dst_dir, item)
+ if os.path.isfile(file_path):
+ logger.info("copy %s to %s" % (file_path, child_path))
+ copyFile(file_path, child_path)
+ if not os.path.isfile(child_path):
+ logger.error("Copy %s to %s failed" % (file_path, child_path))
+ return False
+ else:
+ if os.path.isdir(file_path):
+ ret = copyDirectory(file_path, child_path)
+ if not ret:
+ return False
+ return True
+
+def getHostIp():
+ """
+ #===================================================================================
+ # @Method: getHostIp()
+ # @Precondition: none
+ # @Func: 杩斿洖鏈哄櫒ip
+ # @PostStatus: none
+ # @eg: getHostIp()
+ # @return: ip
+ #===================================================================================
+ """
+ ip = ""
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ try:
+ s.connect(('8.8.8.8', 80))
+ ip = s.getsockname()[0]
+ except OSError as e:
+ print(e)
+ finally:
+ s.close()
+ return ip
+
+def getFileName(path, suffix_name):
+ '''
+ #===================================================================================
+ # @Method: getFileName(path, suffix_name)
+ # @Precondition: none
+ # @Func: find the flash script in version path or root path
+ # @PostStatus:
+ # @Param: path, version path or root path
+ # @Example: getFileName(path, suffix_name)
+ # @Author: zwx205888
+ # @ModifyRecord: none
+ #===================================================================================
+ '''
+ logger.info("get %s in %s" % (suffix_name, path))
+ import glob
+ script_files = glob.glob(os.path.join(path, "*" + suffix_name))
+ logger.info("real file is : %s " % script_files)
+ if len(script_files) != 1:
+ logger.error("more than one %s file or has No %s file" % (suffix_name, suffix_name))
+ return False
+
+ return script_files[0]
+
+def subProcessPopen(cmd, outlog_enable=True, errlog_enable=True):
+ """
+ @Method: subProcessPopen()
+ @Precondition: none
+ @Func: excute the command
+ @PostStatus: none
+ @Param: cmd,the command that will be excuted
+ @Example: subProcessPopen("RD /Q /F D:\test")
+ @ModifyRecord: none
+ """
+
+ ret_dict = {}
+ number = 3
+
+ for i in range (number):
+ p1 = subprocess.Popen(cmd,
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ shell=True)
+ out, err = p1.communicate()
+ if 0 != p1.returncode:
+ if True == outlog_enable:
+ logger.error(err)
+ logger.error("%s fail" % cmd)
+ ret = False
+ else:
+ ret = True
+ ret_dict["ret"] = ret
+ ret_dict["out"] = out.strip()
+ ret_dict["err"] = err.strip()
+ if outlog_enable:
+ logger.info("ret is %s" % ret)
+ logger.info(out.strip())
+ if errlog_enable:
+ logger.info(err.strip())
+ if ret_dict["out"] or ret_dict["err"]:
+ break
+ return ret_dict
\ No newline at end of file
diff --git a/DeployDevice/src/aw/Common/Constant.py b/DeployDevice/src/aw/Common/Constant.py
new file mode 100644
index 0000000000000000000000000000000000000000..ca351f38c48c02e4cb4261630815d3b4d9901a47
--- /dev/null
+++ b/DeployDevice/src/aw/Common/Constant.py
@@ -0,0 +1,127 @@
+# encoding=utf-8
+
+'''
+======================================================================================
+鐗堟潈 (C) 2020-2025, Huawei Technologies Co., Env
+========================================================================================
+@FileName: constant.py
+@Function: def constant var
+@Author: w00278233
+@Date: 20200424
+======================================================================================
+'''
+
+import platform
+import os
+
+
+
+class CONSTANT(object):
+ ENVERRMESSAGE = ""
+
+ class Box():
+ '''
+ Box鐩稿叧鐨勫父閲
+ '''
+ SHORT_TIMEOUT=15
+ GT3000_DEFAULT_PORT=7788
+ OK="0,Success"
+
+ class OSType():
+ '''
+ 涓庢搷浣滅郴缁熺殑鐩稿叧鐨勫父閲
+ '''
+ PASSWORD = "gongjubu123456!."
+ ACCOUNT = "pwhpdevice"
+ def getworkspace():
+ WORKSPACE= ""
+ if platform.system() == "Linux":
+ WORKSPACE = "/data/MobileUpgrade"
+ if platform.system() == "Windows":
+ WORKSPACE = "D:\MobileUpgrade"
+ return WORKSPACE
+ default_log_dir = os.path.join(getworkspace(), "log")
+
+ def getscripttype():
+ script_file = ""
+ if platform.system() == "Linux":
+ script_file = ".sh"
+ if platform.system() == "Windows":
+ script_file = ".bat"
+ return script_file
+
+
+ class Board():
+ pass
+
+ class ErrCode():
+ SUCCESS_CODE = 0
+ ERROR_NO_USERCUST_SCRIPT_IN_RESOUCEPOOL = 11
+ ERROR_EXCUTE_USERCUST_SCRIPT_FAIL_IN_RESOUCEPOOL=12
+ ERROR_INVALID_APK_FILE = 33
+ ERROR_CUSTPARAM_IS_NONE=62
+ ERROR_PARAMS_NO_SN=63
+ ERROR_VERSION_USE_CHINAESE=65
+ ERROR_VERSION_IS_NONE=66
+ ERROR_VERSION_PATH_TOO_LONG=67
+ ERROR_CUSTPARAM_NOT_IN_ALLPARAMS=68
+ ERROR_DOWNLOAD_IMG_FAIL=101
+ ERROR_DOWNLOAD_ROOT_FAIL=102
+ RROR_MAKE_DIR_FAIL=103
+ ERROR_DOWNLOAD_APK_FAIL=104
+ ERROR_LOCALPATH_NOT_EXIST=105
+ ERROR_INSTALL_APK_FAIL=106
+ ERROR_NO_UPGRADE_FILE_OR_PACKAGE=107
+ ERROR_DOWNLOAD_VERSION_FAIL=108
+ ERROR_PARSE_RESOURCEPOOL_PARMS_FAIL=109
+ ERROR_DEVICE_IS_FASTBOOT_CAN_NOT_DO_APK_UPGRDE=110
+ ERROR_FLASH_IMAGE_FAIL=111
+ ERROR_FLASH_BASE_FAIL=112
+ ERROR_FLASH_CUST_FAIL=113
+ ERROR_FLASH_PRELOAD_FAIL=114
+ ERROR_BOOT_UP_TIME_OUT=119
+ ERROR_MODEM_CHECK_FAIL=121
+ ERROR_LAUNCHER_CHECK_FAIL=122
+ ERROR_CANNOT_INTO_FASTBOOT_MODE=123
+ ERROR_RESETFACTORY_TIME_OUT=125
+ ERROR_DOWNLOAD_COTA_FAIL=128
+ ERROR_NO_IMG_FILE=131
+ ERROR_NO_SCRIPT_FILE=132
+ ERROR_DEVICE_NOT_FOUND=133
+ ERROR_MODIFY_SCRIPT_FAIL=134
+ ERROR_DEVICE_UNAUTHORIZE=135
+ ERROR_PUSH_FILE_FAIL=136
+ ERROR_VALIDATEPARAMS_FAIL=137
+ ERROR_OTHER_ERROR = 200
+
+ class SysTool():
+ ARIA2CBIN=r"/usr/bin/aria2c"
+
+ class File():
+ LOCK_SUFFIX="file_lock.txt"
+ SUC_FILE="suc.txt"
+ FAILED_FILE="failed.txt"
+
+ class Path():
+ def getDirPath():
+ if platform.system() == "Windows":
+ return "D:\MobileUpgrade\local_img"
+ if platform.system() == "Linux":
+ return "/data/MobileUpgrade/local_img"
+ return "unknow OS"
+
+ def getTftpServerPath():
+ if platform.system() == "Linux":
+ return "/data/nfsuser/data"
+ if platform.system() == "Windows":
+ return "D:\MobileUpgrade\local_img"
+ return "unknow OS"
+
+ def getSavePath():
+ return r'D:\DevicetestTools\upgrade_version.txt'
+
+ class Key():
+ DEV_KEY = "6ba7b8119dad11d180b400c04fd430c8"
+ DEV_DNAME = "b480ff9447a7e874e7065d290b5294c1662e0195a20f0dc60180f8c036bb901e"
+ DEV_PASSWD = "3c5db801e47e4cba7bd0d9bd95bd1540"
+
diff --git a/DeployDevice/src/aw/Common/__init__.py b/DeployDevice/src/aw/Common/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/DeployDevice/src/aw/Download/Download.py b/DeployDevice/src/aw/Download/Download.py
new file mode 100644
index 0000000000000000000000000000000000000000..a0449aa7b58542e36209372f3d1987cdcff0d215
--- /dev/null
+++ b/DeployDevice/src/aw/Download/Download.py
@@ -0,0 +1,606 @@
+# encoding=utf-8
+
+"""
+======================================================================================
+copyright (C) 2018-2019, Huawei Technologies Co.
+========================================================================================
+@鏂囦欢鍚嶇О: Download.py
+@鎻忚堪: 鏂囦欢涓嬭浇鐩稿叧鍔ㄤ綔
+@浣滆: lwx587017
+@鐢熸垚鏃ユ湡: 20181019
+======================================================================================
+"""
+import codecs
+import os
+import shutil
+import urllib
+import time
+import sys
+import re
+import datetime
+import subprocess
+import platform
+import traceback
+import requests
+import json
+import threading
+import zipfile
+
+# from util.config import *
+from util.log_info import logger
+from util.time_info import get_now_time_str_info, timeout
+
+current_path = os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
+BitCometjar = os.path.join(current_path, "Resource", "thirdtools", "TTorrentFull.jar")
+from aw.Common.Constant import CONSTANT
+
+from aw.Common.Common import subProcessPopen, copyFile
+
+Aria2cbin = CONSTANT.SysTool.ARIA2CBIN
+
+
+def downloadByBitComet(source_path, download_dir, os_method):
+ '''
+ #===================================================================================
+ # @Method: downloadByBitComet(source_path, dest_path)
+ # @Precondition: none
+ # @Func: 閫氳繃bt涓嬭浇锛屽皢璧勬簮鏂囦欢涓嬭浇鍒版湰鍦
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # os_method:缁戝畾鎿嶄綔绯荤粺鐢ㄥ埌鍏叡鏂规硶鐨勫璞
+ # @eg: downloadByBitComet锛"xxxx", "D:\\local\\image", os_method锛
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ server_ip = "100.104.224.115"
+ server_port = "2976"
+ source_path = source_path.replace(' ', '%20')
+ torrent_exist_url = "http://" + server_ip + ":" + server_port + "/centerDistributeService/BtCenter/addTaskDistribute?path=" \
+ + source_path
+ logger.info(torrent_exist_url)
+ version_path, destdir = os.path.split(download_dir)
+
+ exist_log = os.path.join(version_path, destdir + "_exist.log")
+ ret = False
+ for _ in range(600):
+ urllib.request.urlretrieve(torrent_exist_url, exist_log)
+ if os.path.isfile(exist_log):
+ open_file = codecs.open(exist_log, "r", "utf-8")
+ content = open_file.readline()
+ if str(content).find("\"status\":\"done\"") != -1:
+ ret = True
+ logger.info("The torrent of %s created seccessfully" % source_path)
+ break
+ else:
+ time.sleep(6)
+ logger.info("The torrent of %s is creating , please wait for a moment" % source_path)
+ continue
+ logger.info(ret)
+ if not ret:
+ logger.info("The torrent of %s created failed" % source_path)
+ return False
+ torrent_down_url = "http://" + server_ip + ":" + server_port + "/centerDistributeService/BtCenter/seed?path=" \
+ + source_path
+ download_torrent = os.path.join(version_path, destdir + ".torrent")
+ for _ in range(3):
+ urllib.request.urlretrieve(torrent_down_url, download_torrent)
+ if os.path.isfile(download_torrent):
+ ret = False
+ logger.info("The torrent of %s downloaded successed" % source_path)
+ break
+ else:
+ time.sleep(3)
+ continue
+ if ret:
+ logger.info("The torrent of %s downloaded failed" % source_path)
+ return False
+
+ if os.path.isfile(Aria2cbin):
+ BT_Command = "aria2c -l - -d %s --enable-dht=false --seed-time=0 --log-level=warn \
+ --max-download-limit=50M --bt-stop-timeout=120 %s" % (version_path, download_torrent)
+ else:
+ BT_Command = "java -cp %s com.turn.ttorrent.demo.Downloader %s %s" % (
+ BitCometjar, download_torrent, version_path)
+ result = os.system(BT_Command)
+ if result:
+ logger.error("BT-Downloader returns: %s, download failed." % result)
+ return False
+ for ld in os.listdir(version_path):
+ if len(ld) == 32 and os.path.isdir(os.path.join(version_path, ld)):
+ copyDirectory(os.path.join(version_path, ld), download_dir, os_method)
+ shutil.rmtree(os.path.join(version_path, ld), True)
+ return True
+
+
+def waitotherdown(suc_mark):
+ '''
+ #===================================================================================
+ # @Method: waitotherdown(suc_mark)
+ # @Precondition: none
+ # @Func: 濡傛灉鐗堟湰鐩稿悓涓旀鐗堟湰娌′笅杞芥垚鍔熻繃锛屼細绛夊緟姝e湪涓嬭浇鐨勪换鍔″幓涓嬭浇锛
+ # 绛夊緟鏃堕暱2灏忔椂锛岃嫢瓒呰繃2灏忔椂姝e湪涓嬭浇鐨勪换鍔¤繕鏈笅杞芥垚鍔燂紝鍒欒嚜琛屼笅杞
+ # @PostStatus: none
+ # @Param: suc_mark锛氭垚鍔熸爣蹇楁枃浠剁殑璺緞
+ # @eg: waitotherdown("xxx\\suc.txt")
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ logger.info("wait other process download")
+ for i in range(240):
+ checktime = 5
+ time.sleep(checktime)
+ if os.path.isfile(suc_mark):
+ logger.info("%s exists. Package has been download successfully" \
+ " by other process." % suc_mark)
+ break
+ if i == 80:
+ logger.error("wait other process download timeout")
+ return False
+ return True
+
+
+def isDownLoadSuccess(download_dir, suc_mark, failed_mark):
+ '''
+ #===================================================================================
+ # @Method: isDownLoadSuccess(download_dir, suc_mark, failed_mark)
+ # @Precondition: none
+ # @Func: 涓嬭浇鏂囦欢鍓嶏紝鍒ゆ柇姝ゆ枃浠舵槸鍚﹀凡涓嬭浇鎴愬姛鎴栧け璐ワ紝鏈変笅杞藉け璐ユ爣蹇楋紝鍒欓噸鏂颁笅杞
+ # ,鑻ユ鏂囦欢鏈笅杞借繃锛屽垯鍒涘缓鏂囦欢澶归噸鏂颁笅杞
+ # @PostStatus: none
+ # @Param: download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰勮矾寰
+ # suc_mark锛氭垚鍔熸爣蹇楁枃浠剁殑璺緞
+ # @eg: isDownLoadSuccess("xxx", "xxx\\suc.txt", "xxx\\fail.txt")
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ if os.path.isfile(suc_mark):
+ logger.info("%s has been download by other process." % download_dir)
+ return True
+ elif os.path.isfile(failed_mark):
+ logger.info("%s exists. Other process has download package and failed. It will download by self" % failed_mark)
+ os.remove(failed_mark)
+ else:
+ try:
+ # 濡傛灉褰撳墠鐗堟湰鐨勭洰褰曞瓨鍦紝鍒欒涓虹増鏈凡缁忎笅杞
+ if not os.path.isdir(download_dir):
+ logger.debug("mkdir %s" % download_dir)
+ os.makedirs(download_dir)
+ else:
+ logger.debug("%s is already downloading by other process,please wait for a moment!" % download_dir)
+ ret = waitotherdown(suc_mark)
+ return ret
+ except Exception as e:
+ logger.error("make dir fail with %s" % e)
+ shutil.rmtree(download_dir)
+
+ return False
+
+
+def saveVersion(save_path_file, versionsavepath):
+ '''
+ #===================================================================================
+ # @Method: saveVersion(save_path_file, versionsavepath)
+ # @Precondition: none
+ # @Func: 姝ゆ柟娉曠敤浜庢枃浠朵笅杞斤紝濡傛灉鏂囦欢涓嬭浇鎴愬姛锛屽氨缂撳瓨鐗堟湰璁板綍鍒皉ecord/xxx.txt涓紝
+ # 鏍煎紡锛/data/MobileUpgrade/local_img/1663de89-4a0b-5b26-bfad-5d2fd7bf0740
+ # @PostStatus: none
+ # @Param: save_path_file锛氭枃浠跺悕绉帮紝渚5c0d84a3a51fff875f8ed4de16791b1c7d3d2cfe.txt
+ # versionsavepath:鏈湴瀛樺偍璺緞
+ # @eg: saveVersion(save_path_file锛 versionsavepath)
+ # @return: None
+ #===================================================================================
+ '''
+ savepath = os.path.dirname(save_path_file)
+ if not os.path.isdir(savepath):
+ logger.debug("mkdir %s" % savepath)
+ os.makedirs(savepath)
+ if os.path.isfile(save_path_file):
+ logger.info("%s exists." % save_path_file)
+ else:
+ logger.info("save_path_file: %s" % save_path_file)
+ with open(save_path_file, "a") as f:
+ f.write(versionsavepath)
+
+
+def downlaodByDownloadTool(dir_path, version_type, upgrade_type, pbiid):
+ '''
+ #===================================================================================
+ # @Method: downlaodByDownloadTool(dir_path, version_type, upgrade_type, pbiid)
+ # @Precondition: none
+ # @Func: 鐢ㄤ笅杞藉伐鍏锋彁渚涚殑jar鍖呰繘琛屼笅杞斤紝闇瑕佷紶鍏ョ増鏈殑pbiid,鍗囩骇绫诲瀷,鐗堟湰绫诲瀷锛
+ # 鍏蜂綋浣跨敤鏂规硶鍙挩璇wx515469
+ # @PostStatus: none
+ # @Param: dir_path锛氭湰鍦板偍瀛樼増鏈殑璺緞
+ # version_type:鐗堟湰鐨勭被鍨嬶紝濡俹dex,dex,no_log
+ # upgrade_type:鍗囩骇鐨勭被鍨嬶紝濡侳ASTBOOT,SD
+ # pbiid:鐗堟湰鐨刾biid鍙
+ # os_method:缁戝畾鎿嶄綔绯荤粺鐢ㄥ埌鍏叡鏂规硶鐨勫璞
+ # @eg: downlaodByDownloadTool(dir_path, version_type, upgrade_type, pbiid, os_method)
+ # @return: None
+ #===================================================================================
+ '''
+ upgrade_type = upgrade_type.upper()
+ jar_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))), "resource",
+ "thirdtools", "downloadTool.jar")
+ os_name = platform.system()
+ logger.debug("copy res to dir_path")
+ res_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))), "resource",
+ "thirdtools", "res")
+ local_res_path = os.path.join(dir_path, "res")
+ if not os.path.isdir(local_res_path):
+ os.makedirs(local_res_path)
+ if os_method.copyDirectory(res_path, local_res_path):
+ logger.info("copy res to the local image path sucess")
+ else:
+ logger.info("copy res to the local image path fail")
+ return False
+ if (os_name == "Linux"):
+ jar_cmd = "cd %s & java -jar %s %s %s:%s" % (dir_path, jar_path, pbiid, upgrade_type, version_type)
+ else:
+ jar_cmd = "D: & cd %s & java -jar %s %s %s:%s" % (dir_path, jar_path, pbiid, upgrade_type, version_type)
+ logger.info("download by download.jar,cmd is %s" % jar_cmd)
+ ret = subprocess.getoutput(jar_cmd)
+ logger.info("the result is %s after excute downloadTool.jar" % ret)
+ if "download success" in ret:
+ list_jardir = os.listdir(dir_path)
+ for dir in list_jardir:
+ jardir = os.path.join(dir_path, dir)
+ if os.path.isdir(jardir) and jardir != "res":
+ os.rename(jardir, os.path.join(dir_path, "jarimg"))
+ break
+ logger.info("download success by downloadjar")
+ return True
+ else:
+ if "failreason" in ret:
+ com = re.search("failreason\((.*)\)", ret)
+ failreason = com.group(1)
+ logger.info("download fail by downloadjar,failreson is %s" % failreason)
+ else:
+ logger.info("download fail by downloadjar,and jartool not support failreason")
+ return False
+
+
+def downloadLinkFileFromHttp(link, path):
+ '''
+ #===================================================================================
+ # @Method: downloadLinkFileFromHttp(link, path)
+ # @Precondition: none
+ # @Func: 閫氳繃http涓嬭浇璧勬簮鏂囦欢鍒版湰鍦
+ # @PostStatus: none
+ # @Param: link锛氳祫婧愭枃浠惰矾寰
+ # path:鏈湴鏂囦欢璺緞
+ # @eg: downloadLinkFileFromHttp("http:xxx", "D:\local_img")
+ # @return: True or False
+ #===================================================================================
+ '''
+ file_name = link.split('/')[-1]
+ destination_file = os.path.join(path, file_name)
+ logger.info('file_name is %s' % file_name)
+ logger.info('destination_file is %s' % destination_file)
+ if not os.path.isdir(path):
+ os.makedirs(path)
+ if not os.path.isfile(destination_file):
+ downloadFileFromHttp(link, destination_file)
+
+ if not os.path.isfile(destination_file):
+ logger.error('download link file error')
+ return False
+ else:
+ return True
+
+
+def downloadFileFromHttp(file_link, destination_file):
+ '''
+ #===================================================================================
+ # @Method: downloadFileFromHttp(file_link, destination_file)
+ # @Precondition: none
+ # @Func: 閫氳繃http鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: file_link锛氳祫婧愭枃浠惰矾寰
+ # destination_file:鏈湴鏂囦欢璺緞
+ # @eg: destination_file("http:xxx", "D:\local_img")
+ # @return: None
+ #===================================================================================
+ '''
+ import urllib
+ logger.info("download file from %s to %s" % (file_link, destination_file))
+ urllib.request.urlretrieve(file_link, destination_file, scheduleDownloadPercent)
+
+
+def scheduleDownloadPercent(downloadsize, blocksize, filesize):
+ '''
+ #===================================================================================
+ # @Method: scheduleDownloadPercent(downloadsize, blocksize, filesize)
+ # @Precondition: none
+ # @Func: 鎵撳嵃褰撳墠涓嬭浇鐨勮繘搴︼紝鐢ㄧ櫨鍒嗘瘮褰㈠紡鏄剧ず
+ # @PostStatus: none
+ # @Param: downloadsize锛氬凡涓嬭浇鏂囦欢鐨勫ぇ灏
+ # blocksize:涓嬭浇鍧楁暟
+ # filesize:鎬绘枃浠跺ぇ灏
+ # @eg: scheduleDownloadPercent(xxx,2,xxx )
+ # @return: None
+ #===================================================================================
+ '''
+ percent = 100.0 * downloadsize * blocksize / filesize
+ if percent >= 100:
+ percent = 100
+ downloadpercent = 100
+ percent = float("%.4f" % percent)
+ if percent % 1 == 0:
+ logger.info("file download percent:%.0f%%" % percent)
+
+
+def downloadByCopyWindows(source_path, download_dir, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, is_file, params)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ # @eg: excutedown("xxxx", "D:\\local\\image", Flase)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ try:
+ if not is_file:
+ for f in os.listdir(source_path):
+ file_name = os.path.join(source_path, f)
+ child_path = os.path.join(download_dir, f)
+ if os.path.isfile(file_name):
+ copyFile(file_name, child_path, 32 * 1024)
+ if not os.path.isfile(child_path):
+ logger.error("Copy %s to %s failed" % (file_name, child_path))
+ return False
+ logger.info("Copy %s to %s successful" % (file_name, child_path))
+ else:
+ if not os.path.isdir(child_path):
+ logger.info("Mkdir %s successful" % child_path)
+ os.makedirs(child_path)
+ ret = downloadByCopyWindows(file_name, child_path, False)
+ if not ret:
+ return False
+ else:
+ copyFile(source_path, download_dir)
+ return True
+ except Exception as e:
+ logger.error(e)
+ return False
+ return True
+
+
+def downloadByCopyLinux(source_path, download_dir, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, is_file, params)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ # @eg: excutedown("xxxx", "D:\\local\\image", Flase)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ try:
+ region = ""
+ source_path = source_path.replace("\\", "/")
+ temp = source_path.split("/")
+ host, share, path, file = '', '', '', ''
+ if is_file:
+ file = temp.pop()
+ else:
+ file = '*'
+ for i in temp:
+ if i:
+ if not host:
+ host = i
+ elif not share:
+ share = i
+ else:
+ path = os.path.join(path, i)
+ else:
+ continue
+ cmd = ("smbclient //%s/%s" % (host, share) + " -U CHINA/"
+ + CONSTANT.OSType.ACCOUNT
+ + "%'"
+ + CONSTANT.OSType.PASSWORD
+ + "' -c 'cd \"%s\"'" % path)
+ result = subProcessPopen(cmd)
+ if not result["ret"]:
+ logger.error("invalid samba path.")
+ return False
+ cmd = ("smbclient //%s/%s" % (host, share) + " -U CHINA/"
+ + CONSTANT.OSType.ACCOUNT
+ + "%'"
+ + CONSTANT.OSType.PASSWORD)
+ if region == "green":
+ cmd = cmd + "' -m SMB2 -c 'cd \"%s\";prompt OFF;recurse ON;lcd %s;mget %s'" % (path, download_dir, file)
+ else:
+ cmd = cmd + "' -c 'cd \"%s\";prompt OFF;recurse ON;lcd %s;mget %s'" % (path, download_dir, file)
+ logger.debug(cmd)
+ result = subProcessPopen(cmd)
+ if ("connect failed" in str(result["out"]) or "NT_STATUS_IO_TIMEOUT" in str(result["out"])) or (
+ not result["ret"]):
+ return False
+ else:
+ return True
+ except Exception:
+ traceback.print_exc()
+ return False
+
+
+def downloadByCopy(source_path, download_dir, is_file):
+ os_name = platform.system()
+ if os_name == "Windows":
+ return downloadByCopyWindows(source_path, download_dir, is_file)
+ if os_name == "Linux":
+ return downloadByCopyLinux(source_path, download_dir, is_file)
+
+
+@timeout(240)
+def getToken(domin_name, name, password):
+ '''
+ #===================================================================================
+ # @Method: getToken(domin_name, name, passwd, proxy)
+ # @Precondition: none
+ # @Func: 閫氳繃http涓嬭浇钃濆尯鏂囦欢
+ # @PostStatus: none
+ # @Param: domin_name: 甯愬彿鍚
+ # username锛氱敤鎴峰悕
+ # password锛氬瘑鐮
+ #
+ # @eg: getToken("xxx", "xxx", "xxx")
+ # @return: None
+ #===================================================================================
+ '''
+ body_1 = {
+ "auth": {
+ "identity": {
+ "methods": [
+ "password"
+ ],
+ "password": {
+ "user": {
+ "domain": {
+ "name": domin_name
+ },
+ "name": name,
+ "password": password
+ }
+ }
+ },
+ "scope": {
+ "project": {
+ "name": "cn-north-4"
+ }
+ }
+ }
+ }
+ header_1 = {"content-type": "application/json;charset=UTF-8"}
+ resp = requests.request("POST", "https://iam.myhuaweicloud.com/v3/auth/tokens", data=json.dumps(body_1),
+ headers=header_1)
+ # print("auth result:", resp.status_code, resp.headers)
+ return resp.headers.get("X-Subject-Token")
+
+
+def downloadFileFromDevCloud(link, destination_file, start, end):
+ '''
+ #===================================================================================
+ # @Method: downloadFileFromDevCloud(link, username, password, path)
+ # @Precondition: none
+ # @Func: 閫氳繃http涓嬭浇钃濆尯鏂囦欢
+ # @PostStatus: none
+ # @Param: link锛氳祫婧愭枃浠惰矾寰
+ # username锛氱敤鎴峰悕
+ # password锛氬瘑鐮
+ # path:鏈湴鏂囦欢璺緞
+ # @eg: downloadFileFromDevCloud("http:xxx", "xxx", "xxx","D:\local_img")
+ # @return: None
+ #===================================================================================
+ '''
+ fd = open(destination_file, 'wb+')
+ dname = decrypt(CONSTANT.Key.DEV_DNAME, CONSTANT.Key.DEV_KEY)
+ pw = decrypt(CONSTANT.Key.DEV_PASSWD, CONSTANT.Key.DEV_KEY)
+ try:
+ try:
+ token = getToken("hwstaff_harmonyos_ci", dname, pw)
+ logger.info("get token end")
+ except Exception as f:
+ logger.error(f)
+ time.sleep(3)
+ logger.info("get token again")
+ token = getToken("hwstaff_harmonyos_ci", dname, pw)
+ logger.info("get token again end")
+ heard = {'Range': 'Bytes=%s-%s' % (start, end), "content-type": "application/json;charset=UTF-8",
+ "X-Language": "zh-cn", "X-Auth-Token": token}
+ try:
+ res = requests.get(link, headers=heard, stream=True, timeout=240)
+ logger.info("connect status: %s" % res.status_code)
+ except Exception as p:
+ logger.error(p)
+ time.sleep(3)
+ logger.info("connect again!")
+ res = requests.get(link, headers=heard, stream=True, timeout=240)
+ logger.info("connect again status: %s" % res.status_code)
+ fd.seek(start)
+ fd.write(res.content)
+ if res.status_code == 206 or res.status_code == 200:
+ if not os.path.isfile(destination_file):
+ logger.error('download link file and write file error')
+ return False
+ else:
+ logger.error("downloadFromDevCloud fail, error: %s" % res)
+ return False
+ except Exception as e:
+ traceback.print_exc()
+ logger.error(e)
+
+
+def decrypt(text, key):
+ from Crypto.Cipher import AES
+ from binascii import a2b_hex
+ cryptor = AES.new(key.encode('utf-8'), AES.MODE_CBC, b'0000000000000000')
+ plain_text = cryptor.decrypt(a2b_hex(text))
+ return bytes.decode(plain_text).rstrip('\0')
+
+
+def run_download(link, path):
+ try:
+ num = 3
+ r = requests.head(link)
+ total = int(r.headers['Content-Length'])
+ logger.info('total is %s' % total)
+ ranges = []
+ offset = int(total / num)
+ for i in range(num):
+ if i == num - 1:
+ ranges.append((i * offset, ''))
+ else:
+ ranges.append((i * offset, (i + 1) * offset))
+ # 淇濆瓨鏂囦欢鎵撳紑瀵硅薄
+ if "file_id=" in link:
+ if link.endswith(".tar.gz"):
+ file_name = link.split('=')[-1]
+ else:
+ file_name = "out.tar.gz"
+ else:
+ file_name = link.split('/')[-1]
+ destination_file = os.path.join(path, file_name)
+ logger.info('file_name is %s' % file_name)
+ logger.info('destination_file is %s' % destination_file)
+ if not os.path.isdir(path):
+ os.makedirs(path)
+ if os.path.isfile(destination_file):
+ logger.info('%s is exit' % destination_file)
+ return True
+ # 淇濆瓨鏂囦欢鎵撳紑瀵硅薄
+ logger.info("downloadFileFromDevCloud start")
+ logger.info(link)
+ thread_list = []
+ # 涓涓暟瀛,鐢ㄦ潵鏍囪鎵撳嵃姣忎釜绾跨▼
+ n = 0
+ for ran in ranges:
+ start, end = ran
+ # 鎵撳嵃淇℃伅
+ logger.info('thread %d start:%s,end:%s' % (n, start, end))
+ n += 1
+ # 鍒涘缓绾跨▼ 浼犲弬,澶勭悊鍑芥暟涓篸ownload
+ thread = threading.Thread(target=downloadFileFromDevCloud, args=(link, destination_file, start, end))
+ # 鍚姩
+ thread.start()
+ thread_list.append(thread)
+ for i in thread_list:
+ # 璁剧疆绛夊緟
+ i.join()
+ if os.path.isfile(destination_file):
+ logger.info('%s is exit' % destination_file)
+ return True
+ return False
+ except Exception as p:
+ logger.error(p)
+ return False
\ No newline at end of file
diff --git a/DeployDevice/src/aw/Download/Downloadold.py b/DeployDevice/src/aw/Download/Downloadold.py
new file mode 100644
index 0000000000000000000000000000000000000000..0bb37aac8b7fa84c26a5876cff1c647a189cf0cb
--- /dev/null
+++ b/DeployDevice/src/aw/Download/Downloadold.py
@@ -0,0 +1,579 @@
+# encoding=utf-8
+
+"""
+======================================================================================
+copyright (C) 2018-2019, Huawei Technologies Co.
+========================================================================================
+@鏂囦欢鍚嶇О: Download.py
+@鎻忚堪: 鏂囦欢涓嬭浇鐩稿叧鍔ㄤ綔
+@浣滆: lwx587017
+@鐢熸垚鏃ユ湡: 20181019
+======================================================================================
+"""
+import codecs
+import os
+import shutil
+import urllib
+import time
+import sys
+import re
+import datetime
+import subprocess
+import platform
+import traceback
+import requests
+import json
+import threading
+import zipfile
+
+# from util.config import *
+from util.log_info import logger
+from util.time_info import get_now_time_str_info, timeout
+
+current_path = os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
+BitCometjar = os.path.join(current_path, "Resource", "thirdtools", "TTorrentFull.jar")
+from aw.Common.Constant import CONSTANT
+
+from aw.Common.Common import subProcessPopen, copyFile
+
+
+Aria2cbin = CONSTANT.SysTool.ARIA2CBIN
+
+def downloadByBitComet(source_path, download_dir, os_method):
+ '''
+ #===================================================================================
+ # @Method: downloadByBitComet(source_path, dest_path)
+ # @Precondition: none
+ # @Func: 閫氳繃bt涓嬭浇锛屽皢璧勬簮鏂囦欢涓嬭浇鍒版湰鍦
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # os_method:缁戝畾鎿嶄綔绯荤粺鐢ㄥ埌鍏叡鏂规硶鐨勫璞
+ # @eg: downloadByBitComet锛"xxxx", "D:\\local\\image", os_method锛
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ server_ip = "100.104.224.115"
+ server_port = "2976"
+ source_path = source_path.replace(' ', '%20')
+ torrent_exist_url = "http://" + server_ip + ":" + server_port + "/centerDistributeService/BtCenter/addTaskDistribute?path=" \
+ + source_path
+ logger.info(torrent_exist_url)
+ version_path, destdir = os.path.split(download_dir)
+
+ exist_log = os.path.join(version_path, destdir + "_exist.log")
+ ret = False
+ for _ in range(600):
+ urllib.request.urlretrieve(torrent_exist_url, exist_log)
+ if os.path.isfile(exist_log):
+ open_file = codecs.open(exist_log, "r", "utf-8")
+ content = open_file.readline()
+ if str(content).find("\"status\":\"done\"") != -1:
+ ret = True
+ logger.info("The torrent of %s created seccessfully" % source_path)
+ break
+ else:
+ time.sleep(6)
+ logger.info("The torrent of %s is creating , please wait for a moment" % source_path)
+ continue
+ logger.info(ret)
+ if not ret:
+ logger.info("The torrent of %s created failed" % source_path)
+ return False
+ torrent_down_url = "http://" + server_ip + ":" + server_port + "/centerDistributeService/BtCenter/seed?path=" \
+ + source_path
+ download_torrent = os.path.join(version_path, destdir + ".torrent")
+ for _ in range(3):
+ urllib.request.urlretrieve(torrent_down_url, download_torrent)
+ if os.path.isfile(download_torrent):
+ ret = False
+ logger.info("The torrent of %s downloaded successed" % source_path)
+ break
+ else:
+ time.sleep(3)
+ continue
+ if ret:
+ logger.info("The torrent of %s downloaded failed" % source_path)
+ return False
+
+ if os.path.isfile(Aria2cbin):
+ BT_Command = "aria2c -l - -d %s --enable-dht=false --seed-time=0 --log-level=warn \
+ --max-download-limit=50M --bt-stop-timeout=120 %s" % (version_path, download_torrent)
+ else:
+ BT_Command = "java -cp %s com.turn.ttorrent.demo.Downloader %s %s" % (
+ BitCometjar, download_torrent, version_path)
+ result = os.system(BT_Command)
+ if result:
+ logger.error("BT-Downloader returns: %s, download failed." % result)
+ return False
+ for ld in os.listdir(version_path):
+ if len(ld) == 32 and os.path.isdir(os.path.join(version_path, ld)):
+ copyDirectory(os.path.join(version_path, ld), download_dir, os_method)
+ shutil.rmtree(os.path.join(version_path, ld), True)
+ return True
+
+def waitotherdown(suc_mark):
+ '''
+ #===================================================================================
+ # @Method: waitotherdown(suc_mark)
+ # @Precondition: none
+ # @Func: 濡傛灉鐗堟湰鐩稿悓涓旀鐗堟湰娌′笅杞芥垚鍔熻繃锛屼細绛夊緟姝e湪涓嬭浇鐨勪换鍔″幓涓嬭浇锛
+ # 绛夊緟鏃堕暱2灏忔椂锛岃嫢瓒呰繃2灏忔椂姝e湪涓嬭浇鐨勪换鍔¤繕鏈笅杞芥垚鍔燂紝鍒欒嚜琛屼笅杞
+ # @PostStatus: none
+ # @Param: suc_mark锛氭垚鍔熸爣蹇楁枃浠剁殑璺緞
+ # @eg: waitotherdown("xxx\\suc.txt")
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ logger.info("wait other process download")
+ for i in range(240):
+ checktime = 5
+ time.sleep(checktime)
+ if os.path.isfile(suc_mark):
+ logger.info("%s exists. Package has been download successfully" \
+ " by other process." % suc_mark)
+ break
+ if i == 239:
+ logger.error("wait other process download timeout")
+ return False
+ return True
+
+def isDownLoadSuccess(download_dir, suc_mark, failed_mark):
+ '''
+ #===================================================================================
+ # @Method: isDownLoadSuccess(download_dir, suc_mark, failed_mark)
+ # @Precondition: none
+ # @Func: 涓嬭浇鏂囦欢鍓嶏紝鍒ゆ柇姝ゆ枃浠舵槸鍚﹀凡涓嬭浇鎴愬姛鎴栧け璐ワ紝鏈変笅杞藉け璐ユ爣蹇楋紝鍒欓噸鏂颁笅杞
+ # ,鑻ユ鏂囦欢鏈笅杞借繃锛屽垯鍒涘缓鏂囦欢澶归噸鏂颁笅杞
+ # @PostStatus: none
+ # @Param: download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰勮矾寰
+ # suc_mark锛氭垚鍔熸爣蹇楁枃浠剁殑璺緞
+ # @eg: isDownLoadSuccess("xxx", "xxx\\suc.txt", "xxx\\fail.txt")
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ if os.path.isfile(suc_mark):
+ logger.info("%s has been download by other process." % download_dir)
+ return True
+ elif os.path.isfile(failed_mark):
+ logger.info("%s exists. Other process has download package and failed. It will download by self" % failed_mark)
+ os.remove(failed_mark)
+ else:
+ try:
+ #濡傛灉褰撳墠鐗堟湰鐨勭洰褰曞瓨鍦紝鍒欒涓虹増鏈凡缁忎笅杞
+ if not os.path.isdir(download_dir):
+ logger.debug("mkdir %s" % download_dir)
+ os.makedirs(download_dir)
+ else:
+ logger.debug("%s is already downloading by other process,please wait for a moment!" % download_dir)
+ ret = waitotherdown(suc_mark)
+ return ret
+ except Exception as e:
+ logger.error("make dir fail with %s" % e)
+ shutil.rmtree(download_dir)
+
+ return False
+
+def saveVersion(save_path_file, versionsavepath):
+ '''
+ #===================================================================================
+ # @Method: saveVersion(save_path_file, versionsavepath)
+ # @Precondition: none
+ # @Func: 姝ゆ柟娉曠敤浜庢枃浠朵笅杞斤紝濡傛灉鏂囦欢涓嬭浇鎴愬姛锛屽氨缂撳瓨鐗堟湰璁板綍鍒皉ecord/xxx.txt涓紝
+ # 鏍煎紡锛/data/MobileUpgrade/local_img/1663de89-4a0b-5b26-bfad-5d2fd7bf0740
+ # @PostStatus: none
+ # @Param: save_path_file锛氭枃浠跺悕绉帮紝渚5c0d84a3a51fff875f8ed4de16791b1c7d3d2cfe.txt
+ # versionsavepath:鏈湴瀛樺偍璺緞
+ # @eg: saveVersion(save_path_file锛 versionsavepath)
+ # @return: None
+ #===================================================================================
+ '''
+ savepath = os.path.dirname(save_path_file)
+ if not os.path.isdir(savepath):
+ logger.debug("mkdir %s" % savepath)
+ os.makedirs(savepath)
+ if os.path.isfile(save_path_file):
+ logger.info("%s exists." % save_path_file)
+ else:
+ logger.info("save_path_file: %s" % save_path_file)
+ with open(save_path_file, "a") as f:
+ f.write(versionsavepath)
+
+def downlaodByDownloadTool(dir_path, version_type, upgrade_type, pbiid):
+ '''
+ #===================================================================================
+ # @Method: downlaodByDownloadTool(dir_path, version_type, upgrade_type, pbiid)
+ # @Precondition: none
+ # @Func: 鐢ㄤ笅杞藉伐鍏锋彁渚涚殑jar鍖呰繘琛屼笅杞斤紝闇瑕佷紶鍏ョ増鏈殑pbiid,鍗囩骇绫诲瀷,鐗堟湰绫诲瀷锛
+ # 鍏蜂綋浣跨敤鏂规硶鍙挩璇wx515469
+ # @PostStatus: none
+ # @Param: dir_path锛氭湰鍦板偍瀛樼増鏈殑璺緞
+ # version_type:鐗堟湰鐨勭被鍨嬶紝濡俹dex,dex,no_log
+ # upgrade_type:鍗囩骇鐨勭被鍨嬶紝濡侳ASTBOOT,SD
+ # pbiid:鐗堟湰鐨刾biid鍙
+ # os_method:缁戝畾鎿嶄綔绯荤粺鐢ㄥ埌鍏叡鏂规硶鐨勫璞
+ # @eg: downlaodByDownloadTool(dir_path, version_type, upgrade_type, pbiid, os_method)
+ # @return: None
+ #===================================================================================
+ '''
+ upgrade_type = upgrade_type.upper()
+ jar_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))), "resource", "thirdtools", "downloadTool.jar")
+ os_name = platform.system()
+ logger.debug("copy res to dir_path")
+ res_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))), "resource", "thirdtools", "res")
+ local_res_path = os.path.join(dir_path, "res")
+ if not os.path.isdir(local_res_path):
+ os.makedirs(local_res_path)
+ if os_method.copyDirectory(res_path, local_res_path):
+ logger.info("copy res to the local image path sucess")
+ else:
+ logger.info("copy res to the local image path fail")
+ return False
+ if (os_name == "Linux"):
+ jar_cmd = "cd %s & java -jar %s %s %s:%s" % (dir_path, jar_path, pbiid, upgrade_type, version_type)
+ else:
+ jar_cmd = "D: & cd %s & java -jar %s %s %s:%s" % (dir_path, jar_path, pbiid, upgrade_type, version_type)
+ logger.info("download by download.jar,cmd is %s" % jar_cmd)
+ ret = subprocess.getoutput(jar_cmd)
+ logger.info("the result is %s after excute downloadTool.jar" % ret)
+ if "download success" in ret:
+ list_jardir = os.listdir(dir_path)
+ for dir in list_jardir:
+ jardir = os.path.join(dir_path, dir)
+ if os.path.isdir(jardir) and jardir != "res":
+ os.rename(jardir, os.path.join(dir_path, "jarimg"))
+ break
+ logger.info("download success by downloadjar")
+ return True
+ else:
+ if "failreason" in ret:
+ com = re.search("failreason\((.*)\)", ret)
+ failreason = com.group(1)
+ logger.info("download fail by downloadjar,failreson is %s" % failreason)
+ else:
+ logger.info("download fail by downloadjar,and jartool not support failreason")
+ return False
+
+
+def downloadLinkFileFromHttp(link, path):
+ '''
+ #===================================================================================
+ # @Method: downloadLinkFileFromHttp(link, path)
+ # @Precondition: none
+ # @Func: 閫氳繃http涓嬭浇璧勬簮鏂囦欢鍒版湰鍦
+ # @PostStatus: none
+ # @Param: link锛氳祫婧愭枃浠惰矾寰
+ # path:鏈湴鏂囦欢璺緞
+ # @eg: downloadLinkFileFromHttp("http:xxx", "D:\local_img")
+ # @return: True or False
+ #===================================================================================
+ '''
+ file_name = link.split('/')[-1]
+ destination_file = os.path.join(path, file_name)
+ logger.info('file_name is %s' % file_name)
+ logger.info('destination_file is %s' % destination_file)
+ if not os.path.isdir(path):
+ os.makedirs(path)
+ if not os.path.isfile(destination_file):
+ downloadFileFromHttp(link, destination_file)
+
+ if not os.path.isfile(destination_file):
+ logger.error('download link file error')
+ return False
+ else:
+ return True
+
+
+def downloadFileFromHttp(file_link, destination_file):
+ '''
+ #===================================================================================
+ # @Method: downloadFileFromHttp(file_link, destination_file)
+ # @Precondition: none
+ # @Func: 閫氳繃http鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: file_link锛氳祫婧愭枃浠惰矾寰
+ # destination_file:鏈湴鏂囦欢璺緞
+ # @eg: destination_file("http:xxx", "D:\local_img")
+ # @return: None
+ #===================================================================================
+ '''
+ import urllib
+ logger.info("download file from %s to %s" % (file_link, destination_file))
+ urllib.request.urlretrieve(file_link, destination_file, scheduleDownloadPercent)
+
+
+def scheduleDownloadPercent(downloadsize, blocksize, filesize):
+ '''
+ #===================================================================================
+ # @Method: scheduleDownloadPercent(downloadsize, blocksize, filesize)
+ # @Precondition: none
+ # @Func: 鎵撳嵃褰撳墠涓嬭浇鐨勮繘搴︼紝鐢ㄧ櫨鍒嗘瘮褰㈠紡鏄剧ず
+ # @PostStatus: none
+ # @Param: downloadsize锛氬凡涓嬭浇鏂囦欢鐨勫ぇ灏
+ # blocksize:涓嬭浇鍧楁暟
+ # filesize:鎬绘枃浠跺ぇ灏
+ # @eg: scheduleDownloadPercent(xxx,2,xxx )
+ # @return: None
+ #===================================================================================
+ '''
+ percent = 100.0 * downloadsize * blocksize / filesize
+ if percent >= 100 :
+ percent = 100
+ downloadpercent = 100
+ percent = float("%.4f" % percent)
+ if percent % 1 == 0:
+ logger.info("file download percent:%.0f%%" % percent)
+
+
+def downloadByCopyWindows(source_path, download_dir, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, is_file, params)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ # @eg: excutedown("xxxx", "D:\\local\\image", Flase)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ try:
+ if not is_file:
+ for f in os.listdir(source_path):
+ file_name = os.path.join(source_path, f)
+ child_path = os.path.join(download_dir, f)
+ if os.path.isfile(file_name):
+ copyFile(file_name, child_path, 32 * 1024)
+ if not os.path.isfile(child_path):
+ logger.error("Copy %s to %s failed" % (file_name, child_path))
+ return False
+ logger.info("Copy %s to %s successful" % (file_name, child_path))
+ else:
+ if not os.path.isdir(child_path):
+ logger.info("Mkdir %s successful" % child_path)
+ os.makedirs(child_path)
+ ret = downloadByCopyWindows(file_name, child_path, False)
+ if not ret:
+ return False
+ else:
+ copyFile(source_path, download_dir)
+ return True
+ except Exception as e:
+ logger.error(e)
+ return False
+ return True
+
+def downloadByCopyLinux(source_path, download_dir, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, is_file, params)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ # @eg: excutedown("xxxx", "D:\\local\\image", Flase)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ try:
+ region = ""
+ source_path = source_path.replace("\\", "/")
+ temp = source_path.split("/")
+ host, share, path, file = '', '', '', ''
+ if is_file:
+ file = temp.pop()
+ else:
+ file = '*'
+ for i in temp:
+ if i:
+ if not host:
+ host = i
+ elif not share:
+ share = i
+ else:
+ path = os.path.join(path, i)
+ else:
+ continue
+ cmd = ("smbclient //%s/%s" % (host, share) + " -U CHINA/"
+ + CONSTANT.OSType.ACCOUNT
+ + "%'"
+ + CONSTANT.OSType.PASSWORD
+ + "' -c 'cd \"%s\"'" % path)
+ result = subProcessPopen(cmd)
+ if not result["ret"]:
+ logger.error("invalid samba path.")
+ return False
+ cmd = ("smbclient //%s/%s" % (host, share) + " -U CHINA/"
+ + CONSTANT.OSType.ACCOUNT
+ + "%'"
+ + CONSTANT.OSType.PASSWORD)
+ if region == "green":
+ cmd = cmd + "' -m SMB2 -c 'cd \"%s\";prompt OFF;recurse ON;lcd %s;mget %s'" % (path, download_dir, file)
+ else:
+ cmd = cmd + "' -c 'cd \"%s\";prompt OFF;recurse ON;lcd %s;mget %s'" % (path, download_dir, file)
+ logger.debug(cmd)
+ result = subProcessPopen(cmd)
+ if ("connect failed" in str(result["out"]) or "NT_STATUS_IO_TIMEOUT" in str(result["out"])) or (
+ not result["ret"]):
+ return False
+ else:
+ return True
+ except Exception:
+ traceback.print_exc()
+ return False
+
+def downloadByCopy(source_path, download_dir, is_file):
+ os_name = platform.system()
+ if os_name == "Windows":
+ return downloadByCopyWindows(source_path, download_dir, is_file)
+ if os_name == "Linux":
+ return downloadByCopyLinux(source_path, download_dir, is_file)
+
+def getToken(domin_name, name, password):
+ '''
+ #===================================================================================
+ # @Method: getToken(domin_name, name, passwd, proxy)
+ # @Precondition: none
+ # @Func: 閫氳繃http涓嬭浇钃濆尯鏂囦欢
+ # @PostStatus: none
+ # @Param: domin_name: 甯愬彿鍚
+ # username锛氱敤鎴峰悕
+ # password锛氬瘑鐮
+ #
+ # @eg: getToken("xxx", "xxx", "xxx")
+ # @return: None
+ #===================================================================================
+ '''
+ body_1 = {
+ "auth": {
+ "identity": {
+ "methods": [
+ "password"
+ ],
+ "password": {
+ "user": {
+ "domain": {
+ "name": domin_name
+ },
+ "name": name,
+ "password": password
+ }
+ }
+ },
+ "scope": {
+ "project": {
+ "name": "cn-north-4"
+ }
+ }
+ }
+ }
+ header_1 = {"content-type":"application/json;charset=UTF-8"}
+ resp = requests.request("POST", "https://iam.myhuaweicloud.com/v3/auth/tokens", data=json.dumps(body_1), headers=header_1)
+ #print("auth result:", resp.status_code, resp.headers)
+ return resp.headers.get("X-Subject-Token")
+
+def downloadFileFromDevCloud(link, destination_file, start, end):
+ '''
+ #===================================================================================
+ # @Method: downloadFileFromDevCloud(link, username, password, path)
+ # @Precondition: none
+ # @Func: 閫氳繃http涓嬭浇钃濆尯鏂囦欢
+ # @PostStatus: none
+ # @Param: link锛氳祫婧愭枃浠惰矾寰
+ # username锛氱敤鎴峰悕
+ # password锛氬瘑鐮
+ # path:鏈湴鏂囦欢璺緞
+ # @eg: downloadFileFromDevCloud("http:xxx", "xxx", "xxx","D:\local_img")
+ # @return: None
+ #===================================================================================
+ '''
+ fd = open(destination_file, 'wb+')
+ dname = decrypt(CONSTANT.Key.DEV_DNAME, CONSTANT.Key.DEV_KEY)
+ pw = decrypt(CONSTANT.Key.DEV_PASSWD, CONSTANT.Key.DEV_KEY)
+ token = getToken("hwstaff_harmonyos_ci", dname, pw)
+ logger.info("get token end")
+ heard = {'Range': 'Bytes=%s-%s' % (start, end), "content-type": "application/json;charset=UTF-8", "X-Language": "zh-cn", "X-Auth-Token": token}
+ res = requests.get(link, headers=heard, stream=True, timeout=600)
+ logger.info("connect status: %s" % res.status_code)
+ fd.seek(start)
+ fd.write(res.content)
+ try:
+ if res.status_code == 206 or res.status_code == 200:
+ if not os.path.isfile(destination_file):
+ logger.error('download link file and write file error')
+ return False
+ else:
+ logger.error("downloadFromDevCloud fail, error: %s" % res)
+ return False
+ except Exception as e:
+ traceback.print_exc()
+ logger.error(e)
+
+
+
+def decrypt(text, key):
+ from Crypto.Cipher import AES
+ from binascii import a2b_hex
+
+ cryptor = AES.new(key.encode('utf-8'), AES.MODE_CBC, b'0000000000000000')
+ plain_text = cryptor.decrypt(a2b_hex(text))
+ return bytes.decode(plain_text).rstrip('\0')
+
+
+def run_download(link, path):
+ num = 6
+ r = requests.head(link)
+ total = int(r.headers['Content-Length'])
+ logger.info('total is %s' % total)
+ ranges = []
+ offset = int(total / num)
+ for i in range(num):
+ if i == num - 1:
+ ranges.append((i * offset, ''))
+ else:
+ ranges.append((i * offset, (i + 1) * offset))
+ # 淇濆瓨鏂囦欢鎵撳紑瀵硅薄
+ if "file_id=" in link:
+ if link.endswith(".tar.gz"):
+ file_name = link.split('=')[-1]
+ else:
+ file_name = "out.tar.gz"
+ else:
+ file_name = link.split('/')[-1]
+
+ destination_file = os.path.join(path, file_name)
+ logger.info('file_name is %s' % file_name)
+ logger.info('destination_file is %s' % destination_file)
+ if not os.path.isdir(path):
+ os.makedirs(path)
+ if os.path.isfile(destination_file):
+ logger.info('%s is exit' % destination_file)
+ return True
+ # 淇濆瓨鏂囦欢鎵撳紑瀵硅薄
+ logger.info("downloadFileFromDevCloud start")
+ logger.info(link)
+ thread_list = []
+ # 涓涓暟瀛,鐢ㄦ潵鏍囪鎵撳嵃姣忎釜绾跨▼
+ n = 0
+ for ran in ranges:
+ start, end = ran
+ # 鎵撳嵃淇℃伅
+ logger.info('thread %d start:%s,end:%s' % (n, start, end))
+ n += 1
+ # 鍒涘缓绾跨▼ 浼犲弬,澶勭悊鍑芥暟涓篸ownload
+ thread = threading.Thread(target=downloadFileFromDevCloud, args=(link, destination_file, start, end))
+ # 鍚姩
+ thread.start()
+ thread_list.append(thread)
+ for i in thread_list:
+ # 璁剧疆绛夊緟
+ i.join()
+ if os.path.isfile(destination_file):
+ logger.info('%s is exit' % destination_file)
+ return True
+ return False
+
diff --git a/DeployDevice/src/aw/Download/__init__.py b/DeployDevice/src/aw/Download/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/DeployDevice/src/aw/ExtractFile/ExtractFile.py b/DeployDevice/src/aw/ExtractFile/ExtractFile.py
new file mode 100644
index 0000000000000000000000000000000000000000..2e2f45b8e3edf71581e55ea22a1cf4de0ef94743
--- /dev/null
+++ b/DeployDevice/src/aw/ExtractFile/ExtractFile.py
@@ -0,0 +1,124 @@
+# encoding=utf-8
+
+"""
+======================================================================================
+copyright (C) 2018-2019, Huawei Technologies Co.
+========================================================================================
+@鏂囦欢鍚嶇О: Download.py
+@鎻忚堪: 鏂囦欢涓嬭浇鐩稿叧鍔ㄤ綔
+@浣滆: lwx587017
+@鐢熸垚鏃ユ湡: 20181019
+======================================================================================
+"""
+import os
+import tarfile
+from aw.Common.Common import copyFile, copyDirectory
+from util.log_info import logger
+
+def extractZipFile(zip_file, extract_dir):
+ '''
+ #===================================================================================
+ # @Method: extractZipFile(zip_file, download_dir)
+ # @Precondition: none
+ # @Func: 鎶婂帇缂╂枃浠惰В鍘嬪埌鎸囧畾鐩綍
+ # @PostStatus: none
+ # @Param: zip_file锛氬帇缂╂枃浠惰矾寰
+ # extract_dir:瑙e帇鐨勭洰鏍囨枃浠跺す
+ # params:宸茶幏鍙栭渶瑕佸弬鏁扮殑瀛楀吀
+ # os_method:缁戝畾鎿嶄綔绯荤粺鐢ㄥ埌鍏叡鏂规硶鐨勫璞
+ # @eg: excutedown("xxxx", "D:\\local\\image", Flase, {"xxx":"xxx"}, os_method)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ if not os.path.isfile(zip_file):
+ logger.error("Decompress package failed.")
+ return False
+ import zipfile
+ if not os.path.isdir(extract_dir):
+ os.mkdir(extract_dir)
+
+ f = zipfile.ZipFile(zip_file)
+ f.extractall(extract_dir)
+ f.close()
+ zfile = None
+ try:
+ zfile = zipfile.ZipFile(zip_file)
+ for file_name in zfile.namelist():
+ if file_name.endswith("filelist.xml") or file_name.endswith(".zip"):
+ file = zfile.extract(file_name, extract_dir)
+ if not os.path.isfile(os.path.join(extract_dir, os.path.basename(file_name))):
+ copyFile(file, extract_dir)
+ return True
+ except Exception as e:
+ logger.error(e)
+ return False
+ finally:
+ if zfile:
+ try:
+ zfile.close()
+ except Exception as e:
+ logger.error(e)
+
+def unTarFile(tar_file, dest_dir):
+ '''
+ #===================================================================================
+ # @Method: unTarFile(tar_file, dest_dir)
+ # @Precondition: none
+ # @Func: 鎶婂帇缂╂枃浠惰В鍘嬪埌鎸囧畾鐩綍
+ # @PostStatus: none
+ # @Param: tar_file锛氬帇缂╂枃浠惰矾寰
+ # dest_dir:瑙e帇鐨勭洰鏍囨枃浠跺す
+ # @eg: excutedown("xxxx", "D:\\local\\image")
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ import platform
+ if platform.system() == "Windows":
+ dest_dir = "\\\\?\\%s" % dest_dir
+ try:
+ logger.info("untar %s to %s " % (tar_file, dest_dir))
+ utar = tarfile.open(tar_file)
+ utar.extractall(path = dest_dir)
+ utar.close()
+ img_path = os.path.join(dest_dir, "resource.img")
+ if not os.path.exists(img_path):
+ logger.error("no img")
+ return False
+ return True
+ except Exception as e:
+ logger.error(e)
+ return False
+
+def backupFile(file):
+ '''
+ #===================================================================================
+ # @Method: backupFile(file)
+ # @Precondition: none
+ # @Func: 澶囦唤鏂囦欢
+ # @PostStatus: none
+ # @Param: file锛氭枃浠跺悕
+ # @eg: backupFile("xxx")
+ # @return: True or False
+ #===================================================================================
+ '''
+ logger.info("file is %s" % file)
+ if not os.path.isfile(file):
+ logger.error("%s file is not exist" % file)
+ return False
+
+ backup_file = file + ".bak"
+ if os.path.exists(backup_file):
+ os.remove(backup_file)
+ try:
+ logger.info("start to backup file and backup_file is %s" % backup_file)
+ os.rename(file, backup_file)
+ except:
+ logger.info("the file may access by another process")
+ time.sleep(10)
+ return False
+
+ if os.path.isfile(file):
+ os.remove(file)
+ return True
+
+
diff --git a/DeployDevice/src/aw/ExtractFile/__init__.py b/DeployDevice/src/aw/ExtractFile/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/DeployDevice/src/aw/Param/UpgradeParam.py b/DeployDevice/src/aw/Param/UpgradeParam.py
new file mode 100644
index 0000000000000000000000000000000000000000..a5d147a958d14c214da2a94d15c44513290f5f90
--- /dev/null
+++ b/DeployDevice/src/aw/Param/UpgradeParam.py
@@ -0,0 +1,114 @@
+# encoding=utf-8
+
+
+"""
+======================================================================================
+copyright (C) 2018-2019, Huawei Technologies Co.
+========================================================================================
+@鏂囦欢鍚嶇О: upgrade_param.py
+@鎻忚堪: 鍙傛暟澶勭悊鐩稿叧鍔ㄤ綔
+@浣滆: lwx587017
+@鐢熸垚鏃ユ湡: 20181015
+======================================================================================
+"""
+import re
+
+
+from util.log_info import logger
+
+
+def validateParams(cust_param):
+ '''
+ #===================================================================================
+ # @Method: validateParams(cust_param)
+ # @Precondition: none
+ # @Func: 鏍¢獙鍙傛暟
+ # @PostStatus: none
+ # @Param: cust_param锛氬崌绾ч渶瑕佺殑鍙傛暟瀛楀吀
+ # @eg: validateParams({鈥渦pgrade_upgradeLocation鈥濓細鈥溾潁)
+ # @return: params_dict锛氭墍鏈夌殑鍙傛暟
+ #===================================================================================
+ '''
+ for key in cust_param:
+ if checkHz(cust_param.get(key)):
+ logger.error("versionpath can't use Chinese")
+ raise UpgradeException(ERROR_VERSION_USE_CHINAESE)
+ if "Location" in key or "param1" in key:
+ if not cust_param.get(key):
+ logger.error("versionpath can't none")
+ raise UpgradeException(ERROR_VERSION_IS_NONE)
+
+ if len(cust_param.get(key)) > 255 :
+ logger.error("versionpath name is too long")
+ raise UpgradeException(ERROR_VERSION_PATH_TOO_LONG)
+ return True
+
+def checkHz(check_str):
+ '''
+ #===================================================================================
+ # @Method: checkHz(check_str)
+ # @Precondition: none
+ # @Func: 鍒ゆ柇鏄惁鏈変腑鏂
+ # @PostStatus: none
+ # @Param: check_str锛氬垽鏂殑瀛楃涓
+ # @eg: checkHz("xxxx")
+ # @return: params_dict锛氭墍鏈夌殑鍙傛暟
+ #===================================================================================
+ '''
+ for ch in check_str:
+ if u'\u4e00' <= ch <= u'\u9fff':
+ return True
+ return False
+
+def getAllParam(param_file):
+ '''
+ #===================================================================================
+ # @Method: getAllParam(param_file)
+ # @Precondition: none
+ # @Func: 瑙f瀽鍙傛暟鏂囦欢鑾峰彇鎵鏈夊弬鏁
+ # @PostStatus: none
+ # @Param: param_file锛氬弬鏁版枃浠
+ # @eg: getAllParam(xxx.properties)
+ # @return: params_dict锛氭墍鏈夌殑鍙傛暟
+ #===================================================================================
+ '''
+ params_dict = {}
+ with open(param_file, 'Ur', encoding="utf-8") as file:
+ for line in file.readlines():
+ line = line.strip()
+ if len(line) != 0:
+ if line.find("=") != -1:
+ str_list = line.split('=')
+ if str_list[0].find("#") != -1:
+ continue
+ else:
+ key = str_list[0].strip()
+ value = line[len(str_list[0]) + 1:].strip()
+ if len(key) != 0 and len(value) != 0:
+ params_dict[key] = value
+
+ #20200423 鍒犻櫎瀵瑰弬鏁拌繘琛岀壒娈婂鐞嗙殑浠g爜
+
+ return params_dict
+
+
+def getCustParam(param_List, params_dict):
+ '''
+ #===================================================================================
+ # @Method: getCustParam(param_List, params_dict)
+ # @Precondition: none
+ # @Func: 鑾峰彇鐢ㄦ埛瀹氬埗鍙傛暟
+ # @PostStatus: none
+ # @Param: param_List锛氱敤鎴风粰鍑虹殑鍙傛暟
+ # params_dict: 鍙傛暟瀛楀吀
+ # @eg: getCustParam([upgrade_upgradeLocation], {upgrade_upgradeLocation:鈥渪xx鈥潁)
+ # @return: cust_param锛氶渶瑕佺殑鍙傛暟
+ #===================================================================================
+ '''
+ if not param_List:
+ cust_param = params_dict
+ return cust_param
+ else:
+ cust_param = {k: params_dict.get(k) for k in params_dict if k in param_List}
+ return cust_param
+
diff --git a/DeployDevice/src/aw/Param/__init__.py b/DeployDevice/src/aw/Param/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/DeployDevice/src/aw/Telnet/TelnetClient.py b/DeployDevice/src/aw/Telnet/TelnetClient.py
new file mode 100644
index 0000000000000000000000000000000000000000..da481b0d3507ce77f97bf62cc597bf697d0e53f6
--- /dev/null
+++ b/DeployDevice/src/aw/Telnet/TelnetClient.py
@@ -0,0 +1,137 @@
+# encoding=utf-8
+
+'''
+======================================================================================
+鐗堟潈 (C) 2015-2020, Huawei Technologies Co., HUTAF xDevice
+========================================================================================
+@FileName: telnet_client.py
+@Function: telnet operation to os
+@Author:
+@Date:
+======================================================================================
+'''
+
+import os
+import platform
+import telnetlib
+import time
+
+from util.log_info import logger
+
+class TelConnect():
+
+ def __init__(self, telip, telport):
+ logger.info("init telnet %s:%s" % (telip, telport))
+ self._host = telip
+ self._port = int(telport)
+ self.__timeout = 10
+ self.device = telnetlib.Telnet(self._host, port=self._port, timeout=self.__timeout)
+
+ def tellogin(self, username, password, endwaittag, timeout):
+ logger.info("telnet login")
+ rets = self.device.read_until(endwaittag, timeout)
+ logger.info("cmd result: %s" % rets)
+ if (endwaittag in rets) or not rets:
+ logger.info("Noneed login")
+ return True
+ else:
+ rets = self.sendCmdAndCheckResult(username.encode('utf-8'), 'Password:', timeout)
+ if rets == False:
+ logger.error("telnet login Failed!!")
+ return False
+ rets = self.sendCmdAndCheckResult(password.encode('utf-8'), endwaittag, timeout)
+ if rets == False:
+ logger.error("telnet login Failed!!")
+ return False
+
+ def sendCmd(self, send_cmd, endtag, timeout):
+ try:
+ logger.info(send_cmd)
+ self.device.write(send_cmd)
+ rets = self.device.read_until(endtag.encode('utf-8'), timeout)
+ return rets.decode('utf-8', 'ignore')
+ except Exception as e:
+ logger.error(e)
+ return False
+
+ def sendEnterCmd(self, endtag, timeout):
+ try:
+ logger.info("send enter to board")
+ i = 0
+ while i < 4:
+ cmd = b'\r\n'
+ rets = self.sendCmd(cmd, endtag, 1)
+ if (endtag in rets):
+ return True
+ logger.info("retry send Enter")
+ i = i + 1
+ return False
+ except Exception as e:
+ logger.error(e)
+ return False
+
+ def sendCmdAndCheckResult(self, cmd, endtag, timeout):
+ try:
+ rets = self.sendCmd(cmd + '\n'.encode('utf-8'), endtag, timeout)
+ logger.info("result: %s" % rets)
+ if (endtag in rets):
+ if (not "error:" in rets.lower()):
+ return True
+ logger.error("cmd not end or cmd failed, please check board !!!")
+ return False
+ except Exception as e:
+ logger.error(e)
+ return False
+
+ def sendCmdAndCheckSucTag(self, cmd, endtag, suctag , timeout):
+ try:
+ rets = self.sendCmd(cmd + '\n'.encode('utf-8'), endtag, timeout)
+ logger.info("result: %s" % rets)
+ if (endtag in rets):
+ if (suctag in rets) or (not "error:" in rets.lower()):
+ return True
+ logger.error("cmd not end or cmd failed, please check board !!!")
+ return False
+ except Exception as e:
+ logger.error(e)
+ return False
+
+ def sendUpgradeCmd(self, sendcmd, endwaittag, suctag, timeout):
+ if suctag:
+ logger.info("cmd is: %s" % sendcmd)
+ return self.sendCmdAndCheckSucTag(sendcmd.encode('utf-8'), endwaittag, suctag, timeout)
+ else:
+ logger.info("cmd is: %s" % sendcmd)
+ return self.sendCmdAndCheckResult(sendcmd.encode('utf-8'), endwaittag, timeout)
+
+ def sendResetCmd(self, endtag, timeout):
+ logger.info("send cmd reset")
+ sendcmd = b'reset\n'
+ try:
+ #rets = self.sendCmd(sendcmd, endtag, timeout)
+ self.device.write(sendcmd)
+ if not self.sendEnterCmd(endtag, timeout):
+ logger.error("send Enter fail")
+ return False
+ return True
+ except Exception as e:
+ logger.error(e)
+ return False
+
+ def getBoardType(self, endtag, timeout):
+ rcvStr = self.sendCmd(b'\r\n', endtag, timeout)
+ if 'HMOS' in rcvStr or 'OHOS' in rcvStr :
+ ostype = 'OHOS'
+ elif 'hisilicon' in rcvStr:
+ ostype = 'uboot'
+ elif ' #' in rcvStr:
+ ostype = 'linux'
+ else:
+ ostype = 'bootrom'
+ logger.info("board type is: %s" % ostype)
+ return ostype
+
+ def close(self):
+ self.device.close()
+
+
diff --git a/DeployDevice/src/aw/Telnet/__init__.py b/DeployDevice/src/aw/Telnet/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/DeployDevice/src/aw/poweronoff/serial_power_on_off.py b/DeployDevice/src/aw/poweronoff/serial_power_on_off.py
new file mode 100644
index 0000000000000000000000000000000000000000..5f73f451f67d6e2fe83694bed645c2dc355b8ceb
--- /dev/null
+++ b/DeployDevice/src/aw/poweronoff/serial_power_on_off.py
@@ -0,0 +1,260 @@
+import sys, time
+import select
+from socket import socket
+from util.log_info import logger
+
+class SocketCon(socket):
+ def __init__(self, ip, port, timeout=10, encoding="GBK"):
+ '''
+ #===================================================================================
+ # @Method: __init__(self, ip, port,timeout=20,encoding="GBK")
+ # @Func: 鍒濆鍖栨柟娉曪紝鍒涘缓telnet杩炴帴
+ # @Param: ip: ip鍦板潃
+ # port:绔彛鍙
+ # timeout:瓒呮椂鏃堕棿
+ # encoding:瀛楃涓插拰瀛楄妭杞崲鐨勬牸寮
+ # @eg: __init__("127.0.0.1", 7788锛10锛寀tf-8)
+ # @return: none
+ #===================================================================================
+ '''
+ super().__init__()
+ try:
+ self.encoding = encoding
+ self.settimeout(timeout)
+ self.connect((ip, port))
+ except Exception as e:
+ if isinstance(e, ConnectionRefusedError):
+ logger.error("ConnectionRefusedError")
+ else:
+ logger.error(e)
+
+ def closeCon(self):
+ '''
+ #===================================================================================
+ # @Method: __init__(self, ip, port,timeout=20,encoding="GBK")
+ # @Func: 鍏抽棴杩炴帴
+ # @Param: 鏃
+ # @eg: closeCon()
+ # @return: none
+ #===================================================================================
+ '''
+ self.close()
+
+ def send(self, msg):
+ '''
+ #===================================================================================
+ # @Method: send(self锛宮sg)
+ # @Func: 鍙戦佹秷鎭粰box鎴栦覆鍙f湇鍔″櫒
+ # @Param: msg
+ # @eg: send("XDEV USB SIGNal 0 ON")
+ # @return: Bool
+ #===================================================================================
+ '''
+ try:
+ self.sendall(msg.encode(self.encoding))
+ return True
+ except Exception as e:
+ logger.error(e)
+ return False
+
+ def login(self, user="Administrator", password=""):
+ '''
+ #===================================================================================
+ # @Method: login(self锛寀ser,password)
+ # @Func: 涓插彛鏈嶅姟鍣ㄨ璇
+ # @Param: user锛氱敤鎴峰悕
+ # password锛氬瘑鐮
+ # @eg: login("Administrator","")
+ # @return: Bool
+ #===================================================================================
+ '''
+ msg = user + "/" + password
+
+ if self.send(msg):
+ recv = self.receive()
+ if recv == "璁よ瘉閿欒!":
+ return False
+ elif recv == "Error":
+ return False
+ else:
+ return True
+ else:
+ return False
+
+ def receive(self, size=16384):
+ '''
+ #===================================================================================
+ # @Method: receive(self锛寀ser,size)
+ # @Func: 鎺ユ敹杩滅▼涓绘満鎴栦覆鍙f湇鍔″櫒杩斿洖鐨勬秷鎭
+ # @Param: size锛
+ # @eg: receive(16384)
+ # @return: str
+ #===================================================================================
+ '''
+
+ try:
+ ready = select.select([self], [], [], 2)
+ if ready[0]:
+ ret = self.recv(size)
+ if isinstance(ret, bytes):
+ recv = ret.decode(self.encoding)
+ return recv
+ return ""
+ except Exception as e:
+ logger.error(e)
+ return "Error"
+
+
+def serialPowerOnOff(ip, port, index, power, user='Administrator', password=''):
+ '''
+ #===================================================================================
+ # @Method: serialPowerOnOff(ip, port,index,power,user='Administrator', password='')
+ # @Func: 涓婁笅鐢垫墽琛屾柟娉
+ # @Param: ip: 涓插彛鏈嶅姟鍣╥p
+ # port:涓婁笅鐢靛懡浠ょ鍙
+ # index:1-48锛岀數婧愮鍙e簭鍙
+ # power:on/off锛屼笂鐢/涓嬬數鎿嶄綔
+ # user:涓插彛鏈嶅姟鍣ㄧ殑鐢ㄦ埛鍚嶏紝榛樿鍙朅dministrator
+ # password:涓插彛鏈嶅姟鍣ㄧ殑瀵嗙爜锛岄粯璁ゅ彇绌
+ # @eg: serialPowerOnOff("10.176.49.48", 18984锛1锛"on")
+ # @return: none
+ #===================================================================================
+ '''
+ try:
+ serialPort = SocketCon(ip, int(port))
+
+ # 涓插彛鏈嶅姟鍣ㄨ璇
+ if not serialPort.login(user=user, password=password):
+ logger.error("璁よ瘉閿欒")
+ return False
+
+ if power == "on":
+ # 涓插彛涓婄數鎸囦护
+ sendMsg = "ctrlpower." + str(index) + "=On\n"
+ # 涓婄數鎴愬姛棰勬湡杩斿洖娑堟伅
+ recvMsg = "ctrlpower." + str(index) + "=1\n"
+ elif power == "off":
+ # 涓插彛涓嬬數鎸囦护
+ sendMsg = "ctrlpower." + str(index) + "=Off\n"
+ # 涓嬬數鎴愬姛棰勬湡杩斿洖娑堟伅
+ recvMsg = "ctrlpower." + str(index) + "=0\n"
+ else:
+ logger.error("璇风粰on/off鎸囦护")
+ return False
+
+ if serialPort.send(sendMsg):
+ recv = serialPort.receive()
+
+ # 杩斿洖娑堟伅涓庨鏈熺浉鍚岋紝璁や负鎿嶄綔鎴愬姛
+ if recv == recvMsg:
+ logger.info("鎿嶄綔鎴愬姛")
+ return True
+ else:
+ logger.error("鎿嶄綔澶辫触")
+ return False
+ else:
+ logger.error("鎿嶄綔澶辫触")
+ return False
+ except Exception as e:
+ logger.error(e)
+ return False
+ finally:
+ serialPort.closeCon()
+
+def usbPowerOnOff(ip, port, index, power):
+ '''
+ #===================================================================================
+ # @Method: usbPowerOnOff(ip, port)
+ # @Func: GT3000涓婁笅鐢垫墽琛屾柟娉
+ # @Param: ip: box IP
+ # port:GT3000绔彛
+ # index:1-8锛寀sb妲戒綅搴忓彿
+ # power:on/off锛屼笂鐢/涓嬬數鎿嶄綔
+ # @eg: usbPowerOnOff("127.0.0.1", 7788锛"on")
+ # @return: none
+ #===================================================================================
+ '''
+
+ usbpower = SocketCon(ip, int(port))
+
+ try:
+ if power == "on":
+ sendMsg = "XDEV USB POWEr " + str(index) + " ON\n"
+ elif power == "off":
+ sendMsg = "XDEV USB POWEr " + str(index) + " OFF\n"
+ else:
+ logger.info("璇风粰on/off鎸囦护")
+ return False
+
+ # 涓婁笅鐢垫垚鍔熼鏈熻繑鍥炴秷鎭
+ recvMsg = "0,Success\n"
+
+ if usbpower.send(sendMsg):
+ recv = usbpower.receive()
+
+ logger.info(sendMsg)
+ logger.info(recv)
+ # 杩斿洖娑堟伅涓庨鏈熺浉鍚岋紝璁や负鎿嶄綔鎴愬姛
+ if "0" in recv and "Success" in recv:
+ logger.info("鎿嶄綔鎴愬姛")
+ return True
+ else:
+ logger.error("鎿嶄綔澶辫触")
+ return False
+ else:
+ logger.error("鎿嶄綔澶辫触")
+ return False
+ except Exception as e:
+ logger.error(e)
+ return False
+ finally:
+ usbpower.closeCon()
+
+def usbPowerOnOffV2(ip, port, index, power):
+ '''
+ #===================================================================================
+ # @Method: usbPowerOnOff_v2(ip, port)
+ # @Func: GT3000涓婁笅鐢垫墽琛屾柟娉,GT3000鐗堟湰璁婂寲锛屽懡浠ゆ湁璁婂寲
+ # @Param: ip: box IP
+ # port:GT3000绔彛
+ # index:1-8锛寀sb妲戒綅搴忓彿
+ # power:on/off锛屼笂鐢/涓嬬數鎿嶄綔
+ # @eg: usbPowerOnOff("127.0.0.1", 7788锛"on")
+ # @return: none
+ #===================================================================================
+ '''
+
+ usbpower = SocketCon(ip, int(port))
+
+ try:
+ if power == "on":
+ sendMsg = "xdev usb signal " + str(index) + " on\n"
+ elif power == "off":
+ sendMsg = "xdev usb signal " + str(index) + " off\n"
+ else:
+ logger.info("璇风粰on/off鎸囦护")
+ return False
+
+ # 涓婁笅鐢垫垚鍔熼鏈熻繑鍥炴秷鎭
+ recvMsg = "0,Success\n"
+
+ if usbpower.send(sendMsg):
+ recv = usbpower.receive()
+
+ logger.info(sendMsg)
+ logger.info(recv)
+ # 杩斿洖娑堟伅涓庨鏈熺浉鍚岋紝璁や负鎿嶄綔鎴愬姛
+ if "0" in recv and "Success" in recv:
+ logger.info("鎿嶄綔鎴愬姛")
+ return True
+ else:
+ logger.error("鎿嶄綔澶辫触")
+ return False
+ else:
+ logger.error("鎿嶄綔澶辫触")
+ return False
+ except Exception as e:
+ logger.error(e)
+ return False
+ finally:
+ usbpower.closeCon()
\ No newline at end of file
diff --git a/DeployDevice/src/controller.py b/DeployDevice/src/controller.py
new file mode 100644
index 0000000000000000000000000000000000000000..babf2b3fd8deefcdd1f2a34e8aa6a2a53430f67f
--- /dev/null
+++ b/DeployDevice/src/controller.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+
+###############################################################
+###浣滆咃細鐜嬬惁 ###########
+###鍔熻兘锛氭鏋跺叆鍙 ###########
+###鍒涘缓鏃ユ湡锛20200424 ###########
+###############################################################
+###############################################################
+
+import os
+import sys
+import argparse
+from core.run import *
+from aw.Common.Constant import CONSTANT
+from util.log_info import logger
+
+if __name__ == "__main__":
+
+ param_file = sys.argv[1]
+
+ #parm_file鐨勬枃浠舵牸寮忓涓嬶細taskid.properity銆傚繀椤绘槸taskid鍛藉悕鐨勬枃浠
+ cust_steps = parseProperties(param_file)
+
+ errcode = start(cust_steps)
+ if errcode != 0:
+ logger.printLog("鎵ц澶辫触锛氶敊璇俊鎭細" + CONSTANT.ENVERRMESSAGE)
+ logger.printLog(errcode)
+ os._exit(errcode)
+
diff --git a/DeployDevice/src/core/__init__.py b/DeployDevice/src/core/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/DeployDevice/src/core/base.py b/DeployDevice/src/core/base.py
new file mode 100644
index 0000000000000000000000000000000000000000..3868d5d2d468a5b08945bebb307bc688a6db509f
--- /dev/null
+++ b/DeployDevice/src/core/base.py
@@ -0,0 +1,120 @@
+# encoding=utf-8
+
+# from aw.Exception.upgrade_exception import UpgradeException
+from aw.Param import UpgradeParam
+from util.log_info import logger
+
+from aw.Common.Constant import CONSTANT
+
+import platform
+import traceback
+import sys
+import os
+
+from util.time_info import get_now_time_str_info
+
+class BaseApp(object):
+ param_List = None
+ flash_type = None
+
+ def __init__(self, param=None):
+ self.logFilePath = None
+
+ self.TAG = self.__class__.__name__
+
+ self.logFilePath = CONSTANT.OSType.default_log_dir
+
+ if isinstance(param, dict):
+ self.logFilePath = param.get('logFilePath')
+ self.params_dict = param
+ elif isinstance(param, str):
+ param_file_path, param_file_name = os.path.split(param)
+ self.logFilePath = os.path.join(param_file_path, ''.join([param_file_name.split('.')[0], '.log']))
+ self.params_dict = upgrade_param.getAllParam(param)
+ else:
+ # raise UpgradeException(200)
+ pass
+ logger.switchFilePath(self.logFilePath)
+
+
+ def _excuteApp(self, flash_type):
+ # exit_code = 0
+
+ try:
+ ret = self._excute()
+ logger.info(ret)
+ nowtime = get_now_time_str_info()
+ #sn = self.params_dict.get("sn")
+ #os.system("hdc_std -t %s shell reboot loader" % sn)
+ if ret == 98:
+ flash_two(nowtime, flash_type)
+ return 98
+ if ret == 99:
+ flash_two(nowtime, flash_type)
+ return 99
+ if not ret:
+ flash_two(nowtime, flash_type)
+ return -1
+ else:
+ logger.printLog("========================%s %s flash success========================" % (nowtime, flash_type))
+ logger.info("============================= end autotest facoty device flash==================================")
+ return 0
+ # else:
+ # logger.printLog("========================%s %s flash fail========================" % (nowtime, flash_type))
+ # exit_code = -1
+ # raise UpgradeException(ERROR_OTHER_ERROR)
+ # except UpgradeException as e:
+ # nowtime = get_now_time_str_info()
+ # errormessage = e.getUpgradeMessage(e.code)
+ # logger.printLog("%s ========================== %s ===============================" % (nowtime, errormessage))
+ # exit_code = e.code
+ except Exception as e:
+ traceback.print_exc()
+ return 200
+ # finally:
+ # logger.info("============================= end autotest facoty device flash==================================")
+ # return exit_code
+
+
+ def _excute(self):
+ ret = self.excute()
+ return ret
+
+ def parsePropertiesFile(self, all_params):
+ logger.debug('select all params')
+ return all_params
+
+
+ #鍦ㄧ敤鎴风骇瀹炵幇锛屽鏋滅敤鎴风骇娌″疄鐜帮紝灏辩洿鎺ユ姤閿
+ def excute(self):
+ logger.error('No custom executor ,check your APP pls')
+ pass
+
+def dec_stepmsg(excutmsg):
+ '''
+ #===================================================================================
+ # @Method: dec_stepmsg(excutmsg)
+ # @Precondition: none
+ # @Func: 瑁呴グ鍣ㄥ嚱鏁帮紝灏哸pp鎵ц姝ラ鐨勫紑濮嬫椂闂淬佺粨鏉熸椂闂翠互鍙婄浉鍏虫楠や俊鎭墦鍗板埌鎺у埗
+ # 鍙帮紝excutmsg涓烘墽琛屾楠ゆ爣璇嗛渶鑷繁浼犲叆
+ # @PostStatus: excutmsg:鎵ц姝ラ鏍囪瘑
+ # @Param: local_upgrade_hotaLocation: hota澶у寘鍦ㄦ湰鍦扮殑璺緞
+ # @eg: dec_stepmsg("download")
+ # @return: 琚楗板嚱鏁
+ #===================================================================================
+ '''
+ def do_dec(fn):
+ def do(self, *args, **kargs):
+ nowtime = get_now_time_str_info()
+ logger.printLog("========================%s start %s ========================" % (nowtime, excutmsg))
+ ret = fn(self, *args, **kargs)
+ nowtime = get_now_time_str_info()
+ logger.printLog("========================%s end %s ========================" % (nowtime, excutmsg))
+ return ret
+ return do
+ return do_dec
+
+
+def flash_two(nowtime, flash_type):
+ logger.printLog("========================%s %s flash fail========================" % (nowtime, flash_type))
+ logger.info("============================= end autotest facoty device flash==================================")
diff --git a/DeployDevice/src/core/run.py b/DeployDevice/src/core/run.py
new file mode 100644
index 0000000000000000000000000000000000000000..acc0bf07aba705aff155916cd60aa910d5bf70cf
--- /dev/null
+++ b/DeployDevice/src/core/run.py
@@ -0,0 +1,172 @@
+# encoding=utf-8
+
+'''
+Created on 20181019
+
+@author: wangqi10
+@modify data:20200424
+@modify:update for BlueArea
+'''
+import platform
+import sys
+import threading
+import time
+import os
+
+from util.time_info import get_now_time_str_info, get_now_time_info, Timeout, timeout
+from aw.Param.UpgradeParam import getAllParam
+from aw.Common.Constant import CONSTANT
+from util.log_info import logger
+
+def start(param):
+ '''
+ #===================================================================================
+ # @Method: start(param)
+ # @Precondition: none
+ # @Func: 鍏ㄦ祦绋嬫墽琛屾ā鏉匡細1.缁勫悎app鎵ц椤哄簭
+ # 2.鍒濆鍖朼pp锛岃皟鐢╝pp.excute鏂规硶
+ # 3.杩斿洖app鎵ц缁撴灉
+ # @PostStatus: none
+ # @Param: param锛氱敤鎴蜂紶閫掔殑鍙傛暟鍒楄〃
+ # @eg: start()
+ # @return: None
+ #===================================================================================
+ '''
+ if isinstance(param, dict):
+ logger.switchFilePath(param.get("logFilePath"))
+ runstage = param.get("runstage")
+ if runstage == "":
+ CONSTANT.ENVERRMESSAGE = "no runstage"
+ return -1
+ step_list = runstage.split(",")
+ param["step_list"] = step_list
+ for step in step_list:
+ app_name = step
+ app_pyFile = 'func.' + app_name[0: app_name.find('_')] + '.' + app_name
+ #app_class_name = app_name[0: app_name.rfind('_')].capitalize()
+ app_class_name = app_name[0: app_name.rfind('_')]
+ improt_cmd_str = 'from %s import %s as APP' % (app_pyFile, app_class_name)
+ print(improt_cmd_str)
+ logger.info("import_cmd_str:%s" % improt_cmd_str)
+ scope = {}
+ exec(improt_cmd_str, scope)
+ APP = scope.get('APP', 'none')
+ logger.info("APP:%s" % APP)
+ app = APP(param)
+ errorcode = app._excuteApp('upgrade')
+ time.sleep(5)
+ scriptpath =os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
+ loader_tool_path = os.path.join(scriptpath, "resource", "RK3568_tool", "upgrade_tool.exe")
+ logger.info(loader_tool_path)
+ mycmd = "%s LD" % loader_tool_path
+ try:
+ num = send_cmd(mycmd)
+ if num != 2:
+ logger.info("try again!")
+ time.sleep(40)
+ num = send_cmd(mycmd)
+ if num != 2:
+ logger.error("鏈夎澶囨柇杩烇紝鍏ㄩ儴澶勭疆涓虹湡闅旂鐘舵侊紒")
+ errorcode = 200
+ except Exception as f:
+ logger.error(f)
+ logger.info(errorcode)
+ if errorcode == 99:
+ logger.error("upgrade success ,but Smoke failed, the fatal problem occurs.")
+ return 99
+ if errorcode == 98:
+ logger.error("upgrade success ,but Smoke failed, the key problem occurs.")
+ return 98
+ if errorcode == -1:
+ logger.error("upgrade failed.")
+ return 101
+ if errorcode == 200:
+ return -1
+ return 0
+ return 0
+ CONSTANT.ENVERRMESSAGE = "unknown error,please contact the engineer"
+ return -1
+
+
+def send_cmd(mycmd):
+ result = "".join(os.popen(mycmd).readlines())
+ logger.info(result)
+ num = int(result.split("(")[1].split(")")[0])
+ logger.info(num)
+ return num
+
+
+def parseProperties(param_file):
+ '''
+ #===================================================================================
+ # @Method: parseProperties(param_file)
+ # @Precondition: none
+ # @Func: 灏唜xx.properties鏂囦欢瑙f瀽鎴恠tart锛坧aram锛夋柟娉曚腑param鍙傛暟闇瑕佺殑鏍煎紡
+ # @PostStatus: none
+ # @Param: param锛氱敤鎴蜂紶閫掔殑鍙傛暟鍒楄〃
+ # @eg: parseProperties()
+ # @return: None
+ #===================================================================================
+ '''
+ param_dict = getAllParam(param_file)
+
+ #鑾峰彇taskid
+ taskid = "NoTaskidJob"
+ task_path = param_file.split('.')[0]
+ if task_path.rfind("/") > -1:
+ r = task_path.rfind("/")
+ else:
+ r = task_path.rfind("\\")
+ taskid = task_path[r + 1:]
+
+ param_dict["taskId"] = taskid
+ param_dict["logFilePath"] = ''.join([task_path, ".log"])
+
+ return param_dict
+
+
+def saveSuccessVersion(success_version):
+ '''
+ #===================================================================================
+ # @Method: saveSuccessVersion(param_file)
+ # @Precondition: none
+ # @Func: 瀛樺偍鎴愬姛鐨勭増鏈
+ # @PostStatus: none
+ # @Param: param锛氱敤鎴蜂紶閫掔殑鍙傛暟鍒楄〃
+ # @return: None
+ #===================================================================================
+ '''
+ save_path = CONSTANT.Path.getSavePath()
+ try:
+ with open(save_path, 'w') as f:
+ f.write(f'upgrade_upgradeLocation={success_version}')
+ except:
+ logger.info('save success version fail')
+ logger.info('saving success')
+
+
+def send_times(mycmd):
+ times = 0
+ outcome = sendCmd(mycmd)
+ while times < 3:
+ if not outcome or "Empty" in outcome:
+ times += 1
+ time.sleep(3)
+ else:
+ return outcome
+ return outcome
+
+
+def sendCmd(mycmd):
+ result = "".join(os.popen(mycmd).readlines())
+ return result
+
+
+@timeout(30)
+def hdc_kill():
+ logger.info("kill the process")
+ os.system("hdc_std kill")
+ time.sleep(5)
+ logger.info("start the process")
+ os.system("hdc_std start")
+ time.sleep(10)
\ No newline at end of file
diff --git a/DeployDevice/src/func/__init__.py b/DeployDevice/src/func/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/DeployDevice/src/func/liteOsUpgrade/__init__.py b/DeployDevice/src/func/liteOsUpgrade/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L0_app.py b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L0_app.py
new file mode 100644
index 0000000000000000000000000000000000000000..f0a7398687f90f12cacea7e14a6c34f7a769a1c1
--- /dev/null
+++ b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L0_app.py
@@ -0,0 +1,234 @@
+#-*- coding:utf-8 -*-
+import uuid
+import sys
+import subprocess
+
+from core.base import BaseApp, dec_stepmsg
+from util.file_locker import FileLock
+from util.log_info import logger
+from util.time_info import get_now_time_str_info, get_now_time_info, Timeout, timeout
+from aw.Download.Download import *
+from aw.Common.Constant import CONSTANT
+from aw.Common.Common import getFileName
+from aw.ExtractFile.ExtractFile import *
+
+lock_suffix = CONSTANT.File.LOCK_SUFFIX
+suc_file = CONSTANT.File.SUC_FILE
+failed_file = CONSTANT.File.FAILED_FILE
+REBOOT_TIMEOUT = 20000000
+
+class liteOsUpgrade_L0(BaseApp):
+ '''
+ @author: zwx877058
+ '''
+
+ def __init__(self, param_file):
+ super().__init__(param_file)
+ self.param_List = ["upgrade_upgradeLocation",
+ "sn"]
+
+ @dec_stepmsg("hongmeng L0 flash")
+ def excute(self):
+ '''
+ #===================================================================================
+ # @Method: excute(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鎵ц鍏ュ彛
+ # @PostStatus: none
+ # @eg: excute()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ step_index = self.params_dict.get("step_list").index("liteOsUpgrade_L0_app")
+
+ # 鎵ц涓嬭浇
+ try:
+ if not self.download():
+ nowtime = get_now_time_str_info()
+ logger.printLog("image download fail" )
+ return False
+ except Exception as e:
+ logger.error(e)
+ raise e
+
+ if self.params_dict.get("isUpdate") == "False":
+ logger.printLog("no need upgrade board")
+ return True
+
+ # 鎵ц鍗囩骇
+ try:
+ if not self.upgrade():
+ logger.printLog("%s upgrade fail")
+ return False
+ return True
+ except Exception as e:
+ logger.error(e)
+ raise e
+
+ def getupgradeport(self):
+ '''
+ #===================================================================================
+ # @Method: getupgradeport(self)
+ # @Precondition: none
+ # @Func: 鑾峰彇鍗囩骇鐨勭鍙e彿
+ # @PostStatus: none
+ # @eg: upgrade()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ coms_info = list_ports.comports()
+ com_list = []
+ cmd_keyword = "Ch A"
+ up_keyword = "Ch B"
+ logger.printLog(coms_info)
+ for com_info in coms_info:
+ if cmd_keyword in com_info[1]:
+ logger.printLog("get upgrade port is %s" % com_info[0])
+ self.cmd_com = com_info[0]
+ if up_keyword in com_info[1]:
+ logger.printLog("get upgrade port is %s" % com_info[0])
+ self.deploy_com = com_info[0]
+ return True
+
+ @dec_stepmsg("upgrade")
+ @timeout(1200)
+ def upgrade(self):
+ '''
+ #===================================================================================
+ # @Method: upgrade(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鐩稿叧涓氬姟閫昏緫
+ # @PostStatus: none
+ # @eg: upgrade()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ # 璋冪敤ES鎺ュ彛棰勭暀
+ logger.info("send_es_mark")
+ if self.params_dict.get("pbiid"):
+ local_image_path = os.path.join(version_savepath, "jarimg", "FASTBOOT", self.params_dict.get("version_type"))
+ logger.info("img path : %s" % local_image_path)
+ else:
+ local_image_path = os.path.join(version_savepath, "img")
+ current_tool_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))))
+ local_tool_path = os.path.join(current_tool_path, "resource", "L0")
+
+ #鏂规硶涓
+ upgrade_file_name = getFileName(local_tool_path, CONSTANT.OSType.getscripttype())
+ upgrade_command = "%s %s %s %s >> %s 2>&1" % (upgrade_file_name, local_tool_path, self.cmd_com, self.deploy_com, local_image_path, logger.log_file_path)
+ return subprocess.call(upgrade_command, shell=True)
+
+ @dec_stepmsg("download")
+ @timeout(1800)
+ def download(self):
+ '''
+ #===================================================================================
+ # @Method: download(self)
+ # @Precondition: none
+ # @Func: 鏋勫缓涓嬭浇鍒版湰鍦扮殑璺緞锛屾墽琛岀浉搴斿寘鐨勪笅杞
+ # @PostStatus: none
+ # @eg: download()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global version_savepath, version_name
+ dir_path = CONSTANT.Path.getDirPath()
+ if self.params_dict.get("pbiid"):
+ version_path = self.params_dict.get("pbiid")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, str(self.params_dict.get("pbiid")) + "FASTBOOT"))
+ version_savepath = os.path.join(dir_path, self.params_dict.get("flash_type"), version_name)
+ else:
+ version_path = self.params_dict.get("upgrade_upgradeLocation")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, (self.params_dict.get("upgrade_upgradeLocation"))))
+ version_savepath = os.path.join(dir_path, version_name, "img")
+ #鎵цimg涓嬭浇
+
+ if self.params_dict.get("isDownload") == "True":
+ logger.printLog("涓嶉渶瑕佸仛涓嬭浇锛岀洿鎺ヨ繑鍥")
+ return True
+
+ import hashlib
+ save_file_str = version_path.replace("/", "").replace("\\", "")
+ save_file_name = hashlib.sha1(save_file_str.encode("utf-8")).hexdigest()
+ logger.info("download hash string:%s, hash value:%s" % (save_file_str, save_file_name))
+ save_path_file = os.path.join(dir_path, "record", "%s%s" % (save_file_name, ".txt"))
+ if not self.excutedown(version_path, version_savepath, save_path_file, False):
+ logger.error("download img fail")
+ return False
+
+ #淇濆瓨鏈湴鐗堟湰璺緞缁檇evicetest鍘荤増鏈矾寰勪笅鍙栫敤渚
+ saveVersion(save_path_file, version_savepath)
+ return True
+
+ def excutedown(self, source_path, download_dir, suc_mark, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, suc_mark, is_file)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ # @eg: excutedown("xxxx", "D:\\local\\image", suc_mark, Flase)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ failed_mark = os.path.join(download_dir, failed_file)
+ lock_path = os.path.join(download_dir, lock_suffix)
+ file_lock = FileLock()
+
+ if isDownLoadSuccess(download_dir, suc_mark, failed_mark):
+ return True
+ try:
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s Downloading, please wait" % nowtime)
+ file_lock.lockFile(lock_path)
+ ret = ""
+ logger.info("Get lock. Start to ")
+ if self.params_dict.get("bt_enable") and self.params_dict.get("bt_enable") == "True":
+ ret = downloadByBitComet(source_path, download_dir, os_method)
+ elif source_path.startswith('\\\\'):
+ ret = downloadByCopy(source_path, download_dir, is_file)
+ elif self.params_dict.get("pbiid"):
+ ret = downlaodByDownloadTool(version_savepath, self.params_dict.get("version_type"), "FASTBOOT", self.params_dict.get("pbiid"))
+ elif source_path.startswith("http"):
+ ret = downloadFileFromDevCloud(source_path, "", "", download_dir)
+
+ if source_path.endswith(".zip"):
+ zip_name = os.path.basename(source_path)
+ ret = extractZipFile(os.path.join(download_dir, zip_name), download_dir)
+ if source_path.endswith(".tar.gz") or (source_path.startswith("http") and ("file_id=" in source_path)):
+ if source_path.startswith("http") and ("file_id=" in source_path):
+ if source_path.endswith(".tar.gz"):
+ zip_name = source_path.split('=')[-1]
+ else:
+ zip_name = "out.tar.gz"
+ else:
+ zip_name = os.path.basename(source_path)
+ ret = unTarFile(os.path.join(download_dir, zip_name), download_dir)
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s download to %s end" % (nowtime, download_dir))
+
+ if not ret:
+ with open(failed_mark, "a+") as fp:
+ fp.write("")
+ return ret
+ except Exception as e:
+ logger.printLog(e)
+ raise Exception(e)
+ finally:
+ file_lock.releaseFile()
+
+
+if __name__ == "__main__":
+ param_file = sys.argv[1]
+ if not param_file:
+ logger.printLog("Missing params file")
+ sys.exit(-1)
+ try:
+ uphandle = liteOsUpgrade_L0(param_file)
+ uphandle._excuteApp()
+ except Exception as e:
+ logger.printLog(e)
+ sys.exit(-1)
\ No newline at end of file
diff --git a/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L1_app.py b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L1_app.py
new file mode 100644
index 0000000000000000000000000000000000000000..45fa4ea53eada52ab05818395e9144f8c519aaf2
--- /dev/null
+++ b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L1_app.py
@@ -0,0 +1,351 @@
+#-*- coding:utf-8 -*-
+import uuid
+import sys
+import subprocess
+import os
+
+from core.base import BaseApp, dec_stepmsg
+from util.file_locker import FileLock
+from util.log_info import logger
+from util.time_info import get_now_time_str_info, get_now_time_info, Timeout, timeout
+from aw.Telnet.TelnetClient import TelConnect
+from aw.Common.Constant import CONSTANT
+from aw.Download.Download import *
+from aw.Common.Common import getHostIp
+from aw.ExtractFile.ExtractFile import *
+from aw.poweronoff.serial_power_on_off import serialPowerOnOff
+
+lock_suffix = CONSTANT.File.LOCK_SUFFIX #閫氳繃鏂囦欢閿佸疄鐜板苟鍙戜笅杞
+suc_file = CONSTANT.File.SUC_FILE #閫氳繃鏈枃浠舵槸鍖哄垎鐗堟湰鏄惁鎴愬姛涓嬭浇
+failed_file = CONSTANT.File.FAILED_FILE #閫氳繃鏈枃浠舵槸鏍囪鏂囦欢涓嬭浇澶辫触
+READ_MAXTIMEOUT = 600
+READ_TIMEOUT = 30
+READ_MINITIMEOUT = 5
+uboot_finish = 'hisilicon #'
+cmd_finish = ' #'
+
+class liteOsUpgrade_L1(BaseApp):
+ '''
+ @author: w00278233
+ '''
+
+ def __init__(self, param_file):
+ super().__init__(param_file)
+ self.param_List = ["Telnet_IP",
+ "Telnet_Port",
+ "upgrade_upgradeLocation"]
+
+ @dec_stepmsg("hongmeng L1 flash")
+ def excute(self):
+ '''
+ #===================================================================================
+ # @Method: excute(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鎵ц鍏ュ彛
+ # @PostStatus: none
+ # @eg: excute()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ step_index = self.params_dict.get("step_list").index("liteOsUpgrade_L1_app")
+
+ # 鎵ц涓嬭浇
+ try:
+ if not self.download():
+ CONSTANT.ENVERRMESSAGE = "image download fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ except Exception as e:
+ raise e
+
+ # 鎵ц鍗囩骇
+ try:
+ if not self.upgrade():
+ CONSTANT.ENVERRMESSAGE = "board upgrade fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ return True
+ except Exception as e:
+ raise e
+
+ @dec_stepmsg("download")
+ @timeout(1800)
+ def download(self):
+ '''
+ #===================================================================================
+ # @Method: download(self)
+ # @Precondition: none
+ # @Func: 鏋勫缓涓嬭浇鍒版湰鍦扮殑璺緞锛屾墽琛岀浉搴斿寘鐨勪笅杞
+ # @PostStatus: none
+ # @eg: download()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global version_savepath, version_name
+ dir_path = CONSTANT.Path.getDirPath()
+ if self.params_dict.get("pbiid"):
+ version_path = self.params_dict.get("pbiid")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, str(self.params_dict.get("pbiid")) + "FASTBOOT"))
+ version_savepath = os.path.join(dir_path, self.params_dict.get("flash_type"), version_name)
+ else:
+ version_path = self.params_dict.get("upgrade_upgradeLocation")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, (self.params_dict.get("upgrade_upgradeLocation"))))
+ version_savepath = os.path.join(dir_path, version_name)
+
+ if self.params_dict.get("isDownload") == "True":
+ logger.printLog("涓嶉渶瑕佸仛涓嬭浇锛岀洿鎺ヨ繑鍥")
+ return True
+
+ #鎵цimg涓嬭浇
+ import hashlib
+ save_file_str = version_path.replace("/", "").replace("\\", "")
+ save_file_name = hashlib.sha1(save_file_str.encode("utf-8")).hexdigest()
+ logger.info("download hash string:%s, hash value:%s" % (save_file_str, save_file_name))
+ save_path_file = os.path.join(dir_path, "record", "%s%s" % (save_file_name, ".txt"))
+ if not self.excutedown(version_path, os.path.join(version_savepath, "img"), save_path_file, False):
+ logger.error("download img fail")
+ return False
+
+ #淇濆瓨鏈湴鐗堟湰璺緞缁檇evicetest鍘荤増鏈矾寰勪笅鍙栫敤渚
+ saveVersion(save_path_file, os.path.join(version_savepath, "img"))
+
+ # 鎵ц鍗囩骇鑴氭湰涓嬭浇
+ if self.params_dict.get("upgrade_script"):
+ suc_mark = os.path.join(version_savepath, "scriptfile", suc_file)
+ if not self.excutedown(self.params_dict.get("upgrade_script"),
+ os.path.join(version_savepath, "scriptfile"), suc_mark, True):
+ logger.error("download upgrade script fail")
+ return False
+ with open(suc_mark, "a+") as fp:
+ fp.write("")
+
+ return True
+
+ def excutedown(self, source_path, download_dir, suc_mark, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, is_file)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ #
+ # @eg: excutedown("xxxx", "D:\\local\\image", Flase锛 os_method)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ failed_mark = os.path.join(download_dir, failed_file)
+ lock_path = os.path.join(download_dir, lock_suffix)
+ file_lock = FileLock()
+
+ if isDownLoadSuccess(download_dir, suc_mark, failed_mark):
+ return True
+ try:
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s Downloading, please wait" % nowtime)
+ file_lock.lockFile(lock_path)
+ ret = ""
+ logger.info("Get lock. Start to ")
+ if self.params_dict.get("bt_enable") and self.params_dict.get("bt_enable") == "True":
+ ret = downloadByBitComet(source_path, download_dir, os_method)
+ elif source_path.startswith('\\\\'):
+ ret = downloadByCopy(source_path, download_dir, is_file)
+ elif self.params_dict.get("pbiid"):
+ ret = downlaodByDownloadTool(version_savepath, self.params_dict.get("version_type"), "FASTBOOT", self.params_dict.get("pbiid"))
+ elif source_path.startswith("http"):
+ ret = downloadFileFromDevCloud(source_path, "", "", download_dir)
+
+ if source_path.endswith(".zip"):
+ zip_name = os.path.basename(source_path)
+ ret = extractZipFile(os.path.join(download_dir, zip_name), download_dir)
+ if source_path.endswith(".tar.gz") or (source_path.startswith("http") and ("file_id=" in source_path)):
+ if source_path.startswith("http") and ("file_id=" in source_path):
+ if source_path.endswith(".tar.gz"):
+ zip_name = source_path.split('=')[-1]
+ else:
+ zip_name = "out.tar.gz"
+ else:
+ zip_name = os.path.basename(source_path)
+ ret = unTarFile(os.path.join(download_dir, zip_name), download_dir)
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s download to %s end" % (nowtime, download_dir))
+
+ if not ret:
+ with open(failed_mark, "a+") as fp:
+ fp.write("")
+ return ret
+ except Exception as e:
+ logger.printLog(e)
+ raise Exception(e)
+ finally:
+ file_lock.releaseFile()
+
+
+ @dec_stepmsg("upgrade")
+ @timeout(900)
+ def upgrade(self):
+ '''
+ #===================================================================================
+ # @Method: upgrade(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鐩稿叧涓氬姟閫昏緫
+ # @PostStatus: none
+ # @eg: upgrade()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+
+ tel_IP = self.params_dict.get("Telnet_IP")
+ tel_port = self.params_dict.get("Telnet_Port")
+ tftp_ip = self.params_dict.get("Tftpserver_IP")
+ device_ip = self.params_dict.get("Device_IP")
+ device_Mac = self.params_dict.get("Device_MAC")
+ device_netmask = self.params_dict.get("Device_Netmask")
+ device_gatewayip = self.params_dict.get("Device_GatewayIP")
+ #鑺墖绫诲瀷,鏍规嵁鑺墖绫诲瀷鑾峰彇瀵瑰簲鐨勫埛鏈哄懡浠
+ flash_type = self.params_dict.get("flash_type")
+ #涓插彛鏈嶅姟鍣ㄥ懡浠ょ鍙
+ tel_cmd_port = self.params_dict.get("cmd_port")
+ #鍗曟澘鐨勭數婧愮鍙
+ power_port = self.params_dict.get("board_power_port")
+ tel_username = self.params_dict.get("server_cmd_username")
+ tel_passwd = self.params_dict.get("server_cmd_password")
+
+ if not tel_IP or not tel_port:
+ logger.error("Telnet_IP or Telnet_Port is NULL !!")
+ return False
+ if not tftp_ip:
+ tftp_ip = getHostIp()
+ logger.info("get host ip, tftp_ip is %s" % tftp_ip)
+ if not device_netmask:
+ device_netmask = "255.255.252.0"
+ if not device_Mac:
+ device_Mac = "3a:82:d0:08:f4:99"
+ if not tel_cmd_port:
+ tel_cmd_port = "18984"
+ local_image_path = "%s/%s" % (version_name, "img")
+ if self.params_dict.get("upgrade_script"):
+ script_name = self.params_dict.get("upgrade_script").split('\\')[-1]
+ scriptfile = os.path.join(version_savepath, "scriptfile", script_name)
+ else:
+ scriptpath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))))
+ if "ev" in flash_type:
+ scriptfile = os.path.join(scriptpath, "resource", "L1", "ev200", "update.txt")
+ elif "dv" in flash_type:
+ scriptfile = os.path.join(scriptpath, "resource", "L1", "dv300", "update.txt")
+ logger.info("upgrade scriptfile is: %s" % scriptfile)
+ if not os.path.exists(scriptfile):
+ logger.error("%s is not exit" % scriptfile)
+ return False
+
+ tnc = TelConnect(tel_IP, tel_port)
+ try:
+ board_type = tnc.getBoardType(cmd_finish, READ_MINITIMEOUT)
+ if board_type != "uboot":
+ if not tnc.sendResetCmd(uboot_finish, READ_TIMEOUT):
+ #涓婁笅鐢垫仮澶嶅崟鏉
+ if power_port:
+ if tel_passwd:
+ if not recoveryBoard(tnc, tel_IP, tel_cmd_port, power_port, tel_username, tel_passwd):
+ logger.error("recovery board fail, please check board")
+ return False
+ else:
+ if not recoveryBoard(tnc, tel_IP, tel_cmd_port, power_port, tel_username):
+ logger.error("recovery board fail, please check board")
+ return False
+ else:
+ logger.error("go hisilicon # fail, please check board status")
+ return False
+
+ with open(scriptfile, "r") as fp:
+ lines = fp.readlines()
+ for line in lines:
+ line = line.strip()
+ if not line:
+ logger.info("cmd is: %s " % line)
+ continue
+ if "%Tftpserver_IP%" in line:
+ line = line.replace("%Tftpserver_IP%", tftp_ip)
+ if "%Device_IP%" in line:
+ line = line.replace("%Device_IP%", device_ip)
+ if "%Device_MAC%" in line:
+ line = line.replace("%Device_MAC%", device_Mac)
+ if "%Device_Netmask%" in line:
+ line = line.replace("%Device_Netmask%", device_netmask)
+ if "%Device_GatewayIP%" in line:
+ line = line.replace("%Device_GatewayIP%", device_gatewayip)
+ if "userfs.img" in line:
+ if not os.path.exists(os.path.join(version_savepath, "img", "userfs.img")):
+ line = line.replace("userfs.img", "userfs_jffs2.img")
+ if "rootfs.img" in line:
+ if not os.path.exists(os.path.join(version_savepath, "img", "rootfs.img")):
+ line = line.replace("rootfs.img", "rootfs_jffs2.img")
+ if "tftp" in line:
+ packagefile_path = "/%s" % flash_type
+ new_packagefile_path = "/%s" % local_image_path
+ line = line.replace(packagefile_path, new_packagefile_path)
+ if not tnc.sendUpgradeCmd(line, uboot_finish, "done", READ_MAXTIMEOUT):
+ return False
+ continue
+ if "setenv" in line:
+ if not tnc.sendUpgradeCmd(line, uboot_finish, "", READ_MINITIMEOUT):
+ return False
+ continue
+ if "EXIT" in line:
+ break
+ if "go " in line:
+ if not tnc.sendUpgradeCmd(line, cmd_finish, "", READ_TIMEOUT):
+ logger.error("go OHOS # fail, please check board status")
+ return False
+ continue
+ if not tnc.sendUpgradeCmd(line, cmd_finish, "", READ_TIMEOUT):
+ return False
+ board_type = tnc.getBoardType(cmd_finish, READ_MINITIMEOUT)
+ if board_type == "OHOS":
+ logger.info("upgrade success")
+ return True
+ else:
+ logger.info("upgrade fail")
+ return False
+ except Exception as e:
+ logger.printLog(e)
+ return False
+ finally:
+ tnc.close()
+ logger.info("close telnet")
+
+def recoveryBoard(tnc, telip, cmdport, powerport, username, passwd=''):
+ logger.info("start recovery board")
+ # 鍏堟墽琛屼笅鐢垫搷浣
+ if not serialPowerOnOff(telip, cmdport, powerport, "off", username, passwd):
+ logger.error("board power off failed")
+ return False
+ #鍐嶆墽琛屼笂鐢垫搷浣
+ if not serialPowerOnOff(telip, cmdport, powerport, "on", username, passwd):
+ logger.error("board power on failed")
+ return False
+ #鍐嶅彂閫佸洖杞
+ if not tnc.sendEnterCmd(" #", READ_MINITIMEOUT):
+ logger.error("send Enter failed")
+ return False
+ board_type = tnc.getBoardType(cmd_finish, READ_MINITIMEOUT)
+ if board_type == "bootrom":
+ logger.error("recovery board failed")
+ return False
+ logger.info("recovery board succ")
+ return True
+
+
+if __name__ == "__main__":
+ param_file = sys.argv[1]
+ if not param_file:
+ logger.printLog("Missing params file")
+ sys.exit(-1)
+ try:
+ uphandle = liteOsUpgrade_L1(param_file)
+ uphandle._excuteApp()
+ except Exception as e:
+ logger.printLog(e)
+ sys.exit(-1)
diff --git a/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L1_shequ_app copy.py b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L1_shequ_app copy.py
new file mode 100644
index 0000000000000000000000000000000000000000..0b7d84e98ccd990b3095dd7682679dcc1f15e009
--- /dev/null
+++ b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L1_shequ_app copy.py
@@ -0,0 +1,465 @@
+#-*- coding:utf-8 -*-
+import uuid
+import sys
+import subprocess
+import os
+import serial
+
+from core.base import BaseApp, dec_stepmsg
+from util.file_locker import FileLock
+from util.log_info import logger
+from util.time_info import get_now_time_str_info, get_now_time_info, Timeout, timeout
+from aw.Telnet.TelnetClient import TelConnect
+from aw.Common.Constant import CONSTANT
+from aw.Download.Download import *
+from aw.Common.Common import getHostIp, copyFile, copyDirectory
+from aw.ExtractFile.ExtractFile import *
+from aw.poweronoff.serial_power_on_off import usbPowerOnOff
+from threading import Thread
+
+lock_suffix = CONSTANT.File.LOCK_SUFFIX #閫氳繃鏂囦欢閿佸疄鐜板苟鍙戜笅杞
+suc_file = CONSTANT.File.SUC_FILE #閫氳繃鏈枃浠舵槸鍖哄垎鐗堟湰鏄惁鎴愬姛涓嬭浇
+failed_file = CONSTANT.File.FAILED_FILE #閫氳繃鏈枃浠舵槸鏍囪鏂囦欢涓嬭浇澶辫触
+READ_MAXTIMEOUT = 20
+READ_TIMEOUT = 30
+READ_MINITIMEOUT = 5
+uboot_finish = 'hisilicon #'
+cmd_finish = ' #'
+error_str_list = ['Unknown', '鍙戦佽捣濮嬪抚澶辫触', '鍙戦佸ご甯уけ璐']
+
+class liteOsUpgrade_L1_shequ(BaseApp):
+ '''
+ @author: w00278233
+ '''
+
+ def __init__(self, param_file):
+ super().__init__(param_file)
+ self.param_List = ["deploy_com",
+ "usb_port",
+ "upgrade_upgradeLocation"]
+
+ @dec_stepmsg("hongmeng L1 flash")
+ def excute(self):
+ '''
+ #===================================================================================
+ # @Method: excute(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鎵ц鍏ュ彛
+ # @PostStatus: none
+ # @eg: excute()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ step_index = self.params_dict.get("step_list").index("liteOsUpgrade_L1_shequ_app")
+
+ # 鎵ц涓嬭浇
+ try:
+ if not self.download():
+ CONSTANT.ENVERRMESSAGE = "image download fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ except Exception as e:
+ raise e
+
+
+ # 鎵ц鍗囩骇
+ try:
+ if not self.upgrade():
+ CONSTANT.ENVERRMESSAGE = "board upgrade fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ return True
+ except Exception as e:
+ raise e
+
+ @dec_stepmsg("download")
+ @timeout(1800)
+ def download(self):
+ '''
+ #===================================================================================
+ # @Method: download(self)
+ # @Precondition: none
+ # @Func: 鏋勫缓涓嬭浇鍒版湰鍦扮殑璺緞锛屾墽琛岀浉搴斿寘鐨勪笅杞
+ # @PostStatus: none
+ # @eg: download()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global version_savepath, version_name
+ dir_path = CONSTANT.Path.getDirPath()
+ if self.params_dict.get("pbiid"):
+ version_path = self.params_dict.get("pbiid")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, str(self.params_dict.get("pbiid")) + "FASTBOOT"))
+ version_savepath = os.path.join(dir_path, self.params_dict.get("flash_type"), version_name)
+ else:
+ version_path = self.params_dict.get("upgrade_upgradeLocation")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, (self.params_dict.get("upgrade_upgradeLocation"))))
+ version_savepath = os.path.join(dir_path, version_name)
+
+ if self.params_dict.get("isDownload") == "True":
+ logger.printLog("涓嶉渶瑕佸仛涓嬭浇锛岀洿鎺ヨ繑鍥")
+ return True
+
+ #鎵цimg涓嬭浇
+ import hashlib
+ save_file_str = version_path.replace("/", "").replace("\\", "")
+ save_file_name = hashlib.sha1(save_file_str.encode("utf-8")).hexdigest()
+ logger.info("download hash value:%s" % (save_file_name))
+ save_path_file = os.path.join(dir_path, "record", "%s%s" % (save_file_name, ".txt"))
+ if not self.excutedown(version_path, os.path.join(version_savepath, "img"), save_path_file, False):
+ logger.error("download img fail")
+ return False
+
+ #淇濆瓨鏈湴鐗堟湰璺緞缁檇evicetest鍘荤増鏈矾寰勪笅鍙栫敤渚
+ saveVersion(save_path_file, os.path.join(version_savepath, "img"))
+
+ return True
+
+ def excutedown(self, source_path, download_dir, suc_mark, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, is_file)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ #
+ # @eg: excutedown("xxxx", "D:\\local\\image", Flase锛 os_method)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ failed_mark = os.path.join(download_dir, failed_file)
+ lock_path = os.path.join(download_dir, lock_suffix)
+ file_lock = FileLock()
+
+ if isDownLoadSuccess(download_dir, suc_mark, failed_mark):
+ return True
+ try:
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s Downloading, please wait" % nowtime)
+ file_lock.lockFile(lock_path)
+ ret = ""
+ logger.info("Get lock. Start to ")
+ if self.params_dict.get("bt_enable") and self.params_dict.get("bt_enable") == "True":
+ ret = downloadByBitComet(source_path, download_dir, os_method)
+ elif source_path.startswith('\\\\'):
+ ret = downloadByCopy(source_path, download_dir, is_file)
+ elif self.params_dict.get("pbiid"):
+ ret = downlaodByDownloadTool(version_savepath, self.params_dict.get("version_type"), "FASTBOOT", self.params_dict.get("pbiid"))
+ elif source_path.startswith("http"):
+ ret = downloadFileFromDevCloud(source_path, "", "", download_dir)
+
+ if source_path.endswith(".zip"):
+ zip_name = os.path.basename(source_path)
+ ret = extractZipFile(os.path.join(download_dir, zip_name), download_dir)
+ if source_path.endswith(".tar.gz") or (source_path.startswith("http") and ("file_id=" in source_path)):
+ if source_path.startswith("http") and ("file_id=" in source_path):
+ if source_path.endswith(".tar.gz"):
+ zip_name = source_path.split('=')[-1]
+ else:
+ zip_name = "out.tar.gz"
+ else:
+ zip_name = os.path.basename(source_path)
+ ret = unTarFile(os.path.join(download_dir, zip_name), download_dir)
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s download to %s end" % (nowtime, download_dir))
+
+ if not ret:
+ with open(failed_mark, "a+") as fp:
+ fp.write("")
+ return ret
+ except Exception as e:
+ logger.printLog(e)
+ raise Exception(e)
+ finally:
+ file_lock.releaseFile()
+
+
+ @dec_stepmsg("upgrade")
+ #@timeout(900)
+ def upgrade(self):
+ '''
+ #===================================================================================
+ # @Method: upgrade(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鐩稿叧涓氬姟閫昏緫
+ # @PostStatus: none
+ # @eg: upgrade()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ logger.printLog('寮濮嬪崌绾')
+ deploy_com = self.params_dict.get("deploy_com")
+ usb_port = self.params_dict.get("usb_port")
+ baudrate = self.params_dict.get("baudrate")
+ #鑺墖绫诲瀷,鏍规嵁鑺墖绫诲瀷鑾峰彇瀵瑰簲鐨勫埛鏈哄懡浠
+ flash_type = self.params_dict.get("flash_type")
+ burn_usbport = self.params_dict.get("hiburn_usbport")
+ device_ip = self.params_dict.get("Device_IP")
+ device_netmask = self.params_dict.get("Device_Netmask")
+ device_gatewayip = self.params_dict.get("Device_GatewayIP")
+ chip_version = self.params_dict.get('chip_version')
+ chip_version = chip_version.lower() if chip_version else chip_version
+
+ if not deploy_com:
+ logger.error("deploy_com is NULL !!")
+ return False
+ if not burn_usbport:
+ logger.error("hiburn_usbport is NULL !!")
+ return False
+ if not baudrate:
+ baudrate = 115200
+ scriptpath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))))
+ #鍗囩骇闇瑕佺殑宸ュ叿褰掓。
+ toolworkspace = CONSTANT.OSType.getworkspace()
+ hiburntoolpath = os.path.join(toolworkspace, "HiBurnCmdLine", "usb%s_tool" % burn_usbport)
+ logger.info("hiburn tool path is: %s" % hiburntoolpath)
+ if not os.path.exists(hiburntoolpath):
+ if not burn_usbport:
+ logger.error("hiburn_usbport is NULL !!")
+ return False
+ os.makedirs(hiburntoolpath)
+ toolpath = os.path.join(scriptpath, "resource", "HiBurnCmdLine.zip")
+ logger.info("copy %s to %s" % (toolpath, hiburntoolpath))
+ copyFile(toolpath, hiburntoolpath)
+ zip_name = os.path.basename(toolpath)
+ ret = extractZipFile(os.path.join(hiburntoolpath, zip_name), hiburntoolpath)
+ if ret:
+ logger.info("unzip to %s succ" % (hiburntoolpath))
+ #淇敼burn.config涓殑usb鍙
+ configpath = os.path.join(hiburntoolpath, "config", "burn.config")
+ all_data = ""
+ with open(configpath, "r", encoding="utf-8") as cf:
+ for line in cf:
+ if "usbDeviceNumber=" in line:
+ old_str = line
+ line = line.replace(old_str, "usbDeviceNumber=%s\r\n" % burn_usbport)
+ logger.info("replace line: %s " % line)
+ all_data += line
+ with open(configpath, "w", encoding="utf-8") as wf:
+ wf.write(all_data)
+ else:
+ logger.error("%s is not exit" % hiburntoolpath)
+ return False
+ #灏嗗崌绾ч渶瑕佺殑鏂囦欢鎷疯礉鍒伴暅鍍忛噷闈
+ local_image_path = os.path.join(version_savepath, "img")
+ old_xml_path = os.path.join(scriptpath, "resource", "L1", flash_type, "usb-burn.xml")
+ xml_path = os.path.join(local_image_path, "usb-burn.xml")
+ if chip_version == 'hi3518':
+ old_xml_path = os.path.join(scriptpath, "resource", "L1", flash_type, "usb-burn-jffs2.xml")
+ elif chip_version == 'hi3516':
+ old_xml_path = os.path.join(scriptpath, "resource", "L1", flash_type, "usb-burn-vfat.xml")
+ copyFile(old_xml_path, xml_path)
+ if flash_type.lower() == "ev300":
+ chip_type = "Hi3518EV300"
+ ubootpath = os.path.join(scriptpath, "resource", "L1", flash_type.lower(), "u-boot-hi3518ev300.bin")
+ elif flash_type.lower() == "dv300":
+ chip_type = "Hi3516DV300"
+ ubootpath = os.path.join(scriptpath, "resource", "L1", flash_type.lower(), "u-boot-hi3516dv300.bin")
+ else:
+ logger.error("flash_type is : %s " % flash_type)
+ return False
+ copyFile(ubootpath, local_image_path)
+ scriptfile = os.path.join(scriptpath, "resource", "L1", f'{flash_type.lower()}', "update.txt")
+ logger.info(f'scriptfile:{scriptfile}')
+
+ current_path = os.getcwd()
+ logger.info("before excute hiburn,current path is: %s" % current_path)
+ os.chdir(hiburntoolpath)
+ logger.info("excute hiburn path is: %s" % os.getcwd())
+ flash_uboot_xml = os.path.join(scriptpath, "resource", "L1", flash_type.lower(), "flash_fastboot.xml")
+ cmd = ".\jre\\bin\java -jar hiburn.jar --erase -n %s -m serial %s -x %s" % (chip_type, deploy_com.upper(), flash_uboot_xml)
+ self.eraseDevice(cmd, usb_port)
+
+ retry = 0
+ while retry < 3:
+ #usb鍒锋満
+ cmd = ".\jre\\bin\java -jar hiburn.jar --burn -n %s -m USBBootrom -x %s" % (chip_type, xml_path)
+ logger.info("cmd is: %s" % cmd)
+ ret, outpri = subprocess.getstatusoutput(cmd)
+ logger.info("usb upgrade result: %s " % ret)
+ logger.info("print console: %s " % outpri)
+ if ret != 0:
+ if ret == 4 and retry < 2:
+ time.sleep(10)
+ retry = retry + 1
+ logger.info('flash fail,so flash once again')
+ continue
+ logger.info(ret)
+ logger.error("hiburn usb upgrade failed!!")
+ return False
+ retry = retry + 3
+ os.chdir(current_path)
+ logger.info("hiburn upgrade end, check board status")
+ time.sleep(5)
+ try:
+ reset_count = 0
+ logger.info("鎵撳紑serial")
+ ser = serial.Serial(deploy_com, int(baudrate), timeout=0)
+ while reset_count < 2:
+ if ser.is_open == False:
+ ser.open()
+ logger.info("get device status")
+ board_type = getBoardType(ser)
+ if board_type == "uboot":
+ with open(scriptfile, "r") as fp:
+ lines = fp.readlines()
+ for line in lines:
+ if not line:
+ logger.info("cmd is: %s " % line)
+ continue
+ if "reset" in line:
+ ret = sendCmd(ser, line, READ_MAXTIMEOUT)
+ continue
+ ret = sendCmd(ser, line, READ_MINITIMEOUT)
+ board_type = getBoardType(ser)
+ if board_type != "OHOS":
+ if reset_count < 2:
+ logger.info('after reset;the device status is error锛宺eset device again,reset_count:%d' % reset_count)
+ reset_count += 1
+ time.sleep(20)
+ continue
+ logger.error("upgrade fail")
+ return False
+ if flash_type.lower() == "dv300":
+ logger.info("upgrade success")
+ init_cmd = "toybox ifconfig eth0 %s netmask %s gateway %s \r" % (device_ip, device_netmask, device_gatewayip)
+ sendCmd(ser, init_cmd, READ_MINITIMEOUT)
+ sendCmd(ser, 'toybox ifconfig\r', READ_MINITIMEOUT)
+ return True
+ elif flash_type.lower() == "ev300":
+ logger.info("setup wifi")
+ cmd = 'toybox ls\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ if not "sdcard" in ret.lower():
+ cmd = 'toybox mkdir /sdcard\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ if "error:" in ret.lower():
+ logger.error("toybox mkdir /sdcard fail")
+ return False
+ cmd = 'toybox mount /dev/mmcblk0p0 /sdcard vfat\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ cmd = 'toybox ls /sdcard\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ cmd = 'cd /sdcard/wpa\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ cmd = './wpa_supplicant -i wlan0 -c wpa_supplicant.conf & \r'
+ ret = sendCmd(ser, cmd, READ_MAXTIMEOUT)
+ if "error:" in ret.lower():
+ logger.error("setup wifi fail")
+ return False
+ cmd = 'toybox ifconfig\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ if "error:" in ret.lower():
+ logger.error("toybox ifconfig fail")
+ return False
+ logger.info("upgrade success")
+ return True
+ else:
+ logger.info('before reset;the device status is error锛宺eset device again,reset_count:%d'%reset_count)
+ reset_count += 1
+ time.sleep(20)
+ continue
+
+ except Exception as e:
+ logger.info(e)
+ return False
+ finally:
+ ser.close()
+ logger.info("close serial")
+
+ def eraseDevice(self, cmd, usb_port):
+ '''
+ ret 鏆傛椂娌℃湁浣滅敤锛屽厛浣跨敤out
+ '''
+ erase_retry = 0
+ while erase_retry < 3:
+ # 閫氱數
+ PowerOnByThread(usb_port)
+ logger.info("cmd is: %s" % cmd)
+ ret, outpri = subprocess.getstatusoutput(cmd)
+ logger.info("flash fastboot result: %s " % ret)
+ logger.info("print console: %s " % outpri)
+ is_earse_again = any([True if item in outpri else False for item in error_str_list])
+ if ret == 0 and erase_retry < 2 and not is_earse_again :
+ logger.info('妾櫎鎴愬姛'.center(20,'*'))
+ break
+ elif is_earse_again:
+ logger.info('妾櫎瀛樺湪闂 閲嶆柊涓婁笅鐢 閲嶆柊妾櫎')
+ erase_retry += 1
+ time.sleep(5)
+ continue
+ else:
+ logger.info('other error')
+ return False
+ else:
+ return False
+
+def PowerOnByThread(usb_port,wait_time=10):
+ thread = Thread(target=boardPowerOn, args=[usb_port, wait_time])
+ thread.start()
+ logger.info("thread board power on start")
+
+
+def boardPowerOn(usb_port, waittime):
+ logger.info("board power on start")
+ time.sleep(waittime)
+
+ #瀵圭鍙d笅鐢
+ if not usbPowerOnOff('127.0.0.1', '7788', usb_port, "off"):
+ logger.error("board power off failed")
+ return False
+
+ #瀵圭鍙d笂鐢
+ if not usbPowerOnOff('127.0.0.1', '7788', usb_port, "on"):
+ logger.error("board power on failed")
+ return False
+ logger.info("board power on end")
+
+
+def getBoardType(ser):
+ ret = sendCmd(ser, '\r', READ_TIMEOUT)
+ if 'HMOS' in ret or 'OHOS' in ret or '$' in ret:
+ ostype = 'OHOS'
+ elif 'hisilicon' in ret:
+ ostype = 'uboot'
+ elif ' #' in ret:
+ ostype = 'linux'
+ else:
+ ostype = 'bootrom'
+ logger.info("board type is: %s" % ostype)
+ return ostype
+
+def sendCmd(ser, cmd, timeout):
+ logger.info("cmd is: %s " % cmd)
+ ser.write((cmd + '\n').encode())
+ time.sleep(0.5)
+ ret = ''
+ i = 0
+ while True:
+ out = ser.read(ser.inWaiting())
+ if not out:
+ break
+ if i > 2:
+ break
+ ret = ret + out.decode(encoding="utf-8", errors="ignore")
+ time.sleep(timeout)
+ i = i + 1
+ logger.info("result is: %s " % ret)
+ return ret
+
+
+
+if __name__ == "__main__":
+ param_file = sys.argv[1]
+ if not param_file:
+ logger.printLog("Missing params file")
+ sys.exit(-1)
+ try:
+ uphandle = liteOsUpgrade_L1(param_file)
+ uphandle._excuteApp()
+ except Exception as e:
+ logger.printLog(e)
+ sys.exit(-1)
diff --git a/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L1_shequ_app.py b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L1_shequ_app.py
new file mode 100644
index 0000000000000000000000000000000000000000..e1d15d6715155ada000716c68bdb21fa5399f706
--- /dev/null
+++ b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L1_shequ_app.py
@@ -0,0 +1,517 @@
+#-*- coding:utf-8 -*-
+import uuid
+import sys
+import subprocess
+import os
+import serial
+
+from core.base import BaseApp, dec_stepmsg
+from util.file_locker import FileLock
+from util.log_info import logger
+from util.time_info import get_now_time_str_info, get_now_time_info, Timeout, timeout
+from aw.Telnet.TelnetClient import TelConnect
+from aw.Common.Constant import CONSTANT
+from aw.Download.Download import *
+from aw.Common.Common import getHostIp, copyFile, copyDirectory
+from aw.ExtractFile.ExtractFile import *
+from aw.poweronoff.serial_power_on_off import usbPowerOnOff
+from threading import Thread
+
+lock_suffix = CONSTANT.File.LOCK_SUFFIX #閫氳繃鏂囦欢閿佸疄鐜板苟鍙戜笅杞
+suc_file = CONSTANT.File.SUC_FILE #閫氳繃鏈枃浠舵槸鍖哄垎鐗堟湰鏄惁鎴愬姛涓嬭浇
+failed_file = CONSTANT.File.FAILED_FILE #閫氳繃鏈枃浠舵槸鏍囪鏂囦欢涓嬭浇澶辫触
+READ_MAXTIMEOUT = 5
+READ_TIMEOUT = 5
+READ_MINITIMEOUT = 2
+uboot_finish = 'hisilicon #'
+cmd_finish = ' #'
+error_str_list = ['Unknown', '鍙戦佽捣濮嬪抚澶辫触', '鍙戦佸ご甯уけ璐']
+ip_cmd = 'ping 192.168.18.1'
+
+class liteOsUpgrade_L1_shequ(BaseApp):
+ '''
+ @author: w00278233
+ '''
+
+ def __init__(self, param_file):
+ super().__init__(param_file)
+ self.param_List = ["deploy_com",
+ "usb_port",
+ "upgrade_upgradeLocation"]
+
+ @dec_stepmsg("hongmeng L1 flash")
+ def excute(self):
+ '''
+ #===================================================================================
+ # @Method: excute(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鎵ц鍏ュ彛
+ # @PostStatus: none
+ # @eg: excute()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ step_index = self.params_dict.get("step_list").index("liteOsUpgrade_L1_shequ_app")
+
+ # 鎵ц涓嬭浇
+ try:
+ if not self.download():
+ CONSTANT.ENVERRMESSAGE = "image download fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ except Exception as e:
+ raise e
+
+
+ # 鎵ц鍗囩骇
+ try:
+ if not self.upgrade():
+ CONSTANT.ENVERRMESSAGE = "board upgrade fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ return True
+ except Exception as e:
+ raise e
+
+ @dec_stepmsg("download")
+ @timeout(1800)
+ def download(self):
+ '''
+ #===================================================================================
+ # @Method: download(self)
+ # @Precondition: none
+ # @Func: 鏋勫缓涓嬭浇鍒版湰鍦扮殑璺緞锛屾墽琛岀浉搴斿寘鐨勪笅杞
+ # @PostStatus: none
+ # @eg: download()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global version_savepath, version_name
+ dir_path = CONSTANT.Path.getDirPath()
+ if self.params_dict.get("pbiid"):
+ version_path = self.params_dict.get("pbiid")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, str(self.params_dict.get("pbiid")) + "FASTBOOT"))
+ version_savepath = os.path.join(dir_path, self.params_dict.get("flash_type"), version_name)
+ else:
+ version_path = self.params_dict.get("upgrade_upgradeLocation")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, (self.params_dict.get("upgrade_upgradeLocation"))))
+ version_savepath = os.path.join(dir_path, version_name)
+
+ if self.params_dict.get("isDownload") == "True":
+ logger.printLog("涓嶉渶瑕佸仛涓嬭浇锛岀洿鎺ヨ繑鍥")
+ return True
+
+ #鎵цimg涓嬭浇
+ import hashlib
+ save_file_str = version_path.replace("/", "").replace("\\", "")
+ save_file_name = hashlib.sha1(save_file_str.encode("utf-8")).hexdigest()
+ logger.info("download hash value:%s" % (save_file_name))
+ save_path_file = os.path.join(dir_path, "record", "%s%s" % (save_file_name, ".txt"))
+ if not self.excutedown(version_path, os.path.join(version_savepath, "img"), save_path_file, False):
+ logger.error("download img fail")
+ return False
+
+ #淇濆瓨鏈湴鐗堟湰璺緞缁檇evicetest鍘荤増鏈矾寰勪笅鍙栫敤渚
+ saveVersion(save_path_file, os.path.join(version_savepath, "img"))
+
+ return True
+
+ def excutedown(self, source_path, download_dir, suc_mark, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, is_file)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ #
+ # @eg: excutedown("xxxx", "D:\\local\\image", Flase锛 os_method)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ failed_mark = os.path.join(download_dir, failed_file)
+ lock_path = os.path.join(download_dir, lock_suffix)
+ file_lock = FileLock()
+
+ if isDownLoadSuccess(download_dir, suc_mark, failed_mark):
+ return True
+ try:
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s Downloading, please wait" % nowtime)
+ file_lock.lockFile(lock_path)
+ ret = ""
+ logger.info("Get lock. Start to ")
+ if self.params_dict.get("bt_enable") and self.params_dict.get("bt_enable") == "True":
+ ret = downloadByBitComet(source_path, download_dir, os_method)
+ elif source_path.startswith('\\\\'):
+ ret = downloadByCopy(source_path, download_dir, is_file)
+ elif self.params_dict.get("pbiid"):
+ ret = downlaodByDownloadTool(version_savepath, self.params_dict.get("version_type"), "FASTBOOT", self.params_dict.get("pbiid"))
+ elif source_path.startswith("http"):
+ ret = downloadFileFromDevCloud(source_path, "", "", download_dir)
+
+ if source_path.endswith(".zip"):
+ zip_name = os.path.basename(source_path)
+ ret = extractZipFile(os.path.join(download_dir, zip_name), download_dir)
+ if source_path.endswith(".tar.gz") or (source_path.startswith("http") and ("file_id=" in source_path)):
+ if source_path.startswith("http") and ("file_id=" in source_path):
+ if source_path.endswith(".tar.gz"):
+ zip_name = source_path.split('=')[-1]
+ else:
+ zip_name = "out.tar.gz"
+ else:
+ zip_name = os.path.basename(source_path)
+ ret = unTarFile(os.path.join(download_dir, zip_name), download_dir)
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s download to %s end" % (nowtime, download_dir))
+
+ if not ret:
+ with open(failed_mark, "a+") as fp:
+ fp.write("")
+ return ret
+ except Exception as e:
+ logger.printLog(e)
+ raise Exception(e)
+ finally:
+ file_lock.releaseFile()
+
+
+ @dec_stepmsg("upgrade")
+ #@timeout(900)
+ def upgrade(self):
+ '''
+ #===================================================================================
+ # @Method: upgrade(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鐩稿叧涓氬姟閫昏緫
+ # @PostStatus: none
+ # @eg: upgrade()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ logger.printLog('寮濮嬪崌绾')
+ deploy_com = self.params_dict.get("deploy_com")
+ usb_port = self.params_dict.get("usb_port")
+ baudrate = self.params_dict.get("baudrate")
+ #鑺墖绫诲瀷,鏍规嵁鑺墖绫诲瀷鑾峰彇瀵瑰簲鐨勫埛鏈哄懡浠
+ flash_type = self.params_dict.get("flash_type")
+ burn_usbport = self.params_dict.get("hiburn_usbport")
+ device_ip = self.params_dict.get("Device_IP")
+ device_netmask = self.params_dict.get("Device_Netmask")
+ device_gatewayip = self.params_dict.get("Device_GatewayIP")
+ chip_version = self.params_dict.get('chip_version')
+ chip_version = chip_version.lower() if chip_version else chip_version
+
+ if not deploy_com:
+ logger.error("deploy_com is NULL !!")
+ return False
+ if not burn_usbport:
+ logger.error("hiburn_usbport is NULL !!")
+ return False
+ if not baudrate:
+ baudrate = 115200
+ scriptpath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))))
+ #鍗囩骇闇瑕佺殑宸ュ叿褰掓。
+ toolworkspace = CONSTANT.OSType.getworkspace()
+ hiburntoolpath = os.path.join(toolworkspace, "HiBurnCmdLine", "usb%s_tool" % burn_usbport)
+ logger.info("hiburn tool path is: %s" % hiburntoolpath)
+ if not os.path.exists(hiburntoolpath):
+ if not burn_usbport:
+ logger.error("hiburn_usbport is NULL !!")
+ return False
+ os.makedirs(hiburntoolpath)
+ toolpath = os.path.join(scriptpath, "resource", "HiBurnCmdLine.zip")
+ logger.info("copy %s to %s" % (toolpath, hiburntoolpath))
+ copyFile(toolpath, hiburntoolpath)
+ zip_name = os.path.basename(toolpath)
+ ret = extractZipFile(os.path.join(hiburntoolpath, zip_name), hiburntoolpath)
+ if ret:
+ logger.info("unzip to %s succ" % (hiburntoolpath))
+ #淇敼burn.config涓殑usb鍙
+ configpath = os.path.join(hiburntoolpath, "config", "burn.config")
+ all_data = ""
+ with open(configpath, "r", encoding="utf-8") as cf:
+ for line in cf:
+ if "usbDeviceNumber=" in line:
+ old_str = line
+ line = line.replace(old_str, "usbDeviceNumber=%s\r\n" % burn_usbport)
+ logger.info("replace line: %s " % line)
+ all_data += line
+ with open(configpath, "w", encoding="utf-8") as wf:
+ wf.write(all_data)
+ else:
+ logger.error("%s is not exit" % hiburntoolpath)
+ return False
+ #灏嗗崌绾ч渶瑕佺殑鏂囦欢鎷疯礉鍒伴暅鍍忛噷闈
+ local_image_path = os.path.join(version_savepath, "img")
+ old_xml_path = os.path.join(scriptpath, "resource", "L1", flash_type, "usb-burn.xml")
+ xml_path = os.path.join(local_image_path, "usb-burn.xml")
+ if chip_version == 'hi3518':
+ old_xml_path = os.path.join(scriptpath, "resource", "L1", flash_type, "usb-burn-jffs2.xml")
+ elif chip_version == 'hi3516':
+ old_xml_path = os.path.join(scriptpath, "resource", "L1", flash_type, "usb-burn-vfat.xml")
+ copyFile(old_xml_path, xml_path)
+ if flash_type.lower() == "ev300":
+ chip_type = "Hi3518EV300"
+ ubootpath = os.path.join(scriptpath, "resource", "L1", flash_type.lower(), "u-boot-hi3518ev300.bin")
+ elif flash_type.lower() == "dv300":
+ chip_type = "Hi3516DV300"
+ ubootpath = os.path.join(scriptpath, "resource", "L1", flash_type.lower(), "u-boot-hi3516dv300.bin")
+ else:
+ logger.error("flash_type is : %s " % flash_type)
+ return False
+ copyFile(ubootpath, local_image_path)
+ scriptfile = os.path.join(scriptpath, "resource", "L1", f'{flash_type.lower()}', "update.txt")
+ logger.info(f'scriptfile:{scriptfile}')
+
+ current_path = os.getcwd()
+ logger.info("before excute hiburn,current path is: %s" % current_path)
+ os.chdir(hiburntoolpath)
+ logger.info("excute hiburn path is: %s" % os.getcwd())
+ flash_uboot_xml = os.path.join(scriptpath, "resource", "L1", flash_type.lower(), "flash_fastboot.xml")
+ cmd = ".\jre\\bin\java -jar hiburn.jar --erase -n %s -m serial %s -x %s" % (chip_type, deploy_com.upper(), flash_uboot_xml)
+ self.eraseDevice(cmd, usb_port)
+
+ retry = 0
+ while retry < 3:
+ #usb鍒锋満
+ cmd = ".\jre\\bin\java -jar hiburn.jar --burn -n %s -m USBBootrom -x %s" % (chip_type, xml_path)
+ logger.info("cmd is: %s" % cmd)
+ ret, outpri = subprocess.getstatusoutput(cmd)
+ logger.info("usb upgrade result: %s " % ret)
+ logger.info("print console: %s " % outpri)
+ if ret != 0:
+ if ret == 4 and retry < 2:
+ time.sleep(10)
+ retry = retry + 1
+ logger.info('flash fail,so flash once again')
+ continue
+ logger.info(ret)
+ logger.error("hiburn usb upgrade failed!!")
+ return False
+ retry = retry + 3
+ os.chdir(current_path)
+ logger.info("hiburn upgrade end, check board status")
+ time.sleep(5)
+ try:
+ logger.info("鎵撳紑serial")
+ ser = serial.Serial(deploy_com, int(baudrate), timeout=0)
+ if self.bootUpUboot(ser,scriptfile) and self.configureIp(ser, flash_type, device_ip, device_netmask, device_gatewayip) and self.checkStatus(ser):
+ return True
+ return False
+ except Exception as e:
+ logger.info(e)
+ return False
+ finally:
+ ser.close()
+ logger.info("close serial")
+
+ def bootUpUboot(self,ser,scriptfile):
+ '''
+ 鍚姩uboot
+ '''
+ reset_count = 0
+ while reset_count < 2:
+ if ser.is_open == False:
+ ser.open()
+ logger.info("get device status")
+ board_type = getBoardType(ser)
+ if board_type == "uboot":
+ with open(scriptfile, "r") as fp:
+ lines = fp.readlines()
+ for line in lines:
+ if not line:
+ logger.info("cmd is: %s " % line)
+ continue
+ if "reset" in line:
+ ret = sendCmd(ser, line, READ_MAXTIMEOUT)
+ continue
+ ret = sendCmd(ser, line, READ_MINITIMEOUT)
+ board_type = getBoardType(ser)
+ if board_type != "OHOS":
+ if reset_count < 2:
+ logger.info('after reset;the device status is error锛宺eset device again,reset_count:%d' % reset_count)
+ reset_count += 1
+ time.sleep(20)
+ continue
+ logger.error("upgrade fail")
+ return False
+ return True
+ else:
+ logger.info('before reset;the device status is error锛宺eset device again,reset_count:%d'%reset_count)
+ reset_count += 1
+ time.sleep(20)
+ continue
+ else:
+ return False
+
+ def configureIp(self,ser,flash_type, device_ip, device_netmask, device_gatewayip):
+ '''
+ 閰嶇疆ip锛岀‘璁ら厤缃儏鍐
+ '''
+ rerty_count = 0
+ # test_count = 0
+ while rerty_count <= 2:
+ if flash_type.lower() == "dv300":
+ if not self.afterRebootDvConfigure(ser, device_ip, device_netmask, device_gatewayip):
+ return False
+ elif flash_type.lower() == "ev300":
+ if not self.afterRebootEvConfigure(ser):
+ return False
+ time.sleep(5)
+
+ ret = sendCmd(ser, ip_cmd, READ_MINITIMEOUT)
+ logger.info(ret)
+ # if test_count ==0 :
+ # logger.printLog('ip 閰嶇疆澶辫触')
+ # test_count = 1
+ # continue
+ if 'Reply from 192.168.18.1' in ret:
+ logger.info('ip 閰嶇疆鎴愬姛')
+ return True
+ elif 'Ping: sending ICMP echo request failed' in ret:
+ logger.printLog('ip 閰嶇疆澶辫触')
+ logger.info('閲嶆柊閰嶇疆ip')
+ rerty_count += 1
+ else:
+ return False
+
+ def afterRebootDvConfigure(self,ser, device_ip, device_netmask, device_gatewayip):
+ logger.info("dv300 configure ip")
+ init_cmd = "ifconfig eth0 %s netmask %s gateway %s \r" % (device_ip, device_netmask, device_gatewayip)
+ sendCmd(ser, init_cmd, READ_MINITIMEOUT)
+ sendCmd(ser, 'ifconfig\r', READ_MINITIMEOUT)
+ return True
+
+ def afterRebootEvConfigure(self,ser):
+ logger.info("ev300 configuring ,setup wifi")
+ cmd = 'ls\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ if not "sdcard" in ret.lower():
+ cmd = 'mkdir /sdcard\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ if "error:" in ret.lower():
+ logger.error("mkdir /sdcard fail")
+ return False
+ cmd = 'mount /dev/mmcblk0p0 /sdcard vfat\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ cmd = 'ls /sdcard\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ cmd = 'cd /sdcard/wpa\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ cmd = 'exec wpa_supplicant -i wlan0 -c wpa_supplicant.conf \r'
+ ret = sendCmd(ser, cmd, READ_MAXTIMEOUT)
+ if "error:" in ret.lower():
+ logger.error("setup wifi fail")
+ return False
+ cmd = 'ifconfig\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ if "error:" in ret.lower():
+ logger.error("ifconfig fail")
+ return False
+ return True
+
+ def eraseDevice(self, cmd, usb_port):
+ '''
+ ret 鏆傛椂娌℃湁浣滅敤锛屽厛浣跨敤out
+ '''
+ erase_retry = 0
+ while erase_retry < 3:
+ # 閫氱數
+ PowerOnByThread(usb_port)
+ logger.info("cmd is: %s" % cmd)
+ ret, outpri = subprocess.getstatusoutput(cmd)
+ logger.info("flash fastboot result: %s " % ret)
+ logger.info("print console: %s " % outpri)
+ is_earse_again = any([True if item in outpri else False for item in error_str_list])
+ if ret == 0 and erase_retry < 2 and not is_earse_again :
+ logger.info('妾櫎鎴愬姛'.center(20,'*'))
+ break
+ elif is_earse_again:
+ logger.info('妾櫎瀛樺湪闂 閲嶆柊涓婁笅鐢 閲嶆柊妾櫎')
+ erase_retry += 1
+ time.sleep(5)
+ continue
+ else:
+ logger.info('other error')
+ return False
+ else:
+ return False
+
+ def checkStatus(self, ser):
+ ret1 = sendCmd(ser, 'task', READ_TIMEOUT)
+ time.sleep(3)
+ ret2 = sendCmd(ser, 'task', READ_TIMEOUT)
+ if 'com.huawei.launcher' in ret1 and 'com.huawei.launcher' in ret2:
+ return True
+ logger.printLog('process com.huawei.launcher is not exist')
+ return False
+
+def PowerOnByThread(usb_port,wait_time=10):
+ thread = Thread(target=boardPowerOn, args=[usb_port, wait_time])
+ thread.start()
+ logger.info("thread board power on start")
+
+
+def boardPowerOn(usb_port, waittime):
+ logger.info("board power on start")
+ time.sleep(waittime)
+
+ #瀵圭鍙d笅鐢
+ if not usbPowerOnOff('127.0.0.1', '7788', usb_port, "off"):
+ logger.error("board power off failed")
+ return False
+
+ #瀵圭鍙d笂鐢
+ if not usbPowerOnOff('127.0.0.1', '7788', usb_port, "on"):
+ logger.error("board power on failed")
+ return False
+ logger.info("board power on end")
+
+
+def getBoardType(ser):
+ ret = sendCmd(ser, '\r', READ_TIMEOUT)
+ if 'HMOS' in ret or 'OHOS' in ret:
+ ostype = 'OHOS'
+ elif 'hisilicon' in ret:
+ ostype = 'uboot'
+ elif ' #' in ret:
+ ostype = 'linux'
+ else:
+ ostype = 'bootrom'
+ logger.info("board type is: %s" % ostype)
+ return ostype
+
+def sendCmd(ser, cmd, timeout):
+ logger.info("cmd is: %s " % cmd)
+ ser.write((cmd + '\n').encode())
+ time.sleep(0.5)
+ ret = ''
+ i = 0
+ while True:
+ out = ser.read(ser.inWaiting())
+ if not out:
+ break
+ if i > 12:
+ break
+ ret = ret + out.decode(encoding="utf-8", errors="ignore")
+ time.sleep(timeout)
+ i = i + 1
+ logger.info("result is: %s " % ret)
+ return ret
+
+
+
+if __name__ == "__main__":
+ param_file = sys.argv[1]
+ if not param_file:
+ logger.printLog("Missing params file")
+ sys.exit(-1)
+ try:
+ uphandle = liteOsUpgrade_L1(param_file)
+ uphandle._excuteApp()
+ except Exception as e:
+ logger.printLog(e)
+ sys.exit(-1)
diff --git a/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L1_shequ_dv_app.py b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L1_shequ_dv_app.py
new file mode 100644
index 0000000000000000000000000000000000000000..2a9fe655171f3e645184a741c148bb8767707a42
--- /dev/null
+++ b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L1_shequ_dv_app.py
@@ -0,0 +1,498 @@
+#-*- coding:utf-8 -*-
+import uuid
+import sys
+import subprocess
+import os
+import serial
+
+from core.base import BaseApp, dec_stepmsg
+from util.file_locker import FileLock
+from util.log_info import logger
+from util.time_info import get_now_time_str_info, get_now_time_info, Timeout, timeout
+from aw.Telnet.TelnetClient import TelConnect
+from aw.Common.Constant import CONSTANT
+from aw.Download.Download import *
+from aw.Common.Common import getHostIp, copyFile, copyDirectory
+from aw.ExtractFile.ExtractFile import *
+from aw.poweronoff.serial_power_on_off import usbPowerOnOff
+
+lock_suffix = CONSTANT.File.LOCK_SUFFIX #閫氳繃鏂囦欢閿佸疄鐜板苟鍙戜笅杞
+suc_file = CONSTANT.File.SUC_FILE #閫氳繃鏈枃浠舵槸鍖哄垎鐗堟湰鏄惁鎴愬姛涓嬭浇
+failed_file = CONSTANT.File.FAILED_FILE #閫氳繃鏈枃浠舵槸鏍囪鏂囦欢涓嬭浇澶辫触
+READ_MAXTIMEOUT = 120
+READ_TIMEOUT = 30
+READ_MINITIMEOUT = 5
+uboot_finish = 'hisilicon #'
+cmd_finish = ' #'
+
+class liteOsUpgrade_L1_shequ_dv(BaseApp):
+ '''
+ @author: w00278233
+ '''
+
+ def __init__(self, param_file):
+ super().__init__(param_file)
+ self.param_List = ["deploy_com",
+ "usb_port",
+ "upgrade_upgradeLocation"]
+
+ @dec_stepmsg("hongmeng L1 flash")
+ def excute(self):
+ '''
+ #===================================================================================
+ # @Method: excute(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鎵ц鍏ュ彛
+ # @PostStatus: none
+ # @eg: excute()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ step_index = self.params_dict.get("step_list").index("liteOsUpgrade_L1_shequ_dv_app")
+
+ # 鎵ц涓嬭浇
+ try:
+ if not self.download():
+ CONSTANT.ENVERRMESSAGE = "image download fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ except Exception as e:
+ raise e
+
+ # 鎵ц鍗囩骇
+ try:
+ if not self.upgrade():
+ CONSTANT.ENVERRMESSAGE = "board upgrade fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ return True
+ except Exception as e:
+ raise e
+
+ @dec_stepmsg("download")
+ @timeout(1800)
+ def download(self):
+ '''
+ #===================================================================================
+ # @Method: download(self)
+ # @Precondition: none
+ # @Func: 鏋勫缓涓嬭浇鍒版湰鍦扮殑璺緞锛屾墽琛岀浉搴斿寘鐨勪笅杞
+ # @PostStatus: none
+ # @eg: download()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global version_savepath, version_name
+ dir_path = CONSTANT.Path.getDirPath()
+ if self.params_dict.get("pbiid"):
+ version_path = self.params_dict.get("pbiid")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, str(self.params_dict.get("pbiid")) + "FASTBOOT"))
+ version_savepath = os.path.join(dir_path, self.params_dict.get("flash_type"), version_name)
+ else:
+ version_path = self.params_dict.get("upgrade_upgradeLocation")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, (self.params_dict.get("upgrade_upgradeLocation"))))
+ version_savepath = os.path.join(dir_path, version_name)
+
+ if self.params_dict.get("isDownload") == "True":
+ logger.printLog("涓嶉渶瑕佸仛涓嬭浇锛岀洿鎺ヨ繑鍥")
+ return True
+
+ #鎵цimg涓嬭浇
+ import hashlib
+ save_file_str = version_path.replace("/", "").replace("\\", "")
+ save_file_name = hashlib.sha1(save_file_str.encode("utf-8")).hexdigest()
+ logger.info("download hash string:%s, hash value:%s" % (save_file_str, save_file_name))
+ save_path_file = os.path.join(dir_path, "record", "%s%s" % (save_file_name, ".txt"))
+ if not self.excutedown(version_path, os.path.join(version_savepath, "img"), save_path_file, False):
+ logger.error("download img fail")
+ return False
+
+ #淇濆瓨鏈湴鐗堟湰璺緞缁檇evicetest鍘荤増鏈矾寰勪笅鍙栫敤渚
+ saveVersion(save_path_file, os.path.join(version_savepath, "img"))
+
+ #灏嗘湰鍦扮増鏈琾ush鍒拌繙绋媡ftp鏈嶅姟鍣
+ tftp_ip = self.params_dict.get("Tftpserver_IP")
+ if tftp_ip:
+ box_ip = subprocess.getoutput("ipconfig")
+ logger.info("current box ip is: %s" % box_ip)
+ if not tftp_ip in box_ip:
+ logger.info("start to send file")
+ return self.pushFileToTftpServer(tftp_ip, os.path.join(version_savepath, "img"), version_name)
+ return True
+
+ def pushFileToTftpServer(self, tftp_ip, local_file_path, dis_path, username="root", passwd="devicetest@2012"):
+ push_suc = os.path.join(local_file_path, "push_succ.txt")
+ push_fail = os.path.join(local_file_path, "push_fail.txt")
+ push_lock = os.path.join(local_file_path, "push.lock")
+ if os.path.isfile(push_suc):
+ logger.info("push file to tftpserver by other process.")
+ return True
+ elif os.path.isfile(push_fail):
+ logger.info("%s exists. Other process has push package and failed. It will push by self" % push_fail)
+ os.remove(push_fail)
+ else:
+ if os.path.isfile(push_lock):
+ logger.info("wait for other process send succ")
+ ret = waitotherdown(push_suc)
+ return ret
+
+ file_lock = FileLock()
+ file_lock.lockFile(push_lock)
+
+ try:
+ import paramiko
+ logger.info("ip: %s, source_path: %s" % (tftp_ip, local_file_path))
+ #client = paramiko.Transport((tftp_ip,22), default_window_size=3072)
+ client = paramiko.Transport((tftp_ip,22))
+ client.connect(username=username,password=passwd)
+ sftp = paramiko.SFTPClient.from_transport(client)
+ #妫鏌ftp鏈嶅姟鍣ㄦ牴鐩綍锛/data鎴/data/data
+ ret = sftp.listdir(r"/data")
+ server_base_dir = "/data/MobileUpgrade/local_img"
+ if "data" in ret:
+ server_base_dir = "/data/data/MobileUpgrade/local_img"
+ logger.info("server base dir is : %s " % server_base_dir)
+ #妫鏌ftp鏈嶅姟鍣ㄤ笂鏈夋病鏈夋湰娆$殑鐗堟湰鐩綍锛屽鏋滄病鏈夊垯鍒涘缓鏂囦欢澶
+ ret = sftp.listdir(server_base_dir)
+ server_des_path = "%s/%s" % (server_base_dir, dis_path)
+ if not dis_path in ret:
+ logger.info("mkdir in tftpserver: %s " % server_des_path)
+ sftp.mkdir(server_des_path)
+ server_img_path = "%s/%s/img" % (server_base_dir, dis_path)
+ logger.info("mkdir in tftpserver: %s " % server_img_path)
+ sftp.mkdir(server_img_path)
+ remote_path = "%s/%s/img" % (server_base_dir, dis_path)
+ logger.info("%s exists." % remote_path)
+ ret = sftp.listdir(remote_path)
+ #濡傛灉tftp鏈嶅姟鍣ㄤ笂鏈塸ush_succ鏂囦欢澶癸紝鍒欒鏄庡凡缁忕敱鍏跺畠杩涚▼鎴朾ox鎶婄増鏈笂浼犳垚鍔熶簡銆
+ if "push_succ" in ret:
+ logger.info("send file succ by other process")
+ with open(push_suc, "a+") as fp:
+ fp.write("")
+ return True
+ #濡傛灉tftp鏈嶅姟鍣ㄤ笂鏈塸ush.lock鏂囦欢澶癸紝鍒欒鏄庢湁鍏跺畠杩涚▼鍦ㄥ悜tftp鏈嶅姟鍣ㄥ彂閫佺増鏈紝绛夊緟鍏跺畠杩涚▼鍙戦佸畬姣曘
+ elif "push.lock" in ret:
+ logger.info("wait for other process")
+ i = 0
+ while True:
+ time.sleep(10)
+ ret = sftp.listdir(remote_path)
+ if "push_succ" in ret:
+ logger.info("other process succ")
+ return True
+ if i > 6:
+ logger.info("wait 60s, other process failed")
+ break
+ i = i + 1
+ #鐢辨湰杩涚▼鍚憈ftp鏈嶅姟鍣ㄥ彂閫佺増鏈紝鍏堝垱寤簆ush.lock鍗犵敤涓婁紶璧勬簮
+ logger.info("mkdir in tftpserver: %s/push.lock " % remote_path)
+ sftp.mkdir("%s/push.lock" % remote_path)
+ pushfilelist = ["OHOS_Image.bin", "rootfs.img", "userfs.img", "rootfs_vfat.img", "userfs_vfat.img", "rootfs_jffs2.img", "userfs_jffs2.img"]
+ for filename in pushfilelist:
+ if not os.path.exists(os.path.join(local_file_path, filename)):
+ continue
+ logger.info("copy %s to %s" % (os.path.join(local_file_path, filename), "%s/%s" % (remote_path, filename)))
+ try:
+ sftp.put(os.path.join(local_file_path, filename), "%s/%s" % (remote_path, filename))
+ except Exception as e:
+ logger.info("retry, copy %s to %s" % (os.path.join(local_file_path, filename), "%s/%s" % (remote_path, filename)))
+ sftp.put(os.path.join(local_file_path, filename), "%s/%s" % (remote_path, filename))
+ #鍒涘缓涓婁紶鎴愬姛鏍囪瘑
+ logger.info("mkdir in tftpserver: %s/push_succ " % remote_path)
+ sftp.mkdir("%s/push_succ" % remote_path)
+ #鍒犻櫎鍗犵敤鏍囪瘑
+ logger.info("del %s/push.lock " % remote_path)
+ sftp.rmdir("%s/push.lock" % remote_path)
+ with open(push_suc, "a+") as fp:
+ fp.write("")
+ time.sleep(10)
+ return True
+ except (OSError, Exception) as exception:
+ logger.error("copy to file to tftp server failed with error {}".format(exception))
+ logger.info("del %s/%s " % (server_base_dir, dis_path))
+ sftp.rmdir("%s/%s" % (server_base_dir, dis_path))
+ client.close()
+ with open(push_fail, "a+") as fp:
+ fp.write("")
+ return False
+ finally:
+ logger.info("close client")
+ client.close()
+
+ def excutedown(self, source_path, download_dir, suc_mark, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, is_file)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ #
+ # @eg: excutedown("xxxx", "D:\\local\\image", Flase锛 os_method)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ failed_mark = os.path.join(download_dir, failed_file)
+ lock_path = os.path.join(download_dir, lock_suffix)
+ file_lock = FileLock()
+
+ if isDownLoadSuccess(download_dir, suc_mark, failed_mark):
+ return True
+ try:
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s Downloading, please wait" % nowtime)
+ file_lock.lockFile(lock_path)
+ ret = ""
+ logger.info("Get lock. Start to ")
+ if self.params_dict.get("bt_enable") and self.params_dict.get("bt_enable") == "True":
+ ret = downloadByBitComet(source_path, download_dir, os_method)
+ elif source_path.startswith('\\\\'):
+ ret = downloadByCopy(source_path, download_dir, is_file)
+ elif self.params_dict.get("pbiid"):
+ ret = downlaodByDownloadTool(version_savepath, self.params_dict.get("version_type"), "FASTBOOT", self.params_dict.get("pbiid"))
+ elif source_path.startswith("http"):
+ ret = downloadFileFromDevCloud(source_path, "", "", download_dir)
+
+ if source_path.endswith(".zip"):
+ zip_name = os.path.basename(source_path)
+ ret = extractZipFile(os.path.join(download_dir, zip_name), download_dir)
+ if source_path.endswith(".tar.gz") or (source_path.startswith("http") and ("file_id=" in source_path)):
+ if source_path.startswith("http") and ("file_id=" in source_path):
+ if source_path.endswith(".tar.gz"):
+ zip_name = source_path.split('=')[-1]
+ else:
+ zip_name = "out.tar.gz"
+ else:
+ zip_name = os.path.basename(source_path)
+ ret = unTarFile(os.path.join(download_dir, zip_name), download_dir)
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s download to %s end" % (nowtime, download_dir))
+
+ if not ret:
+ with open(failed_mark, "a+") as fp:
+ fp.write("")
+ return ret
+ except Exception as e:
+ logger.printLog(e)
+ raise Exception(e)
+ finally:
+ file_lock.releaseFile()
+
+
+ @dec_stepmsg("upgrade")
+ #@timeout(900)
+ def upgrade(self):
+ '''
+ #===================================================================================
+ # @Method: upgrade(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鐩稿叧涓氬姟閫昏緫
+ # @PostStatus: none
+ # @eg: upgrade()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+
+ deploy_com = self.params_dict.get("deploy_com")
+ usb_port = self.params_dict.get("usb_port")
+ baudrate = self.params_dict.get("baudrate")
+ tftp_ip = self.params_dict.get("Tftpserver_IP")
+ device_ip = self.params_dict.get("Device_IP")
+ device_Mac = self.params_dict.get("Device_MAC")
+ device_netmask = self.params_dict.get("Device_Netmask")
+ device_gatewayip = self.params_dict.get("Device_GatewayIP")
+ #鑺墖绫诲瀷,鏍规嵁鑺墖绫诲瀷鑾峰彇瀵瑰簲鐨勫埛鏈哄懡浠
+ flash_type = self.params_dict.get("flash_type")
+
+ if not deploy_com:
+ logger.error("deploy_com is NULL !!")
+ return False
+ if not baudrate:
+ baudrate = 115200
+ if not device_netmask:
+ device_netmask = "255.255.252.0"
+ if not device_Mac:
+ device_Mac = "3a:82:d0:08:f4:99"
+ local_image_path = "%s/%s" % (version_name, "img")
+ scriptpath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))))
+ scriptfile = os.path.join(scriptpath, "resource", "L1", "dv300_shequ", "update.txt")
+ logger.info("upgrade scriptfile is: %s" % scriptfile)
+ if not os.path.exists(scriptfile):
+ logger.error("%s is not exit" % scriptfile)
+ return False
+
+ logger.info("open com")
+ ser = serial.Serial(deploy_com, int(baudrate), timeout=1)
+ try:
+ logger.info("鎵撳紑serial")
+ if ser.is_open == False:
+ ser.open()
+
+ logger.info("鑾峰彇鍗曟澘鐘舵")
+ board_type = getBoardType(ser)
+ if board_type != "uboot":
+ sendResetCmd(ser, READ_TIMEOUT)
+ board_type = getBoardType(ser)
+ if board_type == "bootrom":
+ if not recoveryBoard(ser, usb_port):
+ logger.error("recovery board fail, please check board")
+ return False
+
+ with open(scriptfile, "r") as fp:
+ lines = fp.readlines()
+ for line in lines:
+ #line = line.strip()
+ if not line:
+ logger.info("cmd is: %s " % line)
+ continue
+ if "%Tftpserver_IP%" in line:
+ line = line.replace("%Tftpserver_IP%", tftp_ip)
+ if "%Device_IP%" in line:
+ line = line.replace("%Device_IP%", device_ip)
+ if "%Device_MAC%" in line:
+ line = line.replace("%Device_MAC%", device_Mac)
+ if "%Device_Netmask%" in line:
+ line = line.replace("%Device_Netmask%", device_netmask)
+ if "%Device_GatewayIP%" in line:
+ line = line.replace("%Device_GatewayIP%", device_gatewayip)
+ if "userfs.img" in line:
+ if not os.path.exists(os.path.join(version_savepath, "img", "userfs.img")):
+ line = line.replace("userfs.img", "userfs_vfat.img")
+ if "rootfs.img" in line:
+ if not os.path.exists(os.path.join(version_savepath, "img", "rootfs.img")):
+ line = line.replace("rootfs.img", "rootfs_vfat.img")
+ if "tftp" in line:
+ packagefile_path = "/%s" % flash_type
+ new_packagefile_path = "/%s" % local_image_path
+ line = line.replace(packagefile_path, new_packagefile_path)
+ ret = sendCmd(ser, line, "hisilicon #", READ_MAXTIMEOUT)
+ if "retry count exceeded; starting again" in ret.lower():
+ logger.info("tftp cmd retry again!!")
+ ret = sendCmd(ser, line, "hisilicon #", READ_MAXTIMEOUT)
+ if "error:" in ret.lower():
+ logger.error("tftp fail")
+ return False
+ continue
+ if "reset" in line:
+ ret = sendCmd(ser, line, "OHOS #", READ_TIMEOUT)
+ continue
+ ret = sendCmd(ser, line, " #", READ_MINITIMEOUT)
+ board_type = getBoardType(ser)
+ if board_type == "OHOS":
+ logger.info("upgrade success")
+ init_cmd = "ifconfig eth0 %s netmask %s gateway %s \r" % (device_ip, device_netmask, device_gatewayip)
+ sendCmd(ser, init_cmd, "OHOS #", READ_MINITIMEOUT)
+ sendCmd(ser, 'ifconfig\r', "OHOS #", READ_MINITIMEOUT)
+ return True
+ else:
+ logger.info("upgrade fail")
+ return False
+ except Exception as e:
+ logger.printLog(e)
+ return False
+ finally:
+ ser.close()
+ logger.info("close serial")
+
+
+def boardPowerOn(usb_port):
+ logger.info("board power on start")
+
+ #瀵圭鍙d笅鐢
+ if not usbPowerOnOff('127.0.0.1', '7788', usb_port, "off"):
+ logger.error("board power off failed")
+ return False
+
+ #瀵圭鍙d笂鐢
+ if not usbPowerOnOff('127.0.0.1', '7788', usb_port, "on"):
+ logger.error("board power on failed")
+ return False
+ logger.info("board power on end")
+
+
+def getBoardType(ser):
+ ret = sendCmd(ser, '\r', " #", READ_MINITIMEOUT)
+ if 'HMOS' in ret or 'OHOS' in ret:
+ ostype = 'OHOS'
+ elif 'hisilicon' in ret:
+ ostype = 'uboot'
+ elif ' #' in ret:
+ ostype = 'linux'
+ else:
+ ostype = 'bootrom'
+ logger.info("board type is: %s" % ostype)
+ return ostype
+
+def sendCmd(ser, cmd, endtag, timeout):
+ ser.reset_input_buffer()
+ logger.info("cmd is: %s " % cmd)
+ ser.write((cmd + '\n').encode())
+ time.sleep(0.5)
+ i = 0
+ ret = ''
+ while True:
+ out = ser.read(ser.inWaiting())
+ ret = ret + out.decode(encoding="utf-8", errors="ignore")
+ if endtag in ret:
+ logger.info("cmd end")
+ break
+ time.sleep(1)
+ i = i + 1
+ if i > timeout:
+ logger.info("cmd timeout")
+ break
+ logger.info("result is: %s " % ret)
+ return ret
+
+def sendResetCmd(ser, timeout):
+ logger.info("send reset")
+ ser.reset_input_buffer()
+ ser.write(b"reset \r\n")
+ ret = ser.read(ser.inWaiting())
+ time.sleep(3)
+ #logger.info("result is: %s " % ret)
+ ser.write(b"\r\n")
+ ret = ser.read(ser.inWaiting())
+ logger.info("result is: %s " % ret)
+ ser.write(b"\r\n")
+ ret = ser.read(ser.inWaiting())
+ logger.info("result is: %s " % ret)
+ ser.write(b"\r\n")
+ ret = ser.read(ser.inWaiting())
+ logger.info("result is: %s " % ret)
+ return ret
+
+
+def recoveryBoard(ser, usb_port):
+ logger.info("start recovery board")
+ boardPowerOn(usb_port)
+ #鍐嶅彂閫佸洖杞
+ ser.write(b"\r\n")
+ time.sleep(0.5)
+ ret = ser.read(ser.inWaiting())
+ logger.info("result is: %s " % ret)
+ ser.write(b"\r\n")
+ time.sleep(0.5)
+ ret = ser.read(ser.inWaiting())
+ logger.info("result is: %s " % ret)
+ board_type = getBoardType(ser)
+ if board_type == "bootrom":
+ logger.error("recovery board failed")
+ return False
+ logger.info("recovery board succ")
+ return True
+
+
+if __name__ == "__main__":
+ param_file = sys.argv[1]
+ if not param_file:
+ logger.printLog("Missing params file")
+ sys.exit(-1)
+ try:
+ uphandle = liteOsUpgrade_L1(param_file)
+ uphandle._excuteApp()
+ except Exception as e:
+ logger.printLog(e)
+ sys.exit(-1)
\ No newline at end of file
diff --git a/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L1_shequ_test_app.py b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L1_shequ_test_app.py
new file mode 100644
index 0000000000000000000000000000000000000000..7dfa7fccea5eb30ed51b4d55fbca9e3fa8c18f78
--- /dev/null
+++ b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L1_shequ_test_app.py
@@ -0,0 +1,443 @@
+#-*- coding:utf-8 -*-
+import uuid
+import sys
+import subprocess
+import os
+import serial
+
+from core.base import BaseApp, dec_stepmsg
+from util.file_locker import FileLock
+from util.log_info import logger
+from util.time_info import get_now_time_str_info, get_now_time_info, Timeout, timeout
+from aw.Telnet.TelnetClient import TelConnect
+from aw.Common.Constant import CONSTANT
+from aw.Download.Download import *
+from aw.Common.Common import getHostIp, copyFile, copyDirectory
+from aw.ExtractFile.ExtractFile import *
+from aw.poweronoff.serial_power_on_off import usbPowerOnOff
+
+lock_suffix = CONSTANT.File.LOCK_SUFFIX #閫氳繃鏂囦欢閿佸疄鐜板苟鍙戜笅杞
+suc_file = CONSTANT.File.SUC_FILE #閫氳繃鏈枃浠舵槸鍖哄垎鐗堟湰鏄惁鎴愬姛涓嬭浇
+failed_file = CONSTANT.File.FAILED_FILE #閫氳繃鏈枃浠舵槸鏍囪鏂囦欢涓嬭浇澶辫触
+READ_MAXTIMEOUT = 60
+READ_TIMEOUT = 30
+READ_MINITIMEOUT = 5
+uboot_finish = 'hisilicon #'
+cmd_finish = ' #'
+
+class liteOsUpgrade_L1_shequ_test(BaseApp):
+ '''
+ @author: w00278233
+ '''
+
+ def __init__(self, param_file):
+ super().__init__(param_file)
+ self.param_List = ["deploy_com",
+ "usb_port",
+ "upgrade_upgradeLocation"]
+
+ @dec_stepmsg("hongmeng L1 flash")
+ def excute(self):
+ '''
+ #===================================================================================
+ # @Method: excute(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鎵ц鍏ュ彛
+ # @PostStatus: none
+ # @eg: excute()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ step_index = self.params_dict.get("step_list").index("liteOsUpgrade_L1_shequ_test_app")
+
+ # 鎵ц涓嬭浇
+ try:
+ if not self.download():
+ CONSTANT.ENVERRMESSAGE = "image download fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ except Exception as e:
+ raise e
+
+
+ # 鎵ц鍗囩骇
+ try:
+ if not self.upgrade():
+ CONSTANT.ENVERRMESSAGE = "board upgrade fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ return True
+ except Exception as e:
+ raise e
+
+ @dec_stepmsg("download")
+ @timeout(1800)
+ def download(self):
+ '''
+ #===================================================================================
+ # @Method: download(self)
+ # @Precondition: none
+ # @Func: 鏋勫缓涓嬭浇鍒版湰鍦扮殑璺緞锛屾墽琛岀浉搴斿寘鐨勪笅杞
+ # @PostStatus: none
+ # @eg: download()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global version_savepath, version_name
+ dir_path = CONSTANT.Path.getDirPath()
+ if self.params_dict.get("pbiid"):
+ version_path = self.params_dict.get("pbiid")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, str(self.params_dict.get("pbiid")) + "FASTBOOT"))
+ version_savepath = os.path.join(dir_path, self.params_dict.get("flash_type"), version_name)
+ else:
+ version_path = self.params_dict.get("upgrade_upgradeLocation")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, (self.params_dict.get("upgrade_upgradeLocation"))))
+ version_savepath = os.path.join(dir_path, version_name)
+
+ if self.params_dict.get("isDownload") == "True":
+ logger.printLog("涓嶉渶瑕佸仛涓嬭浇锛岀洿鎺ヨ繑鍥")
+ return True
+
+ #鎵цimg涓嬭浇
+ import hashlib
+ save_file_str = version_path.replace("/", "").replace("\\", "")
+ save_file_name = hashlib.sha1(save_file_str.encode("utf-8")).hexdigest()
+ logger.info("download hash value:%s" % (save_file_name))
+ save_path_file = os.path.join(dir_path, "record", "%s%s" % (save_file_name, ".txt"))
+ if not self.excutedown(version_path, os.path.join(version_savepath, "img"), save_path_file, False):
+ logger.error("download img fail")
+ return False
+
+ #淇濆瓨鏈湴鐗堟湰璺緞缁檇evicetest鍘荤増鏈矾寰勪笅鍙栫敤渚
+ saveVersion(save_path_file, os.path.join(version_savepath, "img"))
+
+ return True
+
+ def excutedown(self, source_path, download_dir, suc_mark, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, is_file)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ #
+ # @eg: excutedown("xxxx", "D:\\local\\image", Flase锛 os_method)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ failed_mark = os.path.join(download_dir, failed_file)
+ lock_path = os.path.join(download_dir, lock_suffix)
+ file_lock = FileLock()
+
+ if isDownLoadSuccess(download_dir, suc_mark, failed_mark):
+ return True
+ try:
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s Downloading, please wait" % nowtime)
+ file_lock.lockFile(lock_path)
+ ret = ""
+ logger.info("Get lock. Start to ")
+ if self.params_dict.get("bt_enable") and self.params_dict.get("bt_enable") == "True":
+ ret = downloadByBitComet(source_path, download_dir, os_method)
+ elif source_path.startswith('\\\\'):
+ ret = downloadByCopy(source_path, download_dir, is_file)
+ elif self.params_dict.get("pbiid"):
+ ret = downlaodByDownloadTool(version_savepath, self.params_dict.get("version_type"), "FASTBOOT", self.params_dict.get("pbiid"))
+ elif source_path.startswith("http"):
+ ret = downloadFileFromDevCloud(source_path, "", "", download_dir)
+
+ if source_path.endswith(".zip"):
+ zip_name = os.path.basename(source_path)
+ ret = extractZipFile(os.path.join(download_dir, zip_name), download_dir)
+ if source_path.endswith(".tar.gz") or (source_path.startswith("http") and ("file_id=" in source_path)):
+ if source_path.startswith("http") and ("file_id=" in source_path):
+ if source_path.endswith(".tar.gz"):
+ zip_name = source_path.split('=')[-1]
+ else:
+ zip_name = "out.tar.gz"
+ else:
+ zip_name = os.path.basename(source_path)
+ ret = unTarFile(os.path.join(download_dir, zip_name), download_dir)
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s download to %s end" % (nowtime, download_dir))
+
+ if not ret:
+ with open(failed_mark, "a+") as fp:
+ fp.write("")
+ return ret
+ except Exception as e:
+ logger.printLog(e)
+ raise Exception(e)
+ finally:
+ file_lock.releaseFile()
+
+
+ @dec_stepmsg("upgrade")
+ #@timeout(900)
+ def upgrade(self):
+ '''
+ #===================================================================================
+ # @Method: upgrade(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鐩稿叧涓氬姟閫昏緫
+ # @PostStatus: none
+ # @eg: upgrade()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ logger.printLog('寮濮嬪崌绾')
+ deploy_com = self.params_dict.get("deploy_com")
+ usb_port = self.params_dict.get("usb_port")
+ baudrate = self.params_dict.get("baudrate")
+ #鑺墖绫诲瀷,鏍规嵁鑺墖绫诲瀷鑾峰彇瀵瑰簲鐨勫埛鏈哄懡浠
+ flash_type = self.params_dict.get("flash_type")
+ burn_usbport = self.params_dict.get("hiburn_usbport")
+ device_ip = self.params_dict.get("Device_IP")
+ device_netmask = self.params_dict.get("Device_Netmask")
+ device_gatewayip = self.params_dict.get("Device_GatewayIP")
+ chip_version = self.params_dict.get('chip_version')
+ chip_version = chip_version.lower() if chip_version else chip_version
+
+ if not deploy_com:
+ logger.error("deploy_com is NULL !!")
+ return False
+ if not burn_usbport:
+ logger.error("hiburn_usbport is NULL !!")
+ return False
+ if not baudrate:
+ baudrate = 115200
+ scriptpath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))))
+ #鍗囩骇闇瑕佺殑宸ュ叿褰掓。
+ logger.printLog('褰掓。宸ュ叿')
+ toolworkspace = CONSTANT.OSType.getworkspace()
+ hiburntoolpath = os.path.join(toolworkspace, "HiBurnCmdLine", "usb%s_tool" % burn_usbport)
+ logger.info("hiburn tool path is: %s" % hiburntoolpath)
+ if not os.path.exists(hiburntoolpath):
+ if not burn_usbport:
+ logger.error("hiburn_usbport is NULL !!")
+ return False
+ os.makedirs(hiburntoolpath)
+ toolpath = os.path.join(scriptpath, "resource", "HiBurnCmdLine.zip")
+ logger.info("copy %s to %s" % (toolpath, hiburntoolpath))
+ copyFile(toolpath, hiburntoolpath)
+ zip_name = os.path.basename(toolpath)
+ ret = extractZipFile(os.path.join(hiburntoolpath, zip_name), hiburntoolpath)
+ if ret:
+ logger.info("unzip to %s succ" % (hiburntoolpath))
+ #淇敼burn.config涓殑usb鍙
+ configpath = os.path.join(hiburntoolpath, "config", "burn.config")
+ all_data = ""
+ with open(configpath, "r", encoding="utf-8") as cf:
+ for line in cf:
+ if "usbDeviceNumber=" in line:
+ old_str = line
+ line = line.replace(old_str, "usbDeviceNumber=%s\r\n" % burn_usbport)
+ logger.info("replace line: %s " % line)
+ all_data += line
+ with open(configpath, "w", encoding="utf-8") as wf:
+ wf.write(all_data)
+ else:
+ logger.error("%s is not exit" % hiburntoolpath)
+ return False
+ #灏嗗崌绾ч渶瑕佺殑鏂囦欢鎷疯礉鍒伴暅鍍忛噷闈
+ logger.printLog('鎷疯礉闀滃儚')
+ local_image_path = os.path.join(version_savepath, "img")
+ old_xml_path = os.path.join(scriptpath, "resource", "L1", flash_type, "usb-burn.xml")
+ xml_path = os.path.join(local_image_path, "usb-burn.xml")
+ if chip_version == 'hi3518':
+ old_xml_path = os.path.join(scriptpath, "resource", "L1", flash_type, "usb-burn-jffs2.xml")
+ elif chip_version == 'hi3516':
+ old_xml_path = os.path.join(scriptpath, "resource", "L1", flash_type, "usb-burn-vfat.xml")
+ copyFile(old_xml_path, xml_path)
+ if flash_type.lower() == "ev300":
+ chip_type = "Hi3518EV300"
+ ubootpath = os.path.join(scriptpath, "resource", "L1", flash_type.lower(), "u-boot-hi3518ev300.bin")
+ elif flash_type.lower() == "dv300":
+ chip_type = "Hi3516DV300"
+ ubootpath = os.path.join(scriptpath, "resource", "L1", flash_type.lower(), "u-boot-hi3516dv300.bin")
+ else:
+ logger.error("flash_type is : %s " % flash_type)
+ return False
+ copyFile(ubootpath, local_image_path)
+ scriptfile = os.path.join(scriptpath, "resource", "L1", flash_type.lower(), "update.txt")
+
+ from threading import Thread
+ thread = Thread(target=boardPowerOn, args=[usb_port, 10])
+ thread.start()
+
+ current_path = os.getcwd()
+ logger.info("before excute hiburn,current path is: %s" % current_path)
+ os.chdir(hiburntoolpath)
+ logger.info("excute hiburn path is: %s" % os.getcwd())
+ #鎿﹂櫎fastboot
+ logger.printLog('鎿﹂櫎fastboot')
+ flash_uboot_xml = os.path.join(scriptpath, "resource", "L1", flash_type.lower(), "flash_fastboot.xml")
+ cmd = ".\jre\\bin\java -jar hiburn.jar --erase -n %s -m serial %s -x %s" % (chip_type, deploy_com.upper(), flash_uboot_xml)
+ logger.info("cmd is: %s" % cmd)
+ ret, outpri = subprocess.getstatusoutput(cmd)
+ logger.info("flash fastboot result: %s " % ret)
+ logger.info("print console: %s " % outpri)
+
+ retry = 0
+ while retry < 2:
+
+ #usb鍒锋満
+ logger.printLog('寮濮嬪埛鏈')
+ cmd = ".\jre\\bin\java -jar hiburn.jar --burn -n %s -m USBBootrom -x %s" % (chip_type, xml_path)
+ logger.info("cmd is: %s" % cmd)
+ ret, outpri = subprocess.getstatusoutput(cmd)
+ logger.info("usb upgrade result: %s " % ret)
+ logger.info("print console: %s " % outpri)
+ if ret != 0:
+ if ret == 4:
+ time.sleep(10)
+ retry = retry + 1
+ logger.printLog('鍒锋満鏈垚鍔熷啀鍒蜂竴娆')
+ continue
+ logger.printLog(ret)
+ logger.error("hiburn usb upgrade failed!!")
+ return False
+ retry = retry + 3
+ os.chdir(current_path)
+ logger.info("hiburn upgrade end, check board status")
+ time.sleep(5)
+ ser = serial.Serial(deploy_com, int(baudrate), timeout=1)
+ reset_count = 0
+ try:
+ while reset_count < 2:
+ logger.info("鎵撳紑serial")
+ if ser.is_open == False:
+ ser.open()
+
+ logger.info("鑾峰彇鍗曟澘鐘舵")
+ board_type = getBoardType(ser)
+ logger.printLog('before reset')
+ logger.printLog(f'board_type:{board_type}')
+ if board_type == "uboot":
+ with open(scriptfile, "r") as fp:
+ lines = fp.readlines()
+ for line in lines:
+ if not line:
+ logger.info("cmd is: %s " % line)
+ continue
+ if "reset" in line:
+ ret = sendCmd(ser, line, READ_MAXTIMEOUT)
+ continue
+ ret = sendCmd(ser, line, READ_MINITIMEOUT)
+ board_type = getBoardType(ser)
+ logger.printLog('after reset')
+ logger.printLog(f'board_type:{board_type}')
+
+ if True:
+ reset_count += 1
+ logger.printLog('鍐嶆閲嶅惎')
+ continue
+ time.sleep(1000)
+ if flash_type.lower() == "dv300":
+ logger.info("upgrade success")
+ init_cmd = "ifconfig eth0 %s netmask %s gateway %s \r" % (device_ip, device_netmask, device_gatewayip)
+ sendCmd(ser, init_cmd, READ_MINITIMEOUT)
+ sendCmd(ser, 'ifconfig\r', READ_MINITIMEOUT)
+ return True
+ elif flash_type.lower() == "ev300":
+ logger.info("setup wifi")
+ cmd = 'ls\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ if not "sdcard" in ret.lower():
+ cmd = 'mkdir /sdcard\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ if "error:" in ret.lower():
+ logger.error("mkdir /sdcard fail")
+ return False
+ cmd = 'mount /dev/mmcblk0p0 /sdcard vfat\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ cmd = 'ls /sdcard\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ cmd = 'cd /sdcard/wpa\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ cmd = 'exec wpa_supplicant -i wlan0 -c wpa_supplicant.conf \r'
+ ret = sendCmd(ser, cmd, READ_MAXTIMEOUT)
+ if "error:" in ret.lower():
+ logger.error("setup wifi fail")
+ return False
+ cmd = 'ifconfig\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ if "error:" in ret.lower():
+ logger.error("ifconfig fail")
+ return False
+ logger.info("upgrade success")
+ return True
+ else:
+ logger.error("upgrade fail")
+ return False
+ except Exception as e:
+ logger.printLog(e)
+ return False
+ finally:
+ ser.close()
+ logger.info("close serial")
+
+
+def boardPowerOn(usb_port, waittime):
+ logger.info("board power on start")
+ time.sleep(waittime)
+
+ #瀵圭鍙d笅鐢
+ if not usbPowerOnOff('127.0.0.1', '7788', usb_port, "off"):
+ logger.error("board power off failed")
+ return False
+
+ #瀵圭鍙d笂鐢
+ if not usbPowerOnOff('127.0.0.1', '7788', usb_port, "on"):
+ logger.error("board power on failed")
+ return False
+ logger.info("board power on end")
+
+
+def getBoardType(ser):
+ ret = sendCmd(ser, '\r', READ_TIMEOUT)
+ if 'HMOS' in ret or 'OHOS' in ret:
+ ostype = 'OHOS'
+ elif 'hisilicon' in ret:
+ ostype = 'uboot'
+ elif ' #' in ret:
+ ostype = 'linux'
+ else:
+ ostype = 'bootrom'
+ logger.info("board type is: %s" % ostype)
+ return ostype
+
+def sendCmd(ser, cmd, timeout):
+ logger.info("cmd is: %s " % cmd)
+ ser.write((cmd + '\n').encode())
+ time.sleep(0.5)
+ ret = ''
+ i = 0
+ while True:
+ out = ser.read(ser.inWaiting())
+ if not out:
+ break
+ if i > 2:
+ break
+ ret = ret + out.decode(encoding="utf-8", errors="ignore")
+ time.sleep(timeout)
+ i = i + 1
+ logger.info("result is: %s " % ret)
+ return ret
+
+
+
+if __name__ == "__main__":
+ param_file = sys.argv[1]
+ if not param_file:
+ logger.printLog("Missing params file")
+ sys.exit(-1)
+ try:
+ uphandle = liteOsUpgrade_L1(param_file)
+ uphandle._excuteApp()
+ except Exception as e:
+ logger.printLog(e)
+ sys.exit(-1)
diff --git "a/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L2_app - \345\211\257\346\234\254.py" "b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L2_app - \345\211\257\346\234\254.py"
new file mode 100644
index 0000000000000000000000000000000000000000..87126e156bc7611ff5c6c02739c126442dde02fe
--- /dev/null
+++ "b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L2_app - \345\211\257\346\234\254.py"
@@ -0,0 +1,364 @@
+#-*- coding:utf-8 -*-
+import uuid
+import sys
+import subprocess
+import os
+import serial
+
+from core.base import BaseApp, dec_stepmsg
+from util.file_locker import FileLock
+from util.log_info import logger
+from util.time_info import get_now_time_str_info, get_now_time_info, Timeout, timeout
+from aw.Telnet.TelnetClient import TelConnect
+from aw.Common.Constant import CONSTANT
+from aw.Download.Download import *
+from aw.Common.Common import getHostIp, copyFile, copyDirectory
+from aw.ExtractFile.ExtractFile import *
+from aw.poweronoff.serial_power_on_off import usbPowerOnOff
+from threading import Thread
+
+lock_suffix = CONSTANT.File.LOCK_SUFFIX #閫氳繃鏂囦欢閿佸疄鐜板苟鍙戜笅杞
+suc_file = CONSTANT.File.SUC_FILE #閫氳繃鏈枃浠舵槸鍖哄垎鐗堟湰鏄惁鎴愬姛涓嬭浇
+failed_file = CONSTANT.File.FAILED_FILE #閫氳繃鏈枃浠舵槸鏍囪鏂囦欢涓嬭浇澶辫触
+READ_MAXTIMEOUT = 20
+READ_TIMEOUT = 30
+READ_MINITIMEOUT = 5
+uboot_finish = 'hisilicon #'
+cmd_finish = ' #'
+
+class liteOsUpgrade_L2(BaseApp):
+
+ def __init__(self, param_file):
+ super().__init__(param_file)
+ self.param_List = ["deploy_com",
+ "usb_port",
+ "upgrade_upgradeLocation"]
+
+ @dec_stepmsg("hongmeng L2 flash")
+ def excute(self):
+ '''
+ #===================================================================================
+ # @Method: excute(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鎵ц鍏ュ彛
+ # @PostStatus: none
+ # @eg: excute()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ step_index = self.params_dict.get("step_list").index("liteOsUpgrade_L2_app")
+
+ # 鎵ц涓嬭浇
+ try:
+ if not self.download():
+ CONSTANT.ENVERRMESSAGE = "image download fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ except Exception as e:
+ raise e
+
+
+ # 鎵ц鍗囩骇
+ try:
+ if not self.upgrade():
+ CONSTANT.ENVERRMESSAGE = "board upgrade fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ return True
+ except Exception as e:
+ raise e
+
+ @dec_stepmsg("download")
+ @timeout(18000)
+ def download(self):
+ '''
+ #===================================================================================
+ # @Method: download(self)
+ # @Precondition: none
+ # @Func: 鏋勫缓涓嬭浇鍒版湰鍦扮殑璺緞锛屾墽琛岀浉搴斿寘鐨勪笅杞
+ # @PostStatus: none
+ # @eg: download()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global version_savepath, version_name
+ dir_path = CONSTANT.Path.getDirPath()
+ if self.params_dict.get("pbiid"):
+ version_path = self.params_dict.get("pbiid")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, str(self.params_dict.get("pbiid")) + "FASTBOOT"))
+ version_savepath = os.path.join(dir_path, self.params_dict.get("flash_type"), version_name)
+ else:
+ version_path = self.params_dict.get("upgrade_upgradeLocation")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, (self.params_dict.get("upgrade_upgradeLocation"))))
+ version_savepath = os.path.join(dir_path, version_name)
+
+ if self.params_dict.get("isDownload") == "True":
+ logger.printLog("涓嶉渶瑕佸仛涓嬭浇锛岀洿鎺ヨ繑鍥")
+ return True
+
+ #鎵цimg涓嬭浇
+ import hashlib
+ save_file_str = version_path.replace("/", "").replace("\\", "")
+ save_file_name = hashlib.sha1(save_file_str.encode("utf-8")).hexdigest()
+ logger.info("download hash value:%s" % (save_file_name))
+ save_path_file = os.path.join(dir_path, "record", "%s%s" % (save_file_name, ".txt"))
+ logger.printLog('save_path_file: %s' % save_path_file)
+ if not self.excutedown(version_path, os.path.join(version_savepath, "img"), save_path_file, False):
+ logger.error("download img fail")
+ return False
+
+ #淇濆瓨鏈湴鐗堟湰璺緞缁檇evicetest鍘荤増鏈矾寰勪笅鍙栫敤渚
+ saveVersion(save_path_file, os.path.join(version_savepath, "img"))
+
+ return True
+
+ def excutedown(self, source_path, download_dir, suc_mark, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, is_file)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ #
+ # @eg: excutedown("xxxx", "D:\\local\\image", Flase锛 os_method)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ failed_mark = os.path.join(download_dir, failed_file)
+ lock_path = os.path.join(download_dir, lock_suffix)
+ file_lock = FileLock()
+
+ if isDownLoadSuccess(download_dir, suc_mark, failed_mark):
+ return True
+ try:
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s Downloading, please wait" % nowtime)
+ file_lock.lockFile(lock_path)
+ ret = ""
+ logger.info("Get lock. Start to ")
+ if self.params_dict.get("bt_enable") and self.params_dict.get("bt_enable") == "True":
+ ret = downloadByBitComet(source_path, download_dir, os_method)
+ elif source_path.startswith('\\\\'):
+ ret = downloadByCopy(source_path, download_dir, is_file)
+ elif self.params_dict.get("pbiid"):
+ ret = downlaodByDownloadTool(version_savepath, self.params_dict.get("version_type"), "FASTBOOT", self.params_dict.get("pbiid"))
+ elif source_path.startswith("http"):
+ ret = downloadFileFromDevCloud(source_path, "", "", download_dir)
+
+ if source_path.endswith(".zip"):
+ zip_name = os.path.basename(source_path)
+ ret = extractZipFile(os.path.join(download_dir, zip_name), download_dir)
+ if source_path.endswith(".tar.gz") or (source_path.startswith("http") and ("file_id=" in source_path)):
+ if source_path.startswith("http") and ("file_id=" in source_path):
+ if source_path.endswith(".tar.gz"):
+ zip_name = source_path.split('=')[-1]
+ else:
+ zip_name = "out.tar.gz"
+ else:
+ zip_name = os.path.basename(source_path)
+ logger.printLog(f'tar_file:{os.path.join(download_dir, zip_name)},dest_file:{download_dir}')
+ ret = unTarFile(os.path.join(download_dir, zip_name), download_dir)
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s download to %s end" % (nowtime, download_dir))
+
+ if not ret:
+ with open(failed_mark, "a+") as fp:
+ fp.write("")
+ return ret
+ except Exception as e:
+ logger.printLog(e)
+ raise Exception(e)
+ finally:
+ file_lock.releaseFile()
+
+
+ @dec_stepmsg("upgrade")
+ #@timeout(900)
+ def upgrade(self):
+ '''
+ #===================================================================================
+ # @Method: upgrade(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鐩稿叧涓氬姟閫昏緫
+ # @PostStatus: none
+ # @eg: upgrade()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ logger.printLog('寮濮嬪崌绾')
+ deploy_com = self.params_dict.get("deploy_com")
+ usb_port = self.params_dict.get("usb_port")
+ baudrate = self.params_dict.get("baudrate")
+ #鑺墖绫诲瀷,鏍规嵁鑺墖绫诲瀷鑾峰彇瀵瑰簲鐨勫埛鏈哄懡浠
+ flash_type = self.params_dict.get("flash_type")
+ burn_usbport = self.params_dict.get("hiburn_usbport")
+ device_ip = self.params_dict.get("Device_IP")
+ device_netmask = self.params_dict.get("Device_Netmask")
+ device_gatewayip = self.params_dict.get("Device_GatewayIP")
+ chip_version = self.params_dict.get('chip_version')
+ chip_version = chip_version.lower() if chip_version else chip_version
+
+ if not deploy_com:
+ logger.error("deploy_com is NULL !!")
+ return False
+ if not burn_usbport:
+ logger.error("hiburn_usbport is NULL !!")
+ return False
+ if not baudrate:
+ baudrate = 115200
+ scriptpath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))))
+ #鍗囩骇闇瑕佺殑宸ュ叿褰掓。
+ toolworkspace = CONSTANT.OSType.getworkspace()
+ hiburntoolpath = os.path.join(toolworkspace, "HiBurnCmdLine", "usb%s_tool" % burn_usbport)
+ logger.info("hiburn tool path is: %s" % hiburntoolpath)
+ if not os.path.exists(hiburntoolpath):
+ if not burn_usbport:
+ logger.error("hiburn_usbport is NULL !!")
+ return False
+ os.makedirs(hiburntoolpath)
+ toolpath = os.path.join(scriptpath, "resource", "HiBurnCmdLine.zip")
+ logger.info("copy %s to %s" % (toolpath, hiburntoolpath))
+ copyFile(toolpath, hiburntoolpath)
+ zip_name = os.path.basename(toolpath)
+ ret = extractZipFile(os.path.join(hiburntoolpath, zip_name), hiburntoolpath)
+ if ret:
+ logger.info("unzip to %s succ" % (hiburntoolpath))
+ #淇敼burn.config涓殑usb鍙
+ configpath = os.path.join(hiburntoolpath, "config", "burn.config")
+ all_data = ""
+ with open(configpath, "r", encoding="utf-8") as cf:
+ for line in cf:
+ if "usbDeviceNumber=" in line:
+ old_str = line
+ line = line.replace(old_str, "usbDeviceNumber=%s\r\n" % burn_usbport)
+ logger.info("replace line: %s " % line)
+ all_data += line
+ with open(configpath, "w", encoding="utf-8") as wf:
+ wf.write(all_data)
+ else:
+ logger.error("%s is not exit" % hiburntoolpath)
+ return False
+ #灏嗗崌绾ч渶瑕佺殑鏂囦欢鎷疯礉鍒伴暅鍍忛噷闈
+ local_image_path = os.path.join(version_savepath, "img")
+ old_xml_path = os.path.join(scriptpath, "resource", "L2", flash_type, "Hi3516DV300-emmc.xml")
+ xml_path = os.path.join(local_image_path, "Hi3516DV300-emmc.xml")
+ copyFile(old_xml_path, xml_path)
+ if flash_type.lower() == "ev300":
+ chip_type = "Hi3518EV300"
+ elif flash_type.lower() == "dv300":
+ chip_type = "Hi3516DV300"
+ else:
+ logger.error("flash_type is : %s " % flash_type)
+ return False
+ # copyFile(ubootpath, local_image_path)
+ scriptfile = os.path.join(scriptpath, "resource", "L2", f'{flash_type.lower()}', "update.txt")
+ logger.info(f'scriptfile:{scriptfile}')
+
+ current_path = os.getcwd()
+ logger.info("before excute hiburn,current path is: %s" % current_path)
+ os.chdir(hiburntoolpath)
+ logger.info("excute hiburn path is: %s" % os.getcwd())
+ #鎿﹂櫎fastboot
+ logger.printLog('erase fastboot')
+ flash_uboot_xml = os.path.join(scriptpath, "resource", "L2", flash_type.lower(), "flash_fastboot.xml")
+ erase_retry = 0
+ while erase_retry < 3:
+ # 閫氱數
+ PowerOnByThread(usb_port)
+ cmd = ".\jre\\bin\java -jar hiburn.jar --erase -n %s -m serial %s -x %s" % (chip_type, deploy_com.upper(), flash_uboot_xml)
+ logger.info("cmd is: %s" % cmd)
+ ret, outpri = subprocess.getstatusoutput(cmd)
+ logger.info("flash fastboot result: %s " % ret)
+ logger.info("print console: %s " % outpri)
+ if ret == 0 and 'Unknown' not in outpri and erase_retry < 2:
+ break
+ elif 'Unknown' in outpri:
+ logger.info('涓插彛闂 閲嶆柊涓婁笅鐢 閲嶆柊妾櫎')
+ erase_retry += 1
+ time.sleep(5)
+ continue
+ else:
+ logger.info('other error')
+ return False
+ else:
+ return False
+
+ retry = 0
+ while retry < 3:
+ #usb鍒锋満
+ cmd = ".\jre\\bin\java -jar hiburn.jar --burn -n %s -m USBBootrom -x %s" % (chip_type, xml_path)
+ logger.info("cmd is: %s" % cmd)
+ ret, outpri = subprocess.getstatusoutput(cmd)
+ logger.info("usb upgrade result: %s " % ret)
+ logger.info("print console: %s " % outpri)
+ if ret != 0:
+ if ret == 4 and retry < 2:
+ time.sleep(10)
+ retry = retry + 1
+ logger.info('flash fail,so flash once again')
+ continue
+ logger.info(ret)
+ logger.error("hiburn usb upgrade failed!!")
+ return False
+ retry = retry + 3
+ os.chdir(current_path)
+ logger.info("hiburn upgrade end, check board status")
+ return True
+
+def PowerOnByThread(usb_port,wait_time=10):
+ thread = Thread(target=boardPowerOn, args=[usb_port, wait_time])
+ thread.start()
+ logger.info("thread board power on start")
+
+
+def boardPowerOn(usb_port, waittime):
+ logger.info("board power on start")
+ time.sleep(waittime)
+
+ #瀵圭鍙d笅鐢
+ if not usbPowerOnOff('127.0.0.1', '7788', usb_port, "off"):
+ logger.error("board power off failed")
+ return False
+
+ #瀵圭鍙d笂鐢
+ if not usbPowerOnOff('127.0.0.1', '7788', usb_port, "on"):
+ logger.error("board power on failed")
+ return False
+ logger.info("board power on end")
+
+
+def getBoardType(ser):
+ ret = sendCmd(ser, '\r', READ_TIMEOUT)
+ if 'HMOS' in ret or 'OHOS' in ret:
+ ostype = 'OHOS'
+ elif 'hisilicon' in ret:
+ ostype = 'uboot'
+ elif ' #' in ret:
+ ostype = 'linux'
+ else:
+ ostype = 'bootrom'
+ logger.info("board type is: %s" % ostype)
+ return ostype
+
+def sendCmd(ser, cmd, timeout):
+ logger.info("cmd is: %s " % cmd)
+ ser.write((cmd + '\n').encode())
+ time.sleep(0.5)
+ ret = ''
+ i = 0
+ while True:
+ out = ser.read(ser.inWaiting())
+ if not out:
+ break
+ if i > 2:
+ break
+ ret = ret + out.decode(encoding="utf-8", errors="ignore")
+ time.sleep(timeout)
+ i = i + 1
+ logger.info("result is: %s " % ret)
+ return ret
+
+
diff --git a/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L2_app.py b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L2_app.py
new file mode 100644
index 0000000000000000000000000000000000000000..126f44da59b74c8d0021b74fb87bf619e5b2e08f
--- /dev/null
+++ b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L2_app.py
@@ -0,0 +1,524 @@
+#-*- coding:utf-8 -*-
+import uuid
+import sys
+import subprocess
+import os
+import serial
+import datetime
+
+from core.base import BaseApp, dec_stepmsg
+from util.file_locker import FileLock
+from util.log_info import logger
+from util.time_info import get_now_time_str_info, get_now_time_info, Timeout, timeout
+from aw.Telnet.TelnetClient import TelConnect
+from aw.Common.Constant import CONSTANT
+from aw.Download.Download import *
+from aw.Common.Common import getHostIp, copyFile, copyDirectory
+from aw.ExtractFile.ExtractFile import *
+from aw.poweronoff.serial_power_on_off import usbPowerOnOff, usbPowerOnOffV2
+from threading import Thread
+from subprocess import getstatusoutput
+
+lock_suffix = CONSTANT.File.LOCK_SUFFIX #閫氳繃鏂囦欢閿佸疄鐜板苟鍙戜笅杞
+suc_file = CONSTANT.File.SUC_FILE #閫氳繃鏈枃浠舵槸鍖哄垎鐗堟湰鏄惁鎴愬姛涓嬭浇
+failed_file = CONSTANT.File.FAILED_FILE #閫氳繃鏈枃浠舵槸鏍囪鏂囦欢涓嬭浇澶辫触
+READ_MAXTIMEOUT = 5
+READ_TIMEOUT = 5
+READ_MINITIMEOUT = 2
+uboot_finish = 'hisilicon #'
+cmd_finish = ' #'
+error_str_list = ['Unknown', '鍙戦佽捣濮嬪抚澶辫触', '鍙戦佸ご甯уけ璐']
+
+_is_download_success = False
+
+
+class liteOsUpgrade_L2(BaseApp):
+
+ def __init__(self, param_file):
+ super().__init__(param_file)
+ self.param_List = ["deploy_com",
+ "usb_port",
+ "upgrade_upgradeLocation"]
+
+ @dec_stepmsg("hongmeng L2 flash")
+ def excute(self):
+ '''
+ #===================================================================================
+ # @Method: excute(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鎵ц鍏ュ彛
+ # @PostStatus: none
+ # @eg: excute()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ step_index = self.params_dict.get("step_list").index("liteOsUpgrade_L2_app")
+
+ # 鎵ц涓嬭浇
+ try:
+ if not self.download():
+ CONSTANT.ENVERRMESSAGE = "image download fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ except Exception as e:
+ raise e
+
+
+ # 鎵ц鍗囩骇
+ try:
+ if not self.upgrade():
+ CONSTANT.ENVERRMESSAGE = "board upgrade fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ return True
+ except Exception as e:
+ raise e
+
+ @dec_stepmsg("download")
+ @timeout(18000)
+ def download(self):
+ '''
+ #===================================================================================
+ # @Method: download(self)
+ # @Precondition: none
+ # @Func: 鏋勫缓涓嬭浇鍒版湰鍦扮殑璺緞锛屾墽琛岀浉搴斿寘鐨勪笅杞
+ # @PostStatus: none
+ # @eg: download()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global version_savepath, version_name, _is_download_success
+ dir_path = CONSTANT.Path.getDirPath()
+ if self.params_dict.get("pbiid"):
+ version_path = self.params_dict.get("pbiid")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, str(self.params_dict.get("pbiid")) + "FASTBOOT"))
+ version_savepath = os.path.join(dir_path, self.params_dict.get("flash_type"), version_name)
+ else:
+ version_path = self.params_dict.get("upgrade_upgradeLocation")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, (self.params_dict.get("upgrade_upgradeLocation"))))
+ version_savepath = os.path.join(dir_path, version_name)
+
+ if self.params_dict.get("isDownload") == "True":
+ logger.printLog("涓嶉渶瑕佸仛涓嬭浇锛岀洿鎺ヨ繑鍥")
+ return True
+
+ #鎵цimg涓嬭浇
+ import hashlib
+ save_file_str = version_path.replace("/", "").replace("\\", "")
+ save_file_name = hashlib.sha1(save_file_str.encode("utf-8")).hexdigest()
+ logger.info("download hash value:%s" % (save_file_name))
+ save_path_file = os.path.join(dir_path, "record", "%s%s" % (save_file_name, ".txt"))
+ logger.printLog('save_path_file: %s' % save_path_file)
+ if not self.excutedown(version_path, os.path.join(version_savepath, "img"), save_path_file, False):
+ logger.error("download img fail")
+ return False
+ _is_download_success = True
+ #淇濆瓨鏈湴鐗堟湰璺緞缁檇evicetest鍘荤増鏈矾寰勪笅鍙栫敤渚
+ saveVersion(save_path_file, os.path.join(version_savepath, "img"))
+
+ return True
+
+ def excutedown(self, source_path, download_dir, suc_mark, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, is_file)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ #
+ # @eg: excutedown("xxxx", "D:\\local\\image", Flase锛 os_method)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ failed_mark = os.path.join(download_dir, failed_file)
+ lock_path = os.path.join(download_dir, lock_suffix)
+ file_lock = FileLock()
+
+ if isDownLoadSuccess(download_dir, suc_mark, failed_mark):
+ return True
+ try:
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s Downloading, please wait" % nowtime)
+ file_lock.lockFile(lock_path)
+ ret = ""
+ logger.info("Get lock. Start to ")
+ if self.params_dict.get("bt_enable") and self.params_dict.get("bt_enable") == "True":
+ ret = downloadByBitComet(source_path, download_dir, os_method)
+ elif source_path.startswith('\\\\'):
+ ret = downloadByCopy(source_path, download_dir, is_file)
+ elif self.params_dict.get("pbiid"):
+ ret = downlaodByDownloadTool(version_savepath, self.params_dict.get("version_type"), "FASTBOOT", self.params_dict.get("pbiid"))
+ elif source_path.startswith("http"):
+ ret = downloadFileFromDevCloud(source_path, "", "", download_dir)
+
+ if source_path.endswith(".zip"):
+ zip_name = os.path.basename(source_path)
+ ret = extractZipFile(os.path.join(download_dir, zip_name), download_dir)
+ if source_path.endswith(".tar.gz") or (source_path.startswith("http") and ("file_id=" in source_path)):
+ if source_path.startswith("http") and ("file_id=" in source_path):
+ if source_path.endswith(".tar.gz"):
+ zip_name = source_path.split('=')[-1]
+ else:
+ zip_name = "out.tar.gz"
+ else:
+ zip_name = os.path.basename(source_path)
+ logger.printLog(f'tar_file:{os.path.join(download_dir, zip_name)},dest_file:{download_dir}')
+ ret = unTarFile(os.path.join(download_dir, zip_name), download_dir)
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s download to %s end" % (nowtime, download_dir))
+
+ if not ret:
+ with open(failed_mark, "a+") as fp:
+ fp.write("")
+ return ret
+ except Exception as e:
+ logger.printLog(e)
+ raise Exception(e)
+ finally:
+ file_lock.releaseFile()
+
+
+ @dec_stepmsg("upgrade")
+ #@timeout(900)
+ def upgrade(self):
+ '''
+ #===================================================================================
+ # @Method: upgrade(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鐩稿叧涓氬姟閫昏緫
+ # @PostStatus: none
+ # @eg: upgrade()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global _is_download_success
+ logger.printLog('寮濮嬪崌绾')
+ deploy_com = self.params_dict.get("deploy_com")
+ usb_port = self.params_dict.get("usb_port")
+ baudrate = self.params_dict.get("baudrate")
+ #鑺墖绫诲瀷,鏍规嵁鑺墖绫诲瀷鑾峰彇瀵瑰簲鐨勫埛鏈哄懡浠
+ flash_type = self.params_dict.get("flash_type")
+ burn_usbport = self.params_dict.get("hiburn_usbport")
+ device_ip = self.params_dict.get("Device_IP")
+ device_netmask = self.params_dict.get("Device_Netmask")
+ device_gatewayip = self.params_dict.get("Device_GatewayIP")
+ chip_version = self.params_dict.get('chip_version')
+ chip_version = chip_version.lower() if chip_version else chip_version
+ sn = self.params_dict.get('sn')
+
+ if not deploy_com:
+ logger.error("deploy_com is NULL !!")
+ return False
+ if not burn_usbport:
+ logger.error("hiburn_usbport is NULL !!")
+ return False
+ if not baudrate:
+ baudrate = 115200
+ #鎵ц涓嬭浇
+ t_download = Thread(target=self.download, args=())
+ t_download.start()
+ scriptpath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))))
+ #鍗囩骇闇瑕佺殑宸ュ叿褰掓。
+ toolworkspace = CONSTANT.OSType.getworkspace()
+ hiburntoolpath = os.path.join(toolworkspace, "HiBurnCmdLine", "usb%s_tool" % burn_usbport)
+ logger.info("hiburn tool path is: %s" % hiburntoolpath)
+ if not os.path.exists(hiburntoolpath):
+ if not burn_usbport:
+ logger.error("hiburn_usbport is NULL !!")
+ return False
+ os.makedirs(hiburntoolpath)
+ toolpath = os.path.join(scriptpath, "resource", "HiBurnCmdLine.zip")
+ logger.info("copy %s to %s" % (toolpath, hiburntoolpath))
+ copyFile(toolpath, hiburntoolpath)
+ zip_name = os.path.basename(toolpath)
+ ret = extractZipFile(os.path.join(hiburntoolpath, zip_name), hiburntoolpath)
+ if ret:
+ logger.info("unzip to %s succ" % (hiburntoolpath))
+ #淇敼burn.config涓殑usb鍙
+ configpath = os.path.join(hiburntoolpath, "config", "burn.config")
+ all_data = ""
+ with open(configpath, "r", encoding="utf-8") as cf:
+ for line in cf:
+ if "usbDeviceNumber=" in line:
+ old_str = line
+ line = line.replace(old_str, "usbDeviceNumber=%s\r\n" % burn_usbport)
+ logger.info("replace line: %s " % line)
+ all_data += line
+ with open(configpath, "w", encoding="utf-8") as wf:
+ wf.write(all_data)
+ else:
+ logger.error("%s is not exit" % hiburntoolpath)
+ return False
+ os.chdir(hiburntoolpath)
+ if flash_type.lower() == "ev300":
+ chip_type = "Hi3518EV300"
+ elif flash_type.lower() == "dv300":
+ chip_type = "Hi3516DV300"
+ else:
+ logger.error("flash_type is : %s " % flash_type)
+ return False
+ #鎿﹂櫎fastboot
+ logger.printLog('erase fastboot')
+ flash_uboot_xml = os.path.join(scriptpath, "resource", "L2", flash_type.lower(), "flash_fastboot.xml")
+ cmd = ".\jre\\bin\java -jar hiburn.jar --erase -n %s -m serial %s -x %s" % (chip_type, deploy_com.upper(), flash_uboot_xml)
+ self.eraseDevice(cmd, usb_port)
+ t_download.join()
+ # 妫鏌ヤ笅杞芥槸鍚︽垚鍔
+ if not _is_download_success:
+ return False
+
+ #灏嗗崌绾ч渶瑕佺殑鏂囦欢鎷疯礉鍒伴暅鍍忛噷闈
+ local_image_path = os.path.join(version_savepath, "img")
+ old_xml_path = os.path.join(scriptpath, "resource", "L2", flash_type, "Hi3516DV300-emmc.xml")
+ xml_path = os.path.join(local_image_path, "Hi3516DV300-emmc.xml")
+ copyFile(old_xml_path, xml_path)
+ # copyFile(ubootpath, local_image_path)
+ scriptfile = os.path.join(scriptpath, "resource", "L2", f'{flash_type.lower()}', "update.txt")
+ logger.info(f'scriptfile:{scriptfile}')
+
+ logger.printLog('杩涜鐑у啓')
+ retry = 0
+ while retry < 3:
+ #usb鍒锋満
+ cmd = ".\jre\\bin\java -jar hiburn.jar --burn -n %s -m USBBootrom -x %s" % (chip_type, xml_path)
+ logger.info("cmd is: %s" % cmd)
+ ret, outpri = subprocess.getstatusoutput(cmd)
+ logger.info("usb upgrade result: %s " % ret)
+ logger.info("print console: %s " % outpri)
+ if ret != 0:
+ if ret == 4 and retry < 2:
+ time.sleep(10)
+ retry = retry + 1
+ logger.info('flash fail,so flash once again')
+ continue
+ logger.info(ret)
+ logger.error("hiburn usb upgrade failed!!")
+ return False
+ retry = retry + 3
+ os.chdir(current_path)
+ logger.info("hiburn upgrade end, check board status")
+ logger.info("涓轰繚鎸乭dc绋冲畾鎬э紝绛夊緟60绉")
+ time.sleep(60)
+ try:
+ #pass
+ self.hdc_set_time(sn)
+ except Exception as e:
+ logger.printLog('hdc璁剧疆鏃堕棿瓒呮椂')
+ logger.printLog(str(e))
+ try:
+ logger.info("鎵撳紑serial")
+ ser = serial.Serial(deploy_com, int(baudrate), timeout=0)
+ if ser.is_open == False:
+ ser.open()
+ logger.info("get device status")
+ board_type = getBoardType(ser)
+ if board_type == "OHOS" and self.checkStatus(ser):
+ return True
+
+ # ret = sendCmd(ser, 'sa;reset;', READ_MAXTIMEOUT)
+ # board_type = getBoardType(ser)
+ # if board_type != "OHOS":
+ # logger.error("upgrade fail")
+ # return False
+ else:
+ return False
+ except Exception as e:
+ logger.info(str(e))
+ return False
+ finally:
+ ser.close()
+ logger.info("close serial")
+
+ def checkStatus(self, ser):
+ time.sleep(180)
+ # print('wait 120 seconds')
+ ren_cmd = 'ps -elf | grep render_service'
+ laun_cmd = 'ps -elf | grep com.ohos.launcher'
+ time.sleep(10)
+ ren_status_1 = getPsPid(ser, ren_cmd, 'render_service')
+ time.sleep(5)
+ ren_status_2 = getPsPid(ser, ren_cmd, 'render_service')
+ time.sleep(5)
+ laun_status_1 = getPsPid(ser, laun_cmd, 'com.ohos.launcher')
+ time.sleep(5)
+ laun_status_2 = getPsPid(ser, laun_cmd, 'com.ohos.launcher')
+ # wes_cmd = 'pidof weston'
+ # laun_cmd = 'pidof com.ohos.launcher'
+ # time.sleep(10)
+ # wes_status_1 = sendCmd(ser, wes_cmd, READ_TIMEOUT)
+ # time.sleep(5)
+ # wes_status_2 = sendCmd(ser, wes_cmd, READ_TIMEOUT)
+ # time.sleep(5)
+ # laun_status_1 = sendCmd(ser, laun_cmd, READ_TIMEOUT)
+ # time.sleep(5)
+ # laun_status_2 = sendCmd(ser, laun_cmd, READ_TIMEOUT)
+ logger.info('ren_status_1: %s ren_status_2: %s laun_1: %s laun_2: %s '%(ren_status_1,ren_status_2,laun_status_1,laun_status_2))
+ if ren_status_1 and ren_status_1 == ren_status_2 and laun_status_1 and laun_status_1 == laun_status_2:
+ return True
+ if not ren_status_1 or not ren_status_2 or ren_status_1 != ren_status_2:
+ # and not wes_status_1.strip().isdigit() or not wes_status_2.strip().isdigit()
+ logger.printLog('process render_service is not exist')
+ if not laun_status_1 or not laun_status_2 :
+ # or not laun_status_1.strip().isdigit() or not laun_status_2.strip().isdigit()
+ logger.printLog('process com.ohos.launcher is not exist')
+ return False
+
+ @timeout(30)
+ def hdc_set_time(self,sn):
+ # todo
+ y_m_d = time.strftime('%Y-%m-%d',time.localtime())
+ h_m_s = time.strftime('%H:%M:%S',time.localtime())
+ cmd = 'hdc_std -t %s shell date -u "%sT%s"'% (sn,y_m_d,h_m_s)
+ logger.printLog('hdc start set time')
+ logger.printLog('cmd is %s'% cmd)
+ ret,out = subprocess.getstatusoutput(cmd)
+ logger.printLog('hdc end set time')
+ if h_m_s not in out:
+ logger.printLog('hdc璁剧疆鏃堕棿澶辫触')
+ logger.printLog(out)
+ return False
+ logger.printLog(out)
+
+ def eraseDevice(self, cmd, usb_port):
+ '''
+ ret 鏆傛椂娌℃湁浣滅敤锛屽厛浣跨敤out
+ '''
+ erase_retry = 0
+ while erase_retry < 3:
+ # 閫氱數
+ PowerOnByThread(usb_port)
+ logger.info("cmd is: %s" % cmd)
+ ret, outpri = subprocess.getstatusoutput(cmd)
+ logger.info("flash fastboot result: %s " % ret)
+ logger.info("print console: %s " % outpri)
+ is_earse_again = any([True if item in outpri else False for item in error_str_list])
+ if ret == 0 and erase_retry < 2 and not is_earse_again :
+ logger.info('妾櫎鎴愬姛'.center(20,'*'))
+ break
+ elif is_earse_again:
+ logger.info('妾櫎瀛樺湪闂 閲嶆柊涓婁笅鐢 閲嶆柊妾櫎')
+ erase_retry += 1
+ time.sleep(5)
+ continue
+ else:
+ logger.info('other error')
+ return False
+ else:
+ return False
+
+ def catchEraseFail(self,cmd):
+ logger.printLog(datetime.datetime.now())
+ ret, outpri = subprocess.getstatusoutput(cmd)
+ logger.printLog(datetime.datetime.now())
+ return ret,outpri
+
+def getPsPid(ser, cmd, ps):
+ try:
+ data = sendCmd(ser, cmd, READ_TIMEOUT)
+ logger.info(data)
+ data = [item for item in data.split('\n') if 'grep' not in item and ps in item ]
+ if len(data) < 1:
+ return
+ elif len(data) > 1:
+ data = max(data, key=len, default='')
+ logger.info(data)
+ data = data[0].split()
+ if len(data) < 1:
+ return
+ else:
+ logger.info(data)
+ return data[1]
+ except Exception as e :
+ logger.info(str(e))
+ logger.info('pid 鑾峰彇澶辫触')
+
+def PowerOnByThread(usb_port,wait_time=10):
+ thread = Thread(target=boardPowerOn, args=[usb_port, wait_time])
+ thread.start()
+ logger.info("thread board power on start")
+
+
+
+def boardPowerOn(usb_port, waittime):
+ logger.info("board power on start")
+ time.sleep(waittime)
+
+ #瀵圭鍙d笅鐢
+ if not usbPowerOnOff('127.0.0.1', '7788', usb_port, "off"):
+ logger.error("board power off failed")
+ return False
+
+ #瀵圭鍙d笂鐢
+ if not usbPowerOnOff('127.0.0.1', '7788', usb_port, "on"):
+ logger.error("board power on failed")
+ return False
+ logger.info("board power on end")
+
+
+def getBoardType(ser):
+ ret = sendCmd(ser, '\r', READ_TIMEOUT)
+ if 'HMOS' in ret or 'OHOS' in ret or 'console:/ $' in ret or '#' in ret:
+ ostype = 'OHOS'
+ elif 'hisilicon' in ret:
+ ostype = 'uboot'
+ elif ' #' in ret:
+ ostype = 'linux'
+ else:
+ ostype = 'bootrom'
+ logger.info("board type is: %s" % ostype)
+ return ostype
+
+def sendCmd(ser, cmd, timeout):
+ logger.info("cmd is: %s " % cmd)
+ ser.write((cmd + '\n').encode())
+ time.sleep(0.5)
+ ret = ''
+ i = 0
+ while True:
+ out = ser.read(ser.inWaiting())
+ if not out:
+ break
+ if i > 12:
+ break
+ ret = ret + out.decode(encoding="utf-8", errors="ignore")
+ time.sleep(timeout)
+ i = i + 1
+ logger.info("result is: %s " % ret)
+ return ret
+
+def sendHdcCmd(cmd):
+ from subprocess import getstatusoutput
+ i = 0
+ while True:
+ if i > 3:
+ break
+ try:
+ out = executeHdcCmd(cmd)
+ logger.info('hdc cmd success')
+ return out
+ except Exception as e:
+ logger.info(str(e))
+ logger.info('hdc cmd fail')
+ i += 1
+ time.sleep(1)
+ continue
+ logger.error('hdc cmd execute fail by three times')
+ return ''
+
+@timeout(10)
+def executeHdcCmd(cmd):
+ logger.info('cmd is %s' % cmd)
+ time.sleep(0.5)
+ ret, out = getstatusoutput(cmd)
+ time.sleep(0.5)
+ if ret != 0:
+ logger.info('execute fail')
+ return 'execute fail'
+ logger.info('result is %s'% out)
+ return out
+
+if __name__ == '__main__':
+ ser = serial.Serial('com5', 115200, timeout=0)
\ No newline at end of file
diff --git a/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L3_app.py b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L3_app.py
new file mode 100644
index 0000000000000000000000000000000000000000..c4f898dda78032c5138e9a4f0a8c7c0df611f863
--- /dev/null
+++ b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_L3_app.py
@@ -0,0 +1,342 @@
+#-*- coding:utf-8 -*-
+import uuid
+import sys
+import subprocess
+import os
+import serial
+
+from core.base import BaseApp, dec_stepmsg
+from util.file_locker import FileLock
+from util.log_info import logger
+from util.time_info import get_now_time_str_info, get_now_time_info, Timeout, timeout
+from aw.Telnet.TelnetClient import TelConnect
+from aw.Common.Constant import CONSTANT
+from aw.Download.Download import *
+from aw.Common.Common import getHostIp
+from aw.ExtractFile.ExtractFile import *
+from aw.poweronoff.serial_power_on_off import serialPowerOnOff
+
+lock_suffix = CONSTANT.File.LOCK_SUFFIX #閫氳繃鏂囦欢閿佸疄鐜板苟鍙戜笅杞
+suc_file = CONSTANT.File.SUC_FILE #閫氳繃鏈枃浠舵槸鍖哄垎鐗堟湰鏄惁鎴愬姛涓嬭浇
+failed_file = CONSTANT.File.FAILED_FILE #閫氳繃鏈枃浠舵槸鏍囪鏂囦欢涓嬭浇澶辫触
+READ_MAXTIMEOUT = 600
+READ_TIMEOUT = 30
+READ_MINITIMEOUT = 5
+uboot_finish = 'hisilicon #'
+cmd_finish = ' #'
+
+class liteOsUpgrade_L3(BaseApp):
+ '''
+ @author: w00278233
+ '''
+
+ def __init__(self, param_file):
+ super().__init__(param_file)
+ self.param_List = ["upgrade_upgradeLocation"]
+
+ @dec_stepmsg("hongmeng L3 flash")
+ def excute(self):
+ '''
+ #===================================================================================
+ # @Method: excute(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鎵ц鍏ュ彛
+ # @PostStatus: none
+ # @eg: excute()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ step_index = self.params_dict.get("step_list").index("liteOsUpgrade_L3_app")
+
+ # 鎵ц涓嬭浇
+ try:
+ if not self.download():
+ CONSTANT.ENVERRMESSAGE = "image download fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ except Exception as e:
+ raise e
+
+ # 鎵ц鍗囩骇
+ try:
+ status = self.upgrade()
+ logger.info(status)
+ logger.info(type(status))
+ logger.info(f'鍗囩骇鐘舵:{str(status)}')
+ if not status:
+ CONSTANT.ENVERRMESSAGE = "board upgrade fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ return True
+ except Exception as e:
+ raise e
+
+ @dec_stepmsg("download")
+ @timeout(1800)
+ def download(self):
+ '''
+ #===================================================================================
+ # @Method: download(self)
+ # @Precondition: none
+ # @Func: 鏋勫缓涓嬭浇鍒版湰鍦扮殑璺緞锛屾墽琛岀浉搴斿寘鐨勪笅杞
+ # @PostStatus: none
+ # @eg: download()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global version_savepath, version_name
+ dir_path = CONSTANT.Path.getDirPath()
+ if self.params_dict.get("pbiid"):
+ version_path = self.params_dict.get("pbiid")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, str(self.params_dict.get("pbiid")) + "FASTBOOT"))
+ version_savepath = os.path.join(dir_path, self.params_dict.get("flash_type"), version_name)
+ else:
+ version_path = self.params_dict.get("upgrade_upgradeLocation")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, (self.params_dict.get("upgrade_upgradeLocation"))))
+ version_savepath = os.path.join(dir_path, version_name)
+ logger.printLog(version_savepath)
+
+ if self.params_dict.get("isDownload") == "True":
+ logger.printLog("涓嶉渶瑕佸仛涓嬭浇锛岀洿鎺ヨ繑鍥")
+ return True
+
+ #鎵цimg涓嬭浇
+ import hashlib
+ save_file_str = version_path.replace("/", "").replace("\\", "")
+ save_file_name = hashlib.sha1(save_file_str.encode("utf-8")).hexdigest()
+ logger.info("download hash string:%s, hash value:%s" % (save_file_str, save_file_name))
+ save_path_file = os.path.join(dir_path, "record", "%s%s" % (save_file_name, ".txt"))
+ if not self.excutedown(version_path, os.path.join(version_savepath, "img"), save_path_file, False):
+ logger.error("download img fail")
+ return False
+
+ #淇濆瓨鏈湴鐗堟湰璺緞缁檇evicetest鍘荤増鏈矾寰勪笅鍙栫敤渚
+ saveVersion(save_path_file, os.path.join(version_savepath, "img"))
+
+ # 鎵ц鍗囩骇鑴氭湰涓嬭浇
+ if self.params_dict.get("upgrade_script"):
+ suc_mark = os.path.join(version_savepath, "scriptfile", suc_file)
+ if not self.excutedown(self.params_dict.get("upgrade_script"),
+ os.path.join(version_savepath, "scriptfile"), suc_mark, True):
+ logger.error("download upgrade script fail")
+ return False
+ with open(suc_mark, "a+") as fp:
+ fp.write("")
+
+ return True
+
+ def excutedown(self, source_path, download_dir, suc_mark, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, is_file)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ #
+ # @eg: excutedown("xxxx", "D:\\local\\image", Flase锛 os_method)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ failed_mark = os.path.join(download_dir, failed_file)
+ lock_path = os.path.join(download_dir, lock_suffix)
+ file_lock = FileLock()
+ if isDownLoadSuccess(download_dir, suc_mark, failed_mark):
+ return True
+ try:
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s Downloading, please wait" % nowtime)
+ file_lock.lockFile(lock_path)
+ ret = ""
+ logger.info("Get lock. Start to ")
+ if self.params_dict.get("bt_enable") and self.params_dict.get("bt_enable") == "True":
+ ret = downloadByBitComet(source_path, download_dir, os_method)
+ elif source_path.startswith('\\\\'):
+ ret = downloadByCopy(source_path, download_dir, is_file)
+ elif self.params_dict.get("pbiid"):
+ ret = downlaodByDownloadTool(version_savepath, self.params_dict.get("version_type"), "FASTBOOT", self.params_dict.get("pbiid"))
+ elif source_path.startswith("http"):
+ # 涓存椂淇敼涓嬭浇閾炬帴
+ source_path = self.modifyHttpLink(source_path)
+ logger.info(f'modify path:{source_path}')
+ ret = downloadFileFromDevCloud(source_path, "", "", download_dir)
+
+ if source_path.endswith(".zip"):
+ zip_name = os.path.basename(source_path)
+ ret = extractZipFile(os.path.join(download_dir, zip_name), download_dir)
+ if source_path.endswith(".tar.gz") or (source_path.startswith("http") and ("file_id=" in source_path)):
+ if source_path.startswith("http") and ("file_id=" in source_path):
+ if source_path.endswith(".tar.gz"):
+ zip_name = source_path.split('=')[-1]
+ else:
+ zip_name = "out.tar.gz"
+ else:
+ zip_name = os.path.basename(source_path)
+ ret = unTarFile(os.path.join(download_dir, zip_name), download_dir)
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s download to %s end" % (nowtime, download_dir))
+
+ if not ret:
+ with open(failed_mark, "a+") as fp:
+ fp.write("")
+ return ret
+ except Exception as e:
+ logger.printLog(e)
+ raise Exception(e)
+ finally:
+ file_lock.releaseFile()
+
+ def modifyHttpLink(self,link):
+ try:
+ base_link = 'https://hm-verify.obs.cn-north-4.myhuaweicloud.com/'
+ filename = link.split('&')[-1].split('=')[-1]
+ names = filename.split('-')
+ link_1 = '/'.join(names[0:-1])
+ link_2 = f'/{filename}'
+ final_link = base_link + link_1 + link_2
+ return final_link
+ except Exception as e:
+ logger.info('path is errror.check the link_path is right,please')
+ logger.info(str(e))
+
+
+ @dec_stepmsg("upgrade")
+ @timeout(900)
+ def upgrade(self):
+ '''
+ #===================================================================================
+ # @Method: upgrade(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鐩稿叧涓氬姟閫昏緫
+ # @PostStatus: none
+ # @eg: upgrade()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ try:
+ #time.sleep(1000)
+ logger.printLog('寮濮嬪崌绾')
+ self.enterTheDevice()
+ time.sleep(5)
+ self.flashSystemImg()
+ time.sleep(5)
+ self.rebootDevice()
+ return True
+ except Exception as e:
+ logger.error('***********************************')
+ logger.error(str(e))
+ logger.error('flash fail')
+ logger.error('***********************************')
+ return False
+
+ #@timeout(30*3)
+ def enterTheDevice(self):
+ logger.info('enter fastboot status'.center(50,'*'))
+ devices_status_count = 0
+ while devices_status_count < 3 :
+ if self.isFastbootStatus():
+ break
+ devices_status_count += 1
+ time.sleep(20)
+ else:
+ logger.error(f'device {self.params_dict.get("sn")} is not exist ,please make sure the sn is True')
+ raise Exception('ERROR_SN_DEVICE_NOT_EXIST')
+
+ #@timeout(20)
+ def isFastbootStatus(self):
+ adb_retcode, adb_output = subprocess.getstatusoutput('adb devices')
+
+ fastboot_retcode, fastboot_output = subprocess.getstatusoutput('fastboot devices')
+
+ if self.params_dict.get('sn') in adb_output:
+ retcode, output = subprocess.getstatusoutput('adb -s %s reboot fastboot' % self.params_dict.get('sn'))
+ logger.info('adb -s %s reboot fastboot retcode: %s'% (self.params_dict.get('sn'),str(retcode)))
+ logger.info('adb -s %s reboot fastboot output: %s'% (self.params_dict.get('sn'),output))
+ logger.info('device from adb mode to fastboot mode,please wait')
+ time.sleep(30)
+ retcode, output = subprocess.getstatusoutput('fastboot devices')
+ logger.info('fastboot devices fastboot_retcode: %s'% str(fastboot_retcode))
+ logger.info('fastboot devices fastboot_output: %s'% fastboot_output)
+ if self.params_dict.get('sn') in output:
+ logger.info('device enter fastboot mode success')
+ return True
+ else:
+ logger.info('device enter fastboot mode fail')
+ return False
+ elif self.params_dict.get('sn') in fastboot_output:
+ logger.info('device has been in fastboot mode')
+ return True
+ else:
+ logger.info('璁惧鏈壘鍒帮紝閲嶆柊灏濊瘯')
+ return False
+
+ @timeout(60*2*3)
+ def flashSystemImg(self):
+ logger.info('flash system.img '.center(50,'*'))
+ flash_count = 0
+ while flash_count < 3:
+ status = self.isFlashSuccess()
+ logger.info(status)
+ if status:
+ break
+ flash_count +=1
+ time.sleep(3)
+ else:
+ logger.error('system.img闀滃儚鍒峰啓澶辫触')
+ raise Exception('[ERROR] ERROR_FLASH_SYSTEM.IMG_FAIL')
+
+ @timeout(60*2)
+ def isFlashSuccess(self):
+ #local_image_path = os.path.join(version_savepath, 'img', r'aosp\target\product\generic_arm64', 'system.img')
+ local_image_path = os.path.join(version_savepath, 'img', 'system.img')
+ logger.info(f'flash img path: {local_image_path}')
+ if os.path.exists(local_image_path):
+ retcode, output = subprocess.getstatusoutput('fastboot -s %s flash system %s' % (self.params_dict.get('sn'), local_image_path))
+ logger.info('fastboot -s %s flash system %s retcode: %s'% (self.params_dict.get('sn'),local_image_path,str(retcode)))
+ logger.info('fastboot -s %s flash system %s output: %s'% (self.params_dict.get('sn'),local_image_path,output))
+ if retcode == 0:
+ logger.info('flash system.img success')
+ return True
+ else:
+ flash_count += 1
+ logger.info('鍐嶆灏濊瘯鍒穝ystem.img闀滃儚')
+
+ else:
+ logger.error('闀滃儚鏂囦欢璺緞涓嶅')
+ raise Exception('[ERROR] ERROR_IMG_PATH_NOT_EXIST')
+
+ def rebootDevice(self):
+ logger.info('reboot the device '.center(50,'*'))
+ reboot_count = 0
+ while reboot_count < 3 :
+ logger.info('start reboot')
+ if self.isRebootSuccess():
+ break
+ else:
+ reboot_count +=1
+ time.sleep(10)
+ else:
+ raise Exception('[ERROR] ERROR_REBOOT_DEVICE_FAIL')
+
+ def isRebootSuccess(self):
+ retcode, output = subprocess.getstatusoutput('fastboot -s %s reboot' % self.params_dict.get('sn'))
+ logger.info('fastboot -s %s reboot retcode: %s'% (self.params_dict.get('sn'),str(retcode)))
+ logger.info('fastboot -s %s reboot output: %s'% (self.params_dict.get('sn'),output))
+ time.sleep(50)
+ retcode, output = subprocess.getstatusoutput('adb devices')
+ logger.info('adb devices: %s'% str(retcode))
+ logger.info('adb devices: %s'% output)
+ if self.params_dict.get('sn') in output:
+ logger.info('reboot success')
+ return True
+ else:
+ logger.info('reboot fail')
+ return False
+
+
+
+if __name__ == '__main__':
+ liteOsUpgrade_L3.modifyHttpLink(liteOsUpgrade_L3,
+ 'https://devrepo.devcloud.cn-north-4.huaweicloud.com/DevRepoServer/v1/files/download?file_id=0fe39c430a364f59bd040c53e7a3ef1c&type=archive&filename=Daily_Version#2021-05-19_06-38-31#L35_aosp_arm64.tar.gz')
\ No newline at end of file
diff --git a/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_RK3568_app-926.py b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_RK3568_app-926.py
new file mode 100644
index 0000000000000000000000000000000000000000..849dbc0bd4f2b9ba998fce8cc1334df8646ebcc1
--- /dev/null
+++ b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_RK3568_app-926.py
@@ -0,0 +1,511 @@
+# -*- coding:utf-8 -*-
+import uuid
+import sys
+import subprocess
+import os
+import time
+import re
+import shutil
+import random
+
+
+from core.base import BaseApp, dec_stepmsg
+from util.file_locker import FileLock
+from util.log_info import logger
+from util.time_info import get_now_time_str_info, get_now_time_info, Timeout, timeout
+from aw.Download.Download import *
+from aw.Common.Constant import CONSTANT
+from aw.Common.Common import getFileName
+from aw.ExtractFile.ExtractFile import *
+from aw.Common.Common import getHostIp, copyFile, copyDirectory
+
+lock_suffix = CONSTANT.File.LOCK_SUFFIX
+suc_file = CONSTANT.File.SUC_FILE
+failed_file = CONSTANT.File.FAILED_FILE
+REBOOT_TIMEOUT = 20000000
+
+
+class liteOsUpgrade_RK3568(BaseApp):
+ '''
+ @author: cwx1076044
+ '''
+
+ def __init__(self, param_file):
+ super().__init__(param_file)
+ self.param_List = ["upgrade_upgradeLocation", "sn"]
+
+ @dec_stepmsg("hongmeng RK3568 flash")
+ def excute(self):
+ '''
+ #===================================================================================
+ # @Method: excute(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鎵ц鍏ュ彛
+ # @PostStatus: none
+ # @eg: excute()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ step_index = self.params_dict.get("step_list").index("liteOsUpgrade_RK3568_app")
+
+ # 鎵ц涓嬭浇
+ try:
+ if not self.download():
+ CONSTANT.ENVERRMESSAGE = "image download fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ except Exception as e:
+ logger.error(e)
+ raise e
+
+ # 鎵ц鍗囩骇
+ try:
+ return_code = self.upgrade()
+ if not return_code:
+ CONSTANT.ENVERRMESSAGE = "board upgrade fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ if return_code == 98:
+ return 98
+ if return_code == 99:
+ return 99
+ return True
+ except Exception as e:
+ logger.error(e)
+ raise e
+
+ @dec_stepmsg("upgrade")
+ @timeout(3600)
+ def upgrade(self):
+ '''
+ #===================================================================================
+ # @Method: upgrade(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鐩稿叧涓氬姟閫昏緫
+ # @PostStatus: none
+ # @eg: upgrade()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global local_image_path, loader_tool_path, sn, LocationID ,test_num
+ upgrade_test_type = self.params_dict.get("UpgradeTestType")
+ sn = self.params_dict.get("sn")
+ LocationID = self.params_dict.get("LocationID")
+ test_num = self.params_dict.get("test_num")
+ pr_url = self.params_dict.get("pr_url")
+ logFilePath = self.logFilePath
+ logger.info(logFilePath)
+ r = logFilePath.rfind("\\")
+ report_path = logFilePath[:r]
+ logger.info(report_path)
+ scriptpath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))))
+ logger.info(scriptpath)
+ local_image_path = os.path.join(version_savepath)
+ logger.info(local_image_path)
+ loader_tool_path = os.path.join(scriptpath, "resource", "RK3568_tool", "upgrade_tool.exe")
+ logger.info(loader_tool_path)
+ mini_path = os.path.join(local_image_path, "mini_system_test", "L2_mini_system_test.py")
+ archive_path = os.path.join(version_savepath)
+ if not self.check_devices_mode():
+ check_devices_cmd = "hdc_std list targets"
+ f = send_times(check_devices_cmd)
+ logger.info(f)
+ if not f or "Empty" in f:
+ logger.error("No devices found,please check the device.")
+ return False
+ else:
+ logger.info("3568 board is connected.")
+ return self.check_devices_mode()
+ else:
+ # 涓嬭級閺″儚
+ upgrde_loader_cmd = "%s -s %s UL %s/MiniLoaderAll.bin -noreset" % (loader_tool_path, LocationID, local_image_path)
+ h = sendCmd(upgrde_loader_cmd)
+ logger.info(h)
+ if "Upgrade loader ok" not in h:
+ logger.error("Download MiniLoaderAll.bin Fail!")
+ return False
+ else:
+ logger.printLog("Download MiniLoaderAll.bin Success!")
+ # time.sleep(3)
+ write_gpt_cmd = "%s -s %s DI -p %s/parameter.txt" % (loader_tool_path, LocationID, local_image_path)
+ j = sendCmd(write_gpt_cmd)
+ logger.info(j)
+ if "Write gpt ok" not in j:
+ logger.error("Failed to execute the parameter.txt")
+ return False
+ else:
+ logger.printLog("Successfully executed parameter.txt.")
+ # time.sleep(5)
+ download_uboot_cmd = "%s -s %s DI -uboot %s/uboot.img %s/parameter.txt" % (
+ loader_tool_path, LocationID, local_image_path, local_image_path)
+ k = sendCmd(download_uboot_cmd)
+ logger.info(k)
+ if "Download image ok" not in k:
+ logger.error("Failed to download the uboot.image!")
+ if self.check_devices_mode():
+ return 98
+ return False
+ else:
+ logger.printLog("The uboot.image downloaded successfully!")
+ # time.sleep(5)
+ if not self.flash_version():
+ return False
+ reboot_devices_cmd = "%s -s %s RD" % (loader_tool_path, LocationID)
+ reboot_result = sendCmd(reboot_devices_cmd)
+ logger.info(reboot_result)
+ time.sleep(30)
+ try:
+ if upgrade_test_type != "mini_system_test":
+ if not start_cmd(sn):
+ if self.check_devices_mode():
+ return 98
+ return False
+ except Exception as t:
+ logger.info(t)
+ if self.check_devices_mode():
+ return 98
+ return False
+ time.sleep(10)
+ if "Reset Device OK" not in reboot_result:
+ logger.error("Failed to reboot the board!")
+ return False
+ else:
+ logger.info("Reboot successfully!")
+ logger.printLog("******涓嬭浇瀹屾垚锛屽崌绾ф垚鍔燂紝寮濮嬭繘琛屽啋鐑熸祴璇******")
+ if upgrade_test_type == "null":
+ return True
+ screenshot_path = os.path.join(local_image_path, "screenshot")
+ resource_path = os.path.join(screenshot_path, "resource")
+ logger.info(resource_path)
+ py_path = os.path.join(resource_path, "capturescreentest.py")
+ new_report_path = os.path.join(report_path, "result")
+ logger.info(new_report_path)
+ time_sleep = random.randint(1, 5)
+ time.sleep(time_sleep)
+ try:
+ if not os.path.exists(new_report_path):
+ os.mkdir(new_report_path)
+ except Exception as e:
+ logger.error(e)
+ return 98
+ if upgrade_test_type == "mini_system_test":
+ save_path = os.path.join(new_report_path)
+ if exec_cmd(mini_path, sn, save_path, archive_path) == 98:
+ return 98
+ return True
+ if not upgrade_test_type or upgrade_test_type == "smoke_test":
+ test_return = cmd_test(screenshot_path, py_path, new_report_path, resource_path, sn, test_num, pr_url)
+ if test_return == 1:
+ return True
+ if test_return == 98:
+ return 98
+ if test_return == 99:
+ return 99
+ else:
+ return False
+
+ @timeout(1000)
+ def flash_version(self):
+ partList = ["boot_linux", "system", "vendor", "userdata", "resource", "ramdisk", "chipset", "sys-prod", "chip-prod"]
+ for i in partList:
+ if not os.path.exists("%s/%s.img" % (local_image_path, i)):
+ logger.printLog("%s.img is not exist, ignore" % i)
+ continue
+ loadcmd = "%s -s %s DI -%s %s/%s.img" % (loader_tool_path, LocationID, i, local_image_path, i)
+ p = sendCmd(loadcmd)
+ logger.info(p)
+ # time.sleep(5)
+ if "Download image ok" not in p:
+ logger.info("try download %s again!" % i)
+ time.sleep(1)
+ second_cmd = "%s -s %s DI -%s %s/%s.img" % (loader_tool_path, LocationID, i, local_image_path, i)
+ f = sendCmd(second_cmd)
+ logger.info(f)
+ if "Download image ok" not in f:
+ logger.printLog("Failed to download the %s.img!" % i)
+ if self.check_devices_mode():
+ return 98
+ else:
+ return False
+ return True
+ else:
+ logger.printLog("The %s.img downloaded successfully!" % i)
+ return True
+
+ @timeout(120)
+ def check_devices_mode(self):
+ check_times = 0
+ while check_times < 5:
+ check_mode_cmd = "%s LD" % loader_tool_path
+ g = sendCmd(check_mode_cmd)
+ logger.info(g)
+ #time.sleep(40)
+ if "LocationID=%s Mode=Loader" % LocationID in g:
+ logger.info("3568 board has entered the Loader mode successfully!")
+ return True
+ else:
+ #if test_num != "2/2":
+ # hdc_kill()
+ os.system("hdc_std -t %s shell reboot loader" % sn)
+ time.sleep(5)
+ check_times += 1
+ logger.error("Failed to enter the loader mode!")
+ return False
+
+ @dec_stepmsg("download")
+ @timeout(360)
+ def download(self):
+ '''
+ #===================================================================================
+ # @Method: download(self)
+ # @Precondition: none
+ # @Func: 鏋勫缓涓嬭浇鍒版湰鍦扮殑璺緞锛屾墽琛岀浉搴斿寘鐨勪笅杞
+ # @PostStatus: none
+ # @eg: download()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global version_savepath, version_name
+ dir_path = CONSTANT.Path.getDirPath()
+ if self.params_dict.get("pbiid"):
+ version_path = self.params_dict.get("pbiid")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, str(self.params_dict.get("pbiid")) + "FASTBOOT"))
+ version_savepath = os.path.join(dir_path, self.params_dict.get("flash_type"), version_name)
+ else:
+ version_path = self.params_dict.get("upgrade_upgradeLocation")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, (self.params_dict.get("upgrade_upgradeLocation"))))
+ version_savepath = os.path.join(dir_path, version_name, "img")
+ # 鎵цimg涓嬭浇
+
+ if self.params_dict.get("isDownload") == "True":
+ logger.printLog("涓嶉渶瑕佸仛涓嬭浇锛岀洿鎺ヨ繑鍥")
+ return True
+
+ import hashlib
+ save_file_str = version_path.replace("/", "").replace("\\", "")
+ save_file_name = hashlib.sha1(save_file_str.encode("utf-8")).hexdigest()
+ logger.info("download hash string:%s, hash value:%s" % (save_file_str, save_file_name))
+ save_path_file = os.path.join(dir_path, "record", "%s%s" % (save_file_name, ".txt"))
+ if not self.excutedown(version_path, version_savepath, save_path_file, False):
+ logger.error("download img fail")
+ return 98
+
+ # 淇濆瓨鏈湴鐗堟湰璺緞缁檇evicetest鍘荤増鏈矾寰勪笅鍙栫敤渚
+ saveVersion(save_path_file, version_savepath)
+ return True
+
+ def excutedown(self, source_path, download_dir, suc_mark, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, suc_mark, is_file)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ # @eg: excutedown("xxxx", "D:\\local\\image", suc_mark, Flase)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ failed_mark = os.path.join(download_dir, failed_file)
+ lock_path = os.path.join(download_dir, lock_suffix)
+ file_lock = FileLock()
+
+ if isDownLoadSuccess(download_dir, suc_mark, failed_mark):
+ return True
+ try:
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s Downloading, please wait" % nowtime)
+ file_lock.lockFile(lock_path)
+ ret = ""
+ logger.info("Get lock. Start to ")
+ try:
+ if self.params_dict.get("bt_enable") and self.params_dict.get("bt_enable") == "True":
+ ret = downloadByBitComet(source_path, download_dir, os_method)
+ elif source_path.startswith('\\\\'):
+ ret = downloadByCopy(source_path, download_dir, is_file)
+ elif self.params_dict.get("pbiid"):
+ ret = downlaodByDownloadTool(version_savepath, self.params_dict.get("version_type"), "FASTBOOT",
+ self.params_dict.get("pbiid"))
+ elif source_path.startswith("http"):
+ ret = run_download(source_path, download_dir)
+ except Exception as f:
+ logger.error(f)
+ logger.info("涓嬭浇澶辫触锛岄棿闅20绉掞紝灏濊瘯鍐嶆涓嬭浇銆")
+ time.sleep(20)
+ ret = run_download(source_path, download_dir)
+ if source_path.endswith(".zip"):
+ zip_name = os.path.basename(source_path)
+ ret = extractZipFile(os.path.join(download_dir, zip_name), download_dir)
+ if source_path.endswith(".tar.gz") or (source_path.startswith("http") and ("file_id=" in source_path)):
+ if source_path.startswith("http") and ("file_id=" in source_path):
+ if source_path.endswith(".tar.gz"):
+ zip_name = source_path.split('=')[-1]
+ else:
+ zip_name = "out.tar.gz"
+ else:
+ zip_name = os.path.basename(source_path)
+ ret = unTarFile(os.path.join(download_dir, zip_name), download_dir)
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s download to %s end" % (nowtime, download_dir))
+
+ if not ret:
+ with open(failed_mark, "a+") as fp:
+ fp.write("")
+ return ret
+ except Exception as e:
+ logger.printLog(e)
+ #raise Exception(e)
+ finally:
+ file_lock.releaseFile()
+
+
+@timeout(30)
+def hdc_kill():
+ logger.info("kill the process")
+ os.system("hdc_std kill")
+ time.sleep(2)
+ logger.info("start the process")
+ os.system("hdc_std -l5 start")
+ # time.sleep(10)
+
+
+def sendCmd(mycmd):
+ result = "".join(os.popen(mycmd).readlines())
+ return result
+
+
+def send_times(mycmd):
+ times = 0
+ outcome = sendCmd(mycmd)
+ while times < 3:
+ if not outcome or "Empty" in outcome:
+ times += 1
+ time.sleep(3)
+ else:
+ time.sleep(3)
+ return outcome
+ return outcome
+
+
+@timeout(180)
+def start_cmd(sn):
+ try:
+ os.system("hdc_std -l5 start")
+ power_cmd = "hdc_std -t %s shell \"power-shell setmode 602\"" % sn
+ hilog_cmd = "hdc_std -t %s shell \"hilog -w start -l 400000000 -m none\"" % sn
+ logger.info(power_cmd)
+ logger.info(hilog_cmd)
+ power_result = sendCmd(power_cmd)
+ logger.info(power_result)
+ if not power_result:
+ return False
+ number = 0
+ while "Set Mode Success" not in power_result and number < 30:
+ time.sleep(4)
+ power_result = sendCmd(power_cmd)
+ logger.info(power_result)
+ number += 1
+ if number >= 20:
+ logger.error("Set mode failed")
+ return False
+ hilog_result = sendCmd(hilog_cmd)
+ logger.info(hilog_result)
+ return True
+ except Exception as e:
+ logger.error(e)
+ return False
+
+
+@timeout(3600)
+def cmd_test(screenshot_path, py_path, new_report_path, resource_path, sn, test_num, pr_url):
+ save_screenshot_path = os.path.join(new_report_path, "screenshot_result")
+ logger.info(save_screenshot_path)
+ time_sleep = random.randint(1, 5)
+ time.sleep(time_sleep)
+ try:
+ if not os.path.exists(save_screenshot_path):
+ os.mkdir(save_screenshot_path)
+ logger.info(save_screenshot_path)
+ base_screenshot_path = os.path.join(new_report_path, "screenshot_base")
+ if not os.path.exists(base_screenshot_path):
+ os.mkdir(base_screenshot_path)
+ logger.info(base_screenshot_path)
+ except Exception as e:
+ logger.error(e)
+ return 98
+ config_path = os.path.join(screenshot_path, "resource", "app_capture_screen_test_config.json")
+ py_cmd = "python %s --config %s --anwser_path %s --save_path %s --device_num %s --test_num %s --tools_path %s --pr_url %s" \
+ % (py_path, config_path, resource_path, save_screenshot_path, sn, test_num, screenshot_path, pr_url)
+ result = outCmd(py_cmd, save_screenshot_path, base_screenshot_path, resource_path)
+ if result == 1:
+ return True
+ if result == 98:
+ return 98
+ if result == 99:
+ return 99
+ else:
+ return False
+
+
+@timeout(3600)
+def outCmd(cmd, save_screenshot_path, base_screenshot_path, resource_path):
+ logger.info("cmd is: %s" % cmd)
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="gbk")
+ curline = p.stdout.readline()
+ list_png_name = []
+ try:
+ while "End of check" not in curline:
+ curline = p.stdout.readline()
+ logger.info(curline)
+ if "abnarmal" in curline:
+ png_name = curline.split(" ")[3].split(".")[0]
+ list_png_name.append(png_name)
+ if "SmokeTest find some fatal problems" in curline:
+ logger.error("SmokeTest find some fatal problems!")
+ return 99
+ except Exception as e:
+ logger.error(e)
+ logger.error("execute smoke_test.py failed!")
+ return 99
+ l = list(set(list_png_name))
+ if l:
+ logger.error(l)
+ try:
+ for i in l:
+ result = os.path.join(resource_path, "%s.png" % i)
+ base = os.path.join(base_screenshot_path, "%s.png" % i)
+ shutil.copy(result, base)
+ except Exception as t:
+ logger.info(t)
+ p.wait()
+ logger.info("p.returncode %s" % p.returncode)
+ if p.returncode == 0:
+ logger.info("screenshot check is ok!")
+ return True
+ if p.returncode == 101:
+ logger.error("device disconnection, please check the device!")
+ return False
+ logger.error("screenshot test failed, check the %s" % save_screenshot_path)
+ return 98
+
+
+@timeout(1000)
+def exec_cmd(mini_path, sn, save_path, archive_path):
+ cmd = "python %s --device_num %s --save_path %s --archive_path %s" % (mini_path, sn, save_path, archive_path)
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="gbk")
+ curline = p.stdout.readline()
+ try:
+ while "End of check" not in curline:
+ curline = p.stdout.readline()
+ logger.info(curline)
+ except Exception as e:
+ logger.error(e)
+ p.wait()
+ logger.info("p.returncode %s" % p.returncode)
+ if p.returncode == 0:
+ logger.info("mini_system_test is ok!")
+ return True
+ logger.error("mini_system_test failed!")
+ return 98
\ No newline at end of file
diff --git a/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_RK3568_app.py b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_RK3568_app.py
new file mode 100644
index 0000000000000000000000000000000000000000..ecf6aa178bdf85d7485a65c1e08dd879e96ce2dd
--- /dev/null
+++ b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_RK3568_app.py
@@ -0,0 +1,529 @@
+# -*- coding:utf-8 -*-
+import uuid
+import sys
+import subprocess
+import os
+import time
+import re
+import shutil
+import random
+
+
+from core.base import BaseApp, dec_stepmsg
+from util.file_locker import FileLock
+from util.log_info import logger
+from util.time_info import get_now_time_str_info, get_now_time_info, Timeout, timeout
+from aw.Download.Download import *
+from aw.Common.Constant import CONSTANT
+from aw.Common.Common import getFileName
+from aw.ExtractFile.ExtractFile import *
+from aw.Common.Common import getHostIp, copyFile, copyDirectory
+
+lock_suffix = CONSTANT.File.LOCK_SUFFIX
+suc_file = CONSTANT.File.SUC_FILE
+failed_file = CONSTANT.File.FAILED_FILE
+REBOOT_TIMEOUT = 20000000
+
+
+class liteOsUpgrade_RK3568(BaseApp):
+ '''
+ @author: cwx1076044
+ '''
+
+ def __init__(self, param_file):
+ super().__init__(param_file)
+ self.param_List = ["upgrade_upgradeLocation", "sn"]
+
+ @dec_stepmsg("hongmeng RK3568 flash")
+ def excute(self):
+ '''
+ #===================================================================================
+ # @Method: excute(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鎵ц鍏ュ彛
+ # @PostStatus: none
+ # @eg: excute()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ step_index = self.params_dict.get("step_list").index("liteOsUpgrade_RK3568_app")
+
+ # # 鎵ц涓嬭浇
+ # try:
+ # if not self.download():
+ # CONSTANT.ENVERRMESSAGE = "image download fail"
+ # logger.printLog(CONSTANT.ENVERRMESSAGE)
+ # return 98
+ # except Exception as e:
+ # logger.error(e)
+ # #raise e
+ # return 98
+
+ # 鎵ц鍗囩骇
+ try:
+ return_code = self.upgrade()
+ if not return_code:
+ CONSTANT.ENVERRMESSAGE = "board upgrade fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ if return_code == 98:
+ return 98
+ if return_code == 99:
+ return 99
+ return True
+ except Exception as e:
+ logger.error(e)
+ raise e
+
+
+ @dec_stepmsg("upgrade")
+ @timeout(3600)
+ def upgrade(self):
+ '''
+ #===================================================================================
+ # @Method: upgrade(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鐩稿叧涓氬姟閫昏緫
+ # @PostStatus: none
+ # @eg: upgrade()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global local_image_path, loader_tool_path, sn, LocationID ,test_num
+ version_savepath = self.params_dict.get("img_path")
+ upgrade_test_type = self.params_dict.get("UpgradeTestType")
+ sn = self.params_dict.get("sn")
+ LocationID = self.params_dict.get("LocationID")
+ test_num = self.params_dict.get("test_num")
+ pr_url = self.params_dict.get("pr_url")
+ logFilePath = self.logFilePath
+ logger.info(logFilePath)
+ r = logFilePath.rfind("\\")
+ report_path = logFilePath[:r]
+ logger.info(report_path)
+ scriptpath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))))
+ logger.info(scriptpath)
+ local_image_path = os.path.join(version_savepath)
+ logger.info(local_image_path)
+ loader_tool_path = os.path.join(scriptpath, "resource", "RK3568_tool", "upgrade_tool.exe")
+ logger.info(loader_tool_path)
+ mini_path = os.path.join(local_image_path, "mini_system_test", "L2_mini_system_test.py")
+ archive_path = os.path.join(version_savepath)
+ if not self.check_devices_mode():
+ check_devices_cmd = "hdc_std list targets"
+ f = send_times(check_devices_cmd)
+ logger.info(f)
+ if not f or "Empty" in f:
+ logger.error("No devices found,please check the device.")
+ return False
+ else:
+ logger.info("3568 board is connected.")
+ return self.check_devices_mode()
+ else:
+ # 涓嬭級閺″儚
+ upgrde_loader_cmd = "%s -s %s UL %s/MiniLoaderAll.bin -noreset" % (loader_tool_path, LocationID, local_image_path)
+ h = sendCmd(upgrde_loader_cmd)
+ logger.info(h)
+ if "Upgrade loader ok" not in h:
+ logger.error("Download MiniLoaderAll.bin Fail!")
+ return False
+ else:
+ logger.printLog("Download MiniLoaderAll.bin Success!")
+ # time.sleep(3)
+ write_gpt_cmd = "%s -s %s DI -p %s/parameter.txt" % (loader_tool_path, LocationID, local_image_path)
+ j = sendCmd(write_gpt_cmd)
+ logger.info(j)
+ if "Write gpt ok" not in j:
+ logger.error("Failed to execute the parameter.txt")
+ return False
+ else:
+ logger.printLog("Successfully executed parameter.txt.")
+ # time.sleep(5)
+ download_uboot_cmd = "%s -s %s DI -uboot %s/uboot.img %s/parameter.txt" % (
+ loader_tool_path, LocationID, local_image_path, local_image_path)
+ k = sendCmd(download_uboot_cmd)
+ logger.info(k)
+ if "Download image ok" not in k:
+ logger.error("Failed to download the uboot.image!")
+ if self.check_devices_mode():
+ return 98
+ return False
+ else:
+ logger.printLog("The uboot.image downloaded successfully!")
+ # time.sleep(5)
+ if not self.flash_version():
+ return False
+ reboot_devices_cmd = "%s -s %s RD" % (loader_tool_path, LocationID)
+ reboot_result = sendCmd(reboot_devices_cmd)
+ logger.info(reboot_result)
+ time.sleep(30)
+ try:
+ if upgrade_test_type != "mini_system_test":
+ if not start_cmd(sn):
+ if self.check_devices_mode():
+ return 98
+ return False
+ except Exception as t:
+ logger.info(t)
+ if self.check_devices_mode():
+ return 98
+ return False
+ time.sleep(10)
+ if "Reset Device OK" not in reboot_result:
+ logger.error("Failed to reboot the board!")
+ return False
+ else:
+ logger.info("Reboot successfully!")
+ logger.printLog("******涓嬭浇瀹屾垚锛屽崌绾ф垚鍔燂紝寮濮嬭繘琛屽啋鐑熸祴璇******")
+ if upgrade_test_type == "null":
+ return True
+ screenshot_path = os.path.join(local_image_path, "screenshot")
+ resource_path = os.path.join(screenshot_path, "resource")
+ logger.info(resource_path)
+ py_path = os.path.join(resource_path, "capturescreentest.py")
+ new_report_path = os.path.join(report_path, "result")
+ logger.info(new_report_path)
+ time_sleep = random.randint(1, 5)
+ time.sleep(time_sleep)
+ try:
+ if not os.path.exists(new_report_path):
+ os.mkdir(new_report_path)
+ except Exception as e:
+ logger.error(e)
+ return 98
+ if upgrade_test_type == "mini_system_test":
+ save_path = os.path.join(new_report_path)
+ if exec_cmd(mini_path, sn, save_path, archive_path) == 98:
+ return 98
+ return True
+ if not upgrade_test_type or upgrade_test_type == "smoke_test":
+ test_return = cmd_test(screenshot_path, py_path, new_report_path, resource_path, sn, test_num, pr_url)
+ if test_return == 1:
+ return True
+ if test_return == 98:
+ return 98
+ if test_return == 99:
+ return 99
+ else:
+ return False
+
+ @timeout(1000)
+ def flash_version(self):
+ partList = ["boot_linux", "system", "vendor", "userdata", "resource", "ramdisk", "chipset", "sys-prod", "chip-prod"]
+ for i in partList:
+ if not os.path.exists("%s/%s.img" % (local_image_path, i)):
+ logger.printLog("%s.img is not exist, ignore" % i)
+ continue
+ loadcmd = "%s -s %s DI -%s %s/%s.img" % (loader_tool_path, LocationID, i, local_image_path, i)
+ p = sendCmd(loadcmd)
+ logger.info(p)
+ # time.sleep(5)
+ if "Download image ok" not in p:
+ logger.info("try download %s again!" % i)
+ time.sleep(1)
+ second_cmd = "%s -s %s DI -%s %s/%s.img" % (loader_tool_path, LocationID, i, local_image_path, i)
+ f = sendCmd(second_cmd)
+ logger.info(f)
+ if "Download image ok" not in f:
+ logger.printLog("Failed to download the %s.img!" % i)
+ if self.check_devices_mode():
+ return 98
+ else:
+ return False
+ return True
+ else:
+ logger.printLog("The %s.img downloaded successfully!" % i)
+ return True
+
+ @timeout(120)
+ def check_devices_mode(self):
+ check_times = 0
+ while check_times < 5:
+ check_mode_cmd = "%s LD" % loader_tool_path
+ g = sendCmd(check_mode_cmd)
+ logger.info(g)
+ #time.sleep(40)
+ if "LocationID=%s Mode=Loader" % LocationID in g:
+ logger.info("3568 board has entered the Loader mode successfully!")
+ return True
+ else:
+ #if test_num != "2/2":
+ # hdc_kill()
+ os.system("hdc_std -t %s shell reboot loader" % sn)
+ time.sleep(5)
+ check_times += 1
+ logger.error("Failed to enter the loader mode!")
+ return False
+
+ # @dec_stepmsg("download")
+ # @timeout(360)
+ # def download(self):
+ # '''
+ # #===================================================================================
+ # # @Method: download(self)
+ # # @Precondition: none
+ # # @Func: 鏋勫缓涓嬭浇鍒版湰鍦扮殑璺緞锛屾墽琛岀浉搴斿寘鐨勪笅杞
+ # # @PostStatus: none
+ # # @eg: download()
+ # # @return: True or Flase
+ # #===================================================================================
+ # '''
+ # global version_savepath, version_name
+ # dir_path = CONSTANT.Path.getDirPath()
+ # if self.params_dict.get("pbiid"):
+ # version_path = self.params_dict.get("pbiid")
+ # version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, str(self.params_dict.get("pbiid")) + "FASTBOOT"))
+ # version_savepath = os.path.join(dir_path, self.params_dict.get("flash_type"), version_name)
+ # else:
+ # version_path = self.params_dict.get("upgrade_upgradeLocation")
+ # version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, (self.params_dict.get("upgrade_upgradeLocation"))))
+ # version_savepath = os.path.join(dir_path, version_name, "img")
+ # # 鎵цimg涓嬭浇
+ #
+ # if self.params_dict.get("isDownload") == "True":
+ # logger.printLog("涓嶉渶瑕佸仛涓嬭浇锛岀洿鎺ヨ繑鍥")
+ # return True
+ #
+ # import hashlib
+ # save_file_str = version_path.replace("/", "").replace("\\", "")
+ # save_file_name = hashlib.sha1(save_file_str.encode("utf-8")).hexdigest()
+ # logger.info("download hash string:%s, hash value:%s" % (save_file_str, save_file_name))
+ # save_path_file = os.path.join(dir_path, "record", "%s%s" % (save_file_name, ".txt"))
+ # logger.info(version_savepath)
+ # logger.info(save_path_file)
+ # t = version_savepath[:-4]
+ # logger.info(t)
+ # if not self.excutedown(version_path, version_savepath, save_path_file, False):
+ # logger.info("download again!")
+ # try:
+ # if os.path.exists(t):
+ # shutil.rmtree(t)
+ # logger.info("remove dir succeed")
+ # if os.path.exists(save_path_file):
+ # logger.info("remove file succeed")
+ # os.remove(save_path_file)
+ # except Exception as p:
+ # logger.error(p)
+ # raise Exception(p)
+ # time.sleep(15)
+ # if not self.excutedown(version_path, version_savepath, save_path_file, False):
+ # logger.error("download img fail")
+ # return False
+ #
+ # # 淇濆瓨鏈湴鐗堟湰璺緞缁檇evicetest鍘荤増鏈矾寰勪笅鍙栫敤渚
+ # saveVersion(save_path_file, version_savepath)
+ # return True
+ #
+ # def excutedown(self, source_path, download_dir, suc_mark, is_file):
+ # '''
+ # #===================================================================================
+ # # @Method: excutedown(source_path, download_dir, suc_mark, is_file)
+ # # @Precondition: none
+ # # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # # @PostStatus: none
+ # # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # # is_file:鏄惁鏄枃浠
+ # # @eg: excutedown("xxxx", "D:\\local\\image", suc_mark, Flase)
+ # # @return: True or Flase
+ # #===================================================================================
+ # '''
+ # failed_mark = os.path.join(download_dir, failed_file)
+ # lock_path = os.path.join(download_dir, lock_suffix)
+ # file_lock = FileLock()
+ #
+ # if isDownLoadSuccess(download_dir, suc_mark, failed_mark):
+ # return True
+ # try:
+ # nowtime = get_now_time_str_info()
+ # logger.printLog("%s Downloading, please wait" % nowtime)
+ # file_lock.lockFile(lock_path)
+ # ret = ""
+ # logger.info("Get lock. Start to ")
+ # try:
+ # if self.params_dict.get("bt_enable") and self.params_dict.get("bt_enable") == "True":
+ # ret = downloadByBitComet(source_path, download_dir, os_method)
+ # elif source_path.startswith('\\\\'):
+ # ret = downloadByCopy(source_path, download_dir, is_file)
+ # elif self.params_dict.get("pbiid"):
+ # ret = downlaodByDownloadTool(version_savepath, self.params_dict.get("version_type"), "FASTBOOT",
+ # self.params_dict.get("pbiid"))
+ # elif source_path.startswith("http"):
+ # ret = run_download(source_path, download_dir)
+ # except Exception as f:
+ # logger.error(f)
+ #
+ # if source_path.endswith(".zip"):
+ # zip_name = os.path.basename(source_path)
+ # ret = extractZipFile(os.path.join(download_dir, zip_name), download_dir)
+ # if source_path.endswith(".tar.gz") or (source_path.startswith("http") and ("file_id=" in source_path)):
+ # if source_path.startswith("http") and ("file_id=" in source_path):
+ # if source_path.endswith(".tar.gz"):
+ # zip_name = source_path.split('=')[-1]
+ # else:
+ # zip_name = "out.tar.gz"
+ # else:
+ # zip_name = os.path.basename(source_path)
+ # ret = unTarFile(os.path.join(download_dir, zip_name), download_dir)
+ # nowtime = get_now_time_str_info()
+ # logger.printLog("%s download to %s end" % (nowtime, download_dir))
+ #
+ # if not ret:
+ # with open(failed_mark, "a+") as fp:
+ # fp.write("")
+ # return ret
+ # except Exception as e:
+ # logger.printLog(e)
+ # #raise Exception(e)
+ # finally:
+ # file_lock.releaseFile()
+
+
+@timeout(30)
+def hdc_kill():
+ logger.info("kill the process")
+ os.system("hdc_std kill")
+ time.sleep(2)
+ logger.info("start the process")
+ os.system("hdc_std -l5 start")
+ # time.sleep(10)
+
+
+def sendCmd(mycmd):
+ result = "".join(os.popen(mycmd).readlines())
+ return result
+
+
+def send_times(mycmd):
+ times = 0
+ outcome = sendCmd(mycmd)
+ while times < 3:
+ if not outcome or "Empty" in outcome:
+ times += 1
+ time.sleep(3)
+ else:
+ time.sleep(3)
+ return outcome
+ return outcome
+
+
+@timeout(180)
+def start_cmd(sn):
+ try:
+ os.system("hdc_std -l5 start")
+ power_cmd = "hdc_std -t %s shell \"power-shell setmode 602\"" % sn
+ hilog_cmd = "hdc_std -t %s shell \"hilog -w start -l 400000000 -m none\"" % sn
+ logger.info(power_cmd)
+ logger.info(hilog_cmd)
+ power_result = sendCmd(power_cmd)
+ logger.info(power_result)
+ if not power_result:
+ return False
+ number = 0
+ while "Set Mode Success" not in power_result and number < 30:
+ time.sleep(4)
+ power_result = sendCmd(power_cmd)
+ logger.info(power_result)
+ number += 1
+ if number >= 20:
+ logger.error("Set mode failed")
+ return False
+ hilog_result = sendCmd(hilog_cmd)
+ logger.info(hilog_result)
+ return True
+ except Exception as e:
+ logger.error(e)
+ return False
+
+
+@timeout(3600)
+def cmd_test(screenshot_path, py_path, new_report_path, resource_path, sn, test_num, pr_url):
+ save_screenshot_path = os.path.join(new_report_path, "screenshot_result")
+ logger.info(save_screenshot_path)
+ time_sleep = random.randint(1, 5)
+ time.sleep(time_sleep)
+ try:
+ if not os.path.exists(save_screenshot_path):
+ os.mkdir(save_screenshot_path)
+ logger.info(save_screenshot_path)
+ base_screenshot_path = os.path.join(new_report_path, "screenshot_base")
+ if not os.path.exists(base_screenshot_path):
+ os.mkdir(base_screenshot_path)
+ logger.info(base_screenshot_path)
+ except Exception as e:
+ logger.error(e)
+ return 98
+ config_path = os.path.join(screenshot_path, "resource", "app_capture_screen_test_config.json")
+ py_cmd = "python %s --config %s --anwser_path %s --save_path %s --device_num %s --test_num %s --tools_path %s --pr_url %s" \
+ % (py_path, config_path, resource_path, save_screenshot_path, sn, test_num, screenshot_path, pr_url)
+ result = outCmd(py_cmd, save_screenshot_path, base_screenshot_path, resource_path)
+ if result == 1:
+ return True
+ if result == 98:
+ return 98
+ if result == 99:
+ return 99
+ else:
+ return False
+
+
+@timeout(3600)
+def outCmd(cmd, save_screenshot_path, base_screenshot_path, resource_path):
+ logger.info("cmd is: %s" % cmd)
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="gbk")
+ curline = p.stdout.readline()
+ list_png_name = []
+ try:
+ while "End of check" not in curline:
+ curline = p.stdout.readline()
+ logger.info(curline)
+ if "abnarmal" in curline:
+ png_name = curline.split(" ")[3].split(".")[0]
+ list_png_name.append(png_name)
+ if "SmokeTest find some fatal problems" in curline:
+ logger.error("SmokeTest find some fatal problems!")
+ return 99
+ except Exception as e:
+ logger.error(e)
+ logger.error("execute smoke_test.py failed!")
+ return 99
+ l = list(set(list_png_name))
+ if l:
+ logger.error(l)
+ try:
+ for i in l:
+ result = os.path.join(resource_path, "%s.png" % i)
+ base = os.path.join(base_screenshot_path, "%s.png" % i)
+ shutil.copy(result, base)
+ except Exception as t:
+ logger.info(t)
+ p.wait()
+ logger.info("p.returncode %s" % p.returncode)
+ if p.returncode == 0:
+ logger.info("screenshot check is ok!")
+ return True
+ if p.returncode == 101:
+ logger.error("device disconnection, please check the device!")
+ return False
+ logger.error("screenshot test failed, check the %s" % save_screenshot_path)
+ return 98
+
+
+@timeout(1000)
+def exec_cmd(mini_path, sn, save_path, archive_path):
+ cmd = "python %s --device_num %s --save_path %s --archive_path %s" % (mini_path, sn, save_path, archive_path)
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="gbk")
+ curline = p.stdout.readline()
+ try:
+ while "End of check" not in curline:
+ curline = p.stdout.readline()
+ logger.info(curline)
+ except Exception as e:
+ logger.error(e)
+ p.wait()
+ logger.info("p.returncode %s" % p.returncode)
+ if p.returncode == 0:
+ logger.info("mini_system_test is ok!")
+ return True
+ logger.error("mini_system_test failed!")
+ return 98
\ No newline at end of file
diff --git a/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_RK3568_app_old.py b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_RK3568_app_old.py
new file mode 100644
index 0000000000000000000000000000000000000000..1e91d2e60d4ad324761e171d6a33d91e7ab30f81
--- /dev/null
+++ b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_RK3568_app_old.py
@@ -0,0 +1,506 @@
+# -*- coding:utf-8 -*-
+import uuid
+import sys
+import subprocess
+import os
+import time
+import re
+import shutil
+import random
+
+
+from core.base import BaseApp, dec_stepmsg
+from util.file_locker import FileLock
+from util.log_info import logger
+from util.time_info import get_now_time_str_info, get_now_time_info, Timeout, timeout
+from aw.Download.Download import *
+from aw.Common.Constant import CONSTANT
+from aw.Common.Common import getFileName
+from aw.ExtractFile.ExtractFile import *
+from aw.Common.Common import getHostIp, copyFile, copyDirectory
+
+lock_suffix = CONSTANT.File.LOCK_SUFFIX
+suc_file = CONSTANT.File.SUC_FILE
+failed_file = CONSTANT.File.FAILED_FILE
+REBOOT_TIMEOUT = 20000000
+
+
+class liteOsUpgrade_RK3568(BaseApp):
+ '''
+ @author: cwx1076044
+ '''
+
+ def __init__(self, param_file):
+ super().__init__(param_file)
+ self.param_List = ["upgrade_upgradeLocation", "sn"]
+
+ @dec_stepmsg("hongmeng RK3568 flash")
+ def excute(self):
+ '''
+ #===================================================================================
+ # @Method: excute(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鎵ц鍏ュ彛
+ # @PostStatus: none
+ # @eg: excute()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ step_index = self.params_dict.get("step_list").index("liteOsUpgrade_RK3568_app")
+
+ # 鎵ц涓嬭浇
+ try:
+ if not self.download():
+ CONSTANT.ENVERRMESSAGE = "image download fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ except Exception as e:
+ logger.error(e)
+ raise e
+
+ # 鎵ц鍗囩骇
+ try:
+ return_code = self.upgrade()
+ if not return_code:
+ CONSTANT.ENVERRMESSAGE = "board upgrade fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ if return_code == 98:
+ return 98
+ if return_code == 99:
+ return 99
+ return True
+ except Exception as e:
+ logger.error(e)
+ raise e
+
+ @dec_stepmsg("upgrade")
+ @timeout(3600)
+ def upgrade(self):
+ '''
+ #===================================================================================
+ # @Method: upgrade(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鐩稿叧涓氬姟閫昏緫
+ # @PostStatus: none
+ # @eg: upgrade()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global local_image_path, loader_tool_path, sn, LocationID ,test_num
+ upgrade_test_type = self.params_dict.get("UpgradeTestType")
+ sn = self.params_dict.get("sn")
+ LocationID = self.params_dict.get("LocationID")
+ test_num = self.params_dict.get("test_num")
+ pr_url = self.params_dict.get("pr_url")
+ logFilePath = self.logFilePath
+ logger.info(logFilePath)
+ r = logFilePath.rfind("\\")
+ report_path = logFilePath[:r]
+ logger.info(report_path)
+ scriptpath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))))
+ logger.info(scriptpath)
+ local_image_path = os.path.join(version_savepath)
+ logger.info(local_image_path)
+ loader_tool_path = os.path.join(scriptpath, "resource", "RK3568_tool", "upgrade_tool.exe")
+ logger.info(loader_tool_path)
+ mini_path = os.path.join(local_image_path, "mini_system_test", "L2_mini_system_test.py")
+ archive_path = os.path.join(version_savepath)
+ if not self.check_devices_mode():
+ check_devices_cmd = "hdc_std list targets"
+ f = send_times(check_devices_cmd)
+ logger.info(f)
+ if not f or "Empty" in f:
+ logger.error("No devices found,please check the device.")
+ return False
+ else:
+ logger.info("3568 board is connected.")
+ return self.check_devices_mode()
+ else:
+ # 涓嬭級閺″儚
+ upgrde_loader_cmd = "%s -s %s UL %s/MiniLoaderAll.bin -noreset" % (loader_tool_path, LocationID, local_image_path)
+ h = sendCmd(upgrde_loader_cmd)
+ logger.info(h)
+ if "Upgrade loader ok" not in h:
+ logger.error("Download MiniLoaderAll.bin Fail!")
+ return False
+ else:
+ logger.printLog("Download MiniLoaderAll.bin Success!")
+ # time.sleep(3)
+ write_gpt_cmd = "%s -s %s DI -p %s/parameter.txt" % (loader_tool_path, LocationID, local_image_path)
+ j = sendCmd(write_gpt_cmd)
+ logger.info(j)
+ if "Write gpt ok" not in j:
+ logger.error("Failed to execute the parameter.txt")
+ return False
+ else:
+ logger.printLog("Successfully executed parameter.txt.")
+ # time.sleep(5)
+ download_uboot_cmd = "%s -s %s DI -uboot %s/uboot.img %s/parameter.txt" % (
+ loader_tool_path, LocationID, local_image_path, local_image_path)
+ k = sendCmd(download_uboot_cmd)
+ logger.info(k)
+ if "Download image ok" not in k:
+ logger.error("Failed to download the uboot.image!")
+ if self.check_devices_mode():
+ return 98
+ return False
+ else:
+ logger.printLog("The uboot.image downloaded successfully!")
+ # time.sleep(5)
+ if not self.flash_version():
+ return False
+ reboot_devices_cmd = "%s -s %s RD" % (loader_tool_path, LocationID)
+ reboot_result = sendCmd(reboot_devices_cmd)
+ logger.info(reboot_result)
+ time.sleep(30)
+ try:
+ if upgrade_test_type != "mini_system_test":
+ if not start_cmd(sn):
+ if self.check_devices_mode():
+ return 98
+ return False
+ except Exception as t:
+ logger.info(t)
+ if self.check_devices_mode():
+ return 98
+ return False
+ time.sleep(10)
+ if "Reset Device OK" not in reboot_result:
+ logger.error("Failed to reboot the board!")
+ return False
+ else:
+ logger.info("Reboot successfully!")
+ logger.printLog("******涓嬭浇瀹屾垚锛屽崌绾ф垚鍔燂紝寮濮嬭繘琛屽啋鐑熸祴璇******")
+ if upgrade_test_type == "null":
+ return True
+ screenshot_path = os.path.join(local_image_path, "screenshot")
+ resource_path = os.path.join(screenshot_path, "resource")
+ logger.info(resource_path)
+ py_path = os.path.join(resource_path, "capturescreentest.py")
+ new_report_path = os.path.join(report_path, "result")
+ logger.info(new_report_path)
+ time_sleep = random.randint(1, 5)
+ time.sleep(time_sleep)
+ try:
+ if not os.path.exists(new_report_path):
+ os.mkdir(new_report_path)
+ except Exception as e:
+ logger.error(e)
+ return 98
+ if upgrade_test_type == "mini_system_test":
+ save_path = os.path.join(new_report_path)
+ if exec_cmd(mini_path, sn, save_path, archive_path) == 98:
+ return 98
+ return True
+ if not upgrade_test_type or upgrade_test_type == "smoke_test":
+ test_return = cmd_test(screenshot_path, py_path, new_report_path, resource_path, sn, test_num, pr_url)
+ if test_return == 1:
+ return True
+ if test_return == 98:
+ return 98
+ if test_return == 99:
+ return 99
+ else:
+ return False
+
+ @timeout(1000)
+ def flash_version(self):
+ partList = ["boot_linux", "system", "vendor", "userdata", "resource", "ramdisk", "chipset", "sys-prod", "chip-prod"]
+ for i in partList:
+ if not os.path.exists("%s/%s.img" % (local_image_path, i)):
+ logger.printLog("%s.img is not exist, ignore" % i)
+ continue
+ loadcmd = "%s -s %s DI -%s %s/%s.img" % (loader_tool_path, LocationID, i, local_image_path, i)
+ p = sendCmd(loadcmd)
+ logger.info(p)
+ # time.sleep(5)
+ if "Download image ok" not in p:
+ logger.info("try download %s again!" % i)
+ time.sleep(1)
+ second_cmd = "%s -s %s DI -%s %s/%s.img" % (loader_tool_path, LocationID, i, local_image_path, i)
+ f = sendCmd(second_cmd)
+ logger.info(f)
+ if "Download image ok" not in f:
+ logger.printLog("Failed to download the %s.img!" % i)
+ if self.check_devices_mode():
+ return 98
+ else:
+ return False
+ return True
+ else:
+ logger.printLog("The %s.img downloaded successfully!" % i)
+ return True
+
+ @timeout(120)
+ def check_devices_mode(self):
+ check_times = 0
+ while check_times < 5:
+ check_mode_cmd = "%s LD" % loader_tool_path
+ g = sendCmd(check_mode_cmd)
+ logger.info(g)
+ #time.sleep(40)
+ if "LocationID=%s Mode=Loader" % LocationID in g:
+ logger.info("3568 board has entered the Loader mode successfully!")
+ return True
+ else:
+ #if test_num != "2/2":
+ # hdc_kill()
+ os.system("hdc_std -t %s shell reboot loader" % sn)
+ time.sleep(5)
+ check_times += 1
+ logger.error("Failed to enter the loader mode!")
+ return False
+
+ @dec_stepmsg("download")
+ @timeout(1800)
+ def download(self):
+ '''
+ #===================================================================================
+ # @Method: download(self)
+ # @Precondition: none
+ # @Func: 鏋勫缓涓嬭浇鍒版湰鍦扮殑璺緞锛屾墽琛岀浉搴斿寘鐨勪笅杞
+ # @PostStatus: none
+ # @eg: download()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global version_savepath, version_name
+ dir_path = CONSTANT.Path.getDirPath()
+ if self.params_dict.get("pbiid"):
+ version_path = self.params_dict.get("pbiid")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, str(self.params_dict.get("pbiid")) + "FASTBOOT"))
+ version_savepath = os.path.join(dir_path, self.params_dict.get("flash_type"), version_name)
+ else:
+ version_path = self.params_dict.get("upgrade_upgradeLocation")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, (self.params_dict.get("upgrade_upgradeLocation"))))
+ version_savepath = os.path.join(dir_path, version_name, "img")
+ # 鎵цimg涓嬭浇
+
+ if self.params_dict.get("isDownload") == "True":
+ logger.printLog("涓嶉渶瑕佸仛涓嬭浇锛岀洿鎺ヨ繑鍥")
+ return True
+
+ import hashlib
+ save_file_str = version_path.replace("/", "").replace("\\", "")
+ save_file_name = hashlib.sha1(save_file_str.encode("utf-8")).hexdigest()
+ logger.info("download hash string:%s, hash value:%s" % (save_file_str, save_file_name))
+ save_path_file = os.path.join(dir_path, "record", "%s%s" % (save_file_name, ".txt"))
+ if not self.excutedown(version_path, version_savepath, save_path_file, False):
+ logger.error("download img fail")
+ return False
+
+ # 淇濆瓨鏈湴鐗堟湰璺緞缁檇evicetest鍘荤増鏈矾寰勪笅鍙栫敤渚
+ saveVersion(save_path_file, version_savepath)
+ return True
+
+ def excutedown(self, source_path, download_dir, suc_mark, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, suc_mark, is_file)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ # @eg: excutedown("xxxx", "D:\\local\\image", suc_mark, Flase)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ failed_mark = os.path.join(download_dir, failed_file)
+ lock_path = os.path.join(download_dir, lock_suffix)
+ file_lock = FileLock()
+
+ if isDownLoadSuccess(download_dir, suc_mark, failed_mark):
+ return True
+ try:
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s Downloading, please wait" % nowtime)
+ file_lock.lockFile(lock_path)
+ ret = ""
+ logger.info("Get lock. Start to ")
+ if self.params_dict.get("bt_enable") and self.params_dict.get("bt_enable") == "True":
+ ret = downloadByBitComet(source_path, download_dir, os_method)
+ elif source_path.startswith('\\\\'):
+ ret = downloadByCopy(source_path, download_dir, is_file)
+ elif self.params_dict.get("pbiid"):
+ ret = downlaodByDownloadTool(version_savepath, self.params_dict.get("version_type"), "FASTBOOT",
+ self.params_dict.get("pbiid"))
+ elif source_path.startswith("http"):
+ ret = run_download(source_path, download_dir)
+
+ if source_path.endswith(".zip"):
+ zip_name = os.path.basename(source_path)
+ ret = extractZipFile(os.path.join(download_dir, zip_name), download_dir)
+ if source_path.endswith(".tar.gz") or (source_path.startswith("http") and ("file_id=" in source_path)):
+ if source_path.startswith("http") and ("file_id=" in source_path):
+ if source_path.endswith(".tar.gz"):
+ zip_name = source_path.split('=')[-1]
+ else:
+ zip_name = "out.tar.gz"
+ else:
+ zip_name = os.path.basename(source_path)
+ ret = unTarFile(os.path.join(download_dir, zip_name), download_dir)
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s download to %s end" % (nowtime, download_dir))
+
+ if not ret:
+ with open(failed_mark, "a+") as fp:
+ fp.write("")
+ return ret
+ except Exception as e:
+ logger.printLog(e)
+ raise Exception(e)
+ finally:
+ file_lock.releaseFile()
+
+
+@timeout(30)
+def hdc_kill():
+ logger.info("kill the process")
+ os.system("hdc_std kill")
+ time.sleep(2)
+ logger.info("start the process")
+ os.system("hdc_std -l5 start")
+ # time.sleep(10)
+
+
+def sendCmd(mycmd):
+ result = "".join(os.popen(mycmd).readlines())
+ return result
+
+
+def send_times(mycmd):
+ times = 0
+ outcome = sendCmd(mycmd)
+ while times < 3:
+ if not outcome or "Empty" in outcome:
+ times += 1
+ time.sleep(3)
+ else:
+ time.sleep(3)
+ return outcome
+ return outcome
+
+
+@timeout(180)
+def start_cmd(sn):
+ try:
+ os.system("hdc_std -l5 start")
+ power_cmd = "hdc_std -t %s shell \"power-shell setmode 602\"" % sn
+ hilog_cmd = "hdc_std -t %s shell \"hilog -w start -l 400000000 -m none\"" % sn
+ logger.info(power_cmd)
+ logger.info(hilog_cmd)
+ power_result = sendCmd(power_cmd)
+ logger.info(power_result)
+ if not power_result:
+ return False
+ number = 0
+ while "Set Mode Success" not in power_result and number < 30:
+ time.sleep(4)
+ power_result = sendCmd(power_cmd)
+ logger.info(power_result)
+ number += 1
+ if number >= 20:
+ logger.error("Set mode failed")
+ return False
+ hilog_result = sendCmd(hilog_cmd)
+ logger.info(hilog_result)
+ return True
+ except Exception as e:
+ logger.error(e)
+ return False
+
+
+@timeout(3600)
+def cmd_test(screenshot_path, py_path, new_report_path, resource_path, sn, test_num, pr_url):
+ save_screenshot_path = os.path.join(new_report_path, "screenshot_result")
+ logger.info(save_screenshot_path)
+ time_sleep = random.randint(1, 5)
+ time.sleep(time_sleep)
+ try:
+ if not os.path.exists(save_screenshot_path):
+ os.mkdir(save_screenshot_path)
+ logger.info(save_screenshot_path)
+ base_screenshot_path = os.path.join(new_report_path, "screenshot_base")
+ if not os.path.exists(base_screenshot_path):
+ os.mkdir(base_screenshot_path)
+ logger.info(base_screenshot_path)
+ except Exception as e:
+ logger.error(e)
+ return 98
+ config_path = os.path.join(screenshot_path, "resource", "app_capture_screen_test_config.json")
+ py_cmd = "python %s --config %s --anwser_path %s --save_path %s --device_num %s --test_num %s --tools_path %s --pr_url %s" \
+ % (py_path, config_path, resource_path, save_screenshot_path, sn, test_num, screenshot_path, pr_url)
+ result = outCmd(py_cmd, save_screenshot_path, base_screenshot_path, resource_path)
+ if result == 1:
+ return True
+ if result == 98:
+ return 98
+ if result == 99:
+ return 99
+ else:
+ return False
+
+
+@timeout(3600)
+def outCmd(cmd, save_screenshot_path, base_screenshot_path, resource_path):
+ logger.info("cmd is: %s" % cmd)
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="gbk")
+ curline = p.stdout.readline()
+ list_png_name = []
+ try:
+ while "End of check" not in curline:
+ curline = p.stdout.readline()
+ logger.info(curline)
+ if "abnarmal" in curline:
+ png_name = curline.split(" ")[3].split(".")[0]
+ list_png_name.append(png_name)
+ if "SmokeTest find some fatal problems" in curline:
+ logger.error("SmokeTest find some fatal problems!")
+ return 99
+ except Exception as e:
+ logger.error(e)
+ logger.error("execute smoke_test.py failed!")
+ return 99
+ l = list(set(list_png_name))
+ if l:
+ logger.error(l)
+ try:
+ for i in l:
+ result = os.path.join(resource_path, "%s.png" % i)
+ base = os.path.join(base_screenshot_path, "%s.png" % i)
+ shutil.copy(result, base)
+ except Exception as t:
+ logger.info(t)
+ p.wait()
+ logger.info("p.returncode %s" % p.returncode)
+ if p.returncode == 0:
+ logger.info("screenshot check is ok!")
+ return True
+ if p.returncode == 101:
+ logger.error("device disconnection, please check the device!")
+ return False
+ logger.error("screenshot test failed, check the %s" % save_screenshot_path)
+ return 98
+
+
+@timeout(1000)
+def exec_cmd(mini_path, sn, save_path, archive_path):
+ cmd = "python %s --device_num %s --save_path %s --archive_path %s" % (mini_path, sn, save_path, archive_path)
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="gbk")
+ curline = p.stdout.readline()
+ try:
+ while "End of check" not in curline:
+ curline = p.stdout.readline()
+ logger.info(curline)
+ except Exception as e:
+ logger.error(e)
+ p.wait()
+ logger.info("p.returncode %s" % p.returncode)
+ if p.returncode == 0:
+ logger.info("mini_system_test is ok!")
+ return True
+ logger.error("mini_system_test failed!")
+ return 98
\ No newline at end of file
diff --git a/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_linux_app.py b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_linux_app.py
new file mode 100644
index 0000000000000000000000000000000000000000..1b5cf8a769f40161b346ce4c668caeb2fe0ecccb
--- /dev/null
+++ b/DeployDevice/src/func/liteOsUpgrade/liteOsUpgrade_linux_app.py
@@ -0,0 +1,529 @@
+#-*- coding:utf-8 -*-
+import uuid
+import sys
+import subprocess
+import os
+import serial
+import time
+import re
+
+from core.base import BaseApp, dec_stepmsg
+from util.file_locker import FileLock
+from util.log_info import logger
+from util.time_info import get_now_time_str_info, get_now_time_info, Timeout, timeout
+from aw.Telnet.TelnetClient import TelConnect
+from aw.Common.Constant import CONSTANT
+from aw.Download.Download import *
+from aw.Common.Common import getHostIp, copyFile, copyDirectory
+from aw.ExtractFile.ExtractFile import *
+from aw.poweronoff.serial_power_on_off import usbPowerOnOff
+from threading import Thread
+
+lock_suffix = CONSTANT.File.LOCK_SUFFIX #閫氳繃鏂囦欢閿佸疄鐜板苟鍙戜笅杞
+suc_file = CONSTANT.File.SUC_FILE #閫氳繃鏈枃浠舵槸鍖哄垎鐗堟湰鏄惁鎴愬姛涓嬭浇
+failed_file = CONSTANT.File.FAILED_FILE #閫氳繃鏈枃浠舵槸鏍囪鏂囦欢涓嬭浇澶辫触
+READ_MAXTIMEOUT = 5
+READ_TIMEOUT = 5
+READ_MINITIMEOUT = 2
+uboot_finish = 'hisilicon #'
+cmd_finish = ' #'
+error_str_list = ['Unknown', '鍙戦佽捣濮嬪抚澶辫触', '鍙戦佸ご甯уけ璐']
+ip_cmd = 'ping 192.168.18.1'
+
+class liteOsUpgrade_linux(BaseApp):
+ '''
+ @author: cwx1076044
+ '''
+
+ def __init__(self, param_file):
+ super().__init__(param_file)
+ self.param_List = ["deploy_com",
+ "usb_port",
+ "upgrade_upgradeLocation"]
+
+ @dec_stepmsg("linux L1 flash")
+ def excute(self):
+ '''
+ #===================================================================================
+ # @Method: excute(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鎵ц鍏ュ彛
+ # @PostStatus: none
+ # @eg: excute()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ step_index = self.params_dict.get("step_list").index("liteOsUpgrade_linux_app")
+
+ # 鎵ц涓嬭浇
+ try:
+ if not self.download():
+ CONSTANT.ENVERRMESSAGE = "image download fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ except Exception as e:
+ raise e
+
+
+ # 鎵ц鍗囩骇
+ try:
+ if not self.upgrade():
+ CONSTANT.ENVERRMESSAGE = "board upgrade fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ return True
+ except Exception as e:
+ raise e
+
+ @dec_stepmsg("download")
+ @timeout(1800)
+ def download(self):
+ '''
+ #===================================================================================
+ # @Method: download(self)
+ # @Precondition: none
+ # @Func: 鏋勫缓涓嬭浇鍒版湰鍦扮殑璺緞锛屾墽琛岀浉搴斿寘鐨勪笅杞
+ # @PostStatus: none
+ # @eg: download()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ global version_savepath, version_name
+ dir_path = CONSTANT.Path.getDirPath()
+ if self.params_dict.get("pbiid"):
+ version_path = self.params_dict.get("pbiid")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, str(self.params_dict.get("pbiid")) + "FASTBOOT"))
+ version_savepath = os.path.join(dir_path, self.params_dict.get("flash_type"), version_name)
+ else:
+ version_path = self.params_dict.get("upgrade_upgradeLocation")
+ version_name = str(uuid.uuid5(uuid.NAMESPACE_URL, (self.params_dict.get("upgrade_upgradeLocation"))))
+ version_savepath = os.path.join(dir_path, version_name)
+
+ if self.params_dict.get("isDownload") == "True":
+ logger.printLog("涓嶉渶瑕佸仛涓嬭浇锛岀洿鎺ヨ繑鍥")
+ return True
+
+ #鎵цimg涓嬭浇
+ import hashlib
+ save_file_str = version_path.replace("/", "").replace("\\", "")
+ save_file_name = hashlib.sha1(save_file_str.encode("utf-8")).hexdigest()
+ logger.info("download hash value:%s" % (save_file_name))
+ save_path_file = os.path.join(dir_path, "record", "%s%s" % (save_file_name, ".txt"))
+ if not self.excutedown(version_path, os.path.join(version_savepath, "img"), save_path_file, False):
+ logger.error("download img fail")
+ return False
+
+ #淇濆瓨鏈湴鐗堟湰璺緞缁檇evicetest鍘荤増鏈矾寰勪笅鍙栫敤渚
+ saveVersion(save_path_file, os.path.join(version_savepath, "img"))
+
+ return True
+
+ def excutedown(self, source_path, download_dir, suc_mark, is_file):
+ '''
+ #===================================================================================
+ # @Method: excutedown(source_path, download_dir, is_file)
+ # @Precondition: none
+ # @Func: 鎵ц涓嬭浇鍔ㄤ綔
+ # @PostStatus: none
+ # @Param: source_path锛氳祫婧愭枃浠惰矾寰
+ # download_dir:鏂囦欢涓嬭浇鍒版湰鍦扮殑鏂囦欢澶硅矾寰
+ # is_file:鏄惁鏄枃浠
+ #
+ # @eg: excutedown("xxxx", "D:\\local\\image", Flase锛 os_method)
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ failed_mark = os.path.join(download_dir, failed_file)
+ lock_path = os.path.join(download_dir, lock_suffix)
+ file_lock = FileLock()
+
+ if isDownLoadSuccess(download_dir, suc_mark, failed_mark):
+ return True
+ try:
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s Downloading, please wait" % nowtime)
+ file_lock.lockFile(lock_path)
+ ret = ""
+ logger.info("Get lock. Start to ")
+ if self.params_dict.get("bt_enable") and self.params_dict.get("bt_enable") == "True":
+ ret = downloadByBitComet(source_path, download_dir, os_method)
+ elif source_path.startswith('\\\\'):
+ ret = downloadByCopy(source_path, download_dir, is_file)
+ elif self.params_dict.get("pbiid"):
+ ret = downlaodByDownloadTool(version_savepath, self.params_dict.get("version_type"), "FASTBOOT", self.params_dict.get("pbiid"))
+ elif source_path.startswith("http"):
+ ret = downloadFileFromDevCloud(source_path, "", "", download_dir)
+
+ if source_path.endswith(".zip"):
+ zip_name = os.path.basename(source_path)
+ ret = extractZipFile(os.path.join(download_dir, zip_name), download_dir)
+ if source_path.endswith(".tar.gz") or (source_path.startswith("http") and ("file_id=" in source_path)):
+ if source_path.startswith("http") and ("file_id=" in source_path):
+ if source_path.endswith(".tar.gz"):
+ zip_name = source_path.split('=')[-1]
+ else:
+ zip_name = "out.tar.gz"
+ else:
+ zip_name = os.path.basename(source_path)
+ ret = unTarFile(os.path.join(download_dir, zip_name), download_dir)
+ nowtime = get_now_time_str_info()
+ logger.printLog("%s download to %s end" % (nowtime, download_dir))
+
+ if not ret:
+ with open(failed_mark, "a+") as fp:
+ fp.write("")
+ return ret
+ except Exception as e:
+ logger.printLog(e)
+ raise Exception(e)
+ finally:
+ file_lock.releaseFile()
+
+
+ @dec_stepmsg("upgrade")
+ #@timeout(900)
+ def upgrade(self):
+ '''
+ #===================================================================================
+ # @Method: upgrade(self)
+ # @Precondition: none
+ # @Func: 鍗囩骇鐩稿叧涓氬姟閫昏緫
+ # @PostStatus: none
+ # @eg: upgrade()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ logger.printLog('寮濮嬪崌绾')
+ deploy_com = self.params_dict.get("deploy_com")
+ usb_port = self.params_dict.get("usb_port")
+ baudrate = self.params_dict.get("baudrate")
+ #鑺墖绫诲瀷,鏍规嵁鑺墖绫诲瀷鑾峰彇瀵瑰簲鐨勫埛鏈哄懡浠
+ flash_type = self.params_dict.get("flash_type")
+ burn_usbport = self.params_dict.get("hiburn_usbport")
+ device_ip = self.params_dict.get("Device_IP")
+ device_netmask = self.params_dict.get("Device_Netmask")
+ device_gatewayip = self.params_dict.get("Device_GatewayIP")
+ chip_version = self.params_dict.get('chip_version')
+ chip_version = chip_version.lower() if chip_version else chip_version
+
+ if not deploy_com:
+ logger.error("deploy_com is NULL !!")
+ return False
+ if not burn_usbport:
+ logger.error("hiburn_usbport is NULL !!")
+ return False
+ if not baudrate:
+ baudrate = 115200
+ scriptpath = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(__file__)))))
+ #鍗囩骇闇瑕佺殑宸ュ叿褰掓。
+ toolworkspace = CONSTANT.OSType.getworkspace()
+ hiburntoolpath = os.path.join(toolworkspace, "HiBurnCmdLine", "usb%s_tool" % burn_usbport)
+ logger.info("hiburn tool path is: %s" % hiburntoolpath)
+ if not os.path.exists(hiburntoolpath):
+ if not burn_usbport:
+ logger.error("hiburn_usbport is NULL !!")
+ return False
+ os.makedirs(hiburntoolpath)
+ toolpath = os.path.join(scriptpath, "resource", "HiBurnCmdLine.zip")
+ logger.info("copy %s to %s" % (toolpath, hiburntoolpath))
+ copyFile(toolpath, hiburntoolpath)
+ zip_name = os.path.basename(toolpath)
+ ret = extractZipFile(os.path.join(hiburntoolpath, zip_name), hiburntoolpath)
+ if ret:
+ logger.info("unzip to %s succ" % (hiburntoolpath))
+ #淇敼burn.config涓殑usb鍙
+ configpath = os.path.join(hiburntoolpath, "config", "burn.config")
+ all_data = ""
+ with open(configpath, "r", encoding="utf-8") as cf:
+ for line in cf:
+ if "usbDeviceNumber=" in line:
+ old_str = line
+ line = line.replace(old_str, "usbDeviceNumber=%s\r\n" % burn_usbport)
+ logger.info("replace line: %s " % line)
+ all_data += line
+ with open(configpath, "w", encoding="utf-8") as wf:
+ wf.write(all_data)
+ else:
+ logger.error("%s is not exit" % hiburntoolpath)
+ return False
+ #灏嗗崌绾ч渶瑕佺殑鏂囦欢鎷疯礉鍒伴暅鍍忛噷闈
+ local_image_path = os.path.join(version_savepath, "img")
+ old_xml_path = os.path.join(scriptpath, "resource", "L1", flash_type, "usb-burn.xml")
+ xml_path = os.path.join(local_image_path, "usb-burn.xml")
+ copyFile(old_xml_path, xml_path)
+ if flash_type.lower() == "ev300":
+ chip_type = "Hi3518EV300"
+ ubootpath = os.path.join(scriptpath, "resource", "L1", flash_type.lower(), "u-boot-hi3518ev300.bin")
+ elif flash_type.lower() == "dv300_linux":
+ chip_type = "Hi3516DV300"
+ ubootpath = os.path.join(scriptpath, "resource", "L1", flash_type.lower(), "u-boot-hi3516dv300.bin")
+ else:
+ logger.error("flash_type is : %s " % flash_type)
+ return False
+ copyFile(ubootpath, local_image_path)
+ scriptfile = os.path.join(scriptpath, "resource", "L1", f'{flash_type.lower()}', "update.txt")
+ logger.info(f'scriptfile:{scriptfile}')
+
+ current_path = os.getcwd()
+ logger.info("before excute hiburn,current path is: %s" % current_path)
+ os.chdir(hiburntoolpath)
+ logger.info("excute hiburn path is: %s" % os.getcwd())
+ #鎿﹂櫎fastboot
+ logger.printLog('erase fastboot')
+ flash_uboot_xml = os.path.join(scriptpath, "resource", "L1", flash_type.lower(), "flash_fastboot.xml")
+ cmd = ".\jre\\bin\java -jar hiburn.jar --erase -n %s -m serial %s -x %s" % (chip_type, deploy_com.upper(), flash_uboot_xml)
+ self.eraseDevice(cmd, usb_port)
+
+ retry = 0
+ while retry < 3:
+ #usb鍒锋満
+ cmd = ".\jre\\bin\java -jar hiburn.jar --burn -n %s -m USBBootrom -x %s" % (chip_type, xml_path)
+ logger.info("cmd is: %s" % cmd)
+ ret, outpri = subprocess.getstatusoutput(cmd)
+ logger.info("usb upgrade result: %s " % ret)
+ logger.info("print console: %s " % outpri)
+ if ret != 0:
+ if ret == 4 and retry < 2:
+ time.sleep(10)
+ retry = retry + 1
+ logger.info('flash fail,so flash once again')
+ continue
+ logger.info(ret)
+ logger.error("hiburn usb upgrade failed!!")
+ return False
+ retry = retry + 3
+ os.chdir(current_path)
+ logger.info("hiburn upgrade end, check board status")
+ time.sleep(10)
+ try:
+ logger.info("鎵撳紑serial")
+ ser = serial.Serial(deploy_com, int(baudrate), timeout=0)
+ if self.bootUpUboot(ser,scriptfile) and self.configureIp(ser, flash_type, device_ip, device_netmask, device_gatewayip) and self.checkStatus(ser):
+ return True
+ return False
+ except Exception as e:
+ logger.info(e)
+ return False
+ finally:
+ ser.close()
+ logger.info("close serial")
+
+ def bootUpUboot(self,ser,scriptfile):
+ '''
+ 鍚姩uboot
+ '''
+ reset_count = 0
+ while reset_count < 2:
+ if ser.is_open == False:
+ ser.open()
+ logger.info("get device status")
+ board_type = getBoardType(ser)
+ if board_type == "uboot":
+ with open(scriptfile, "r") as fp:
+ lines = fp.readlines()
+ for line in lines:
+ if not line:
+ logger.info("cmd is: %s " % line)
+ continue
+ if "reset" in line:
+ ret = sendCmd(ser, line, READ_MAXTIMEOUT)
+ continue
+ ret = sendCmd(ser, line, READ_MINITIMEOUT)
+ board_type = getBoardType(ser)
+ if board_type != "OHOS":
+ if reset_count < 2:
+ logger.info('after reset;the device status is error锛宺eset device again,reset_count:%d' % reset_count)
+ reset_count += 1
+ time.sleep(20)
+ continue
+ logger.error("upgrade fail")
+ return False
+ return True
+ else:
+ logger.info('before reset;the device status is error锛宺eset device again,reset_count:%d'%reset_count)
+ reset_count += 1
+ time.sleep(20)
+ continue
+ else:
+ return False
+
+ def configureIp(self,ser,flash_type, device_ip, device_netmask, device_gatewayip):
+ '''
+ 閰嶇疆ip锛岀‘璁ら厤缃儏鍐
+ '''
+ rerty_count = 0
+ # test_count = 0
+ while rerty_count <= 2:
+ if flash_type.lower() == "dv300_linux":
+ if not self.afterRebootDvConfigure(ser, device_ip, device_netmask, device_gatewayip):
+ return False
+ elif flash_type.lower() == "ev300":
+ if not self.afterRebootEvConfigure(ser):
+ return False
+ time.sleep(5)
+
+ ret = sendCmd(ser, ip_cmd, READ_MINITIMEOUT)
+ logger.info(ret)
+ # if test_count ==0 :
+ # logger.printLog('ip 閰嶇疆澶辫触')
+ # test_count = 1
+ # continue
+ if 'Reply from 192.168.18.1' in ret:
+ logger.info('ip 閰嶇疆鎴愬姛')
+ return True
+ elif 'Ping: sending ICMP echo request failed' in ret:
+ logger.printLog('ip 閰嶇疆澶辫触')
+ logger.info('閲嶆柊閰嶇疆ip')
+ rerty_count += 1
+ else:
+ return True
+
+ def afterRebootDvConfigure(self,ser, device_ip, device_netmask, device_gatewayip):
+ logger.info("dv300_linux configure ip")
+ init_cmd = "ifconfig eth0 %s netmask %s gateway %s \r" % (device_ip, device_netmask, device_gatewayip)
+ sendCmd(ser, init_cmd, READ_MINITIMEOUT)
+ sendCmd(ser, 'ifconfig\r', READ_MINITIMEOUT)
+ return True
+
+ def afterRebootEvConfigure(self,ser):
+ logger.info("ev300 configuring ,setup wifi")
+ cmd = 'ls\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ if not "sdcard" in ret.lower():
+ cmd = 'mkdir /sdcard\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ if "error:" in ret.lower():
+ logger.error("mkdir /sdcard fail")
+ return False
+ cmd = 'mount /dev/mmcblk0p0 /sdcard vfat\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ cmd = 'ls /sdcard\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ cmd = 'cd /sdcard/wpa\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ cmd = 'exec wpa_supplicant -i wlan0 -c wpa_supplicant.conf \r'
+ ret = sendCmd(ser, cmd, READ_MAXTIMEOUT)
+ if "error:" in ret.lower():
+ logger.error("setup wifi fail")
+ return False
+ cmd = 'ifconfig\r'
+ ret = sendCmd(ser, cmd, READ_MINITIMEOUT)
+ if "error:" in ret.lower():
+ logger.error("ifconfig fail")
+ return False
+ return True
+
+ def eraseDevice(self, cmd, usb_port):
+ '''
+ ret 鏆傛椂娌℃湁浣滅敤锛屽厛浣跨敤out
+ '''
+ erase_retry = 0
+ while erase_retry < 3:
+ # 閫氱數
+ PowerOnByThread(usb_port)
+ logger.info("cmd is: %s" % cmd)
+ ret, outpri = subprocess.getstatusoutput(cmd)
+ logger.info("flash fastboot result: %s " % ret)
+ logger.info("print console: %s " % outpri)
+ is_earse_again = any([True if item in outpri else False for item in error_str_list])
+ if ret == 0 and erase_retry < 2 and not is_earse_again :
+ logger.info('妾櫎鎴愬姛'.center(20,'*'))
+ break
+ elif is_earse_again:
+ logger.info('妾櫎瀛樺湪闂 閲嶆柊涓婁笅鐢 閲嶆柊妾櫎')
+ erase_retry += 1
+ time.sleep(5)
+ continue
+ else:
+ logger.info('other error')
+ return False
+ else:
+ return False
+
+ def checkStatus(self, ser):
+ times = 0
+ while times < 3:
+ ret1 = sendCmd(ser, 'ps -elf', READ_TIMEOUT)
+ list_ret = re.findall('appspawn', ret1)
+ logger.info(list_ret)
+ number = list_ret.count('appspawn')
+ logger.info(number)
+ if number >= 2:
+ return True
+ else:
+ times += 1
+ time.sleep(3)
+ logger.info("No two appspawn processes, please check the device!")
+ return False
+
+def PowerOnByThread(usb_port,wait_time=10):
+ thread = Thread(target=boardPowerOn, args=[usb_port, wait_time])
+ thread.start()
+ logger.info("thread board power on start")
+
+
+def boardPowerOn(usb_port, waittime):
+ logger.info("board power on start")
+ time.sleep(waittime)
+
+ #瀵圭鍙d笅鐢
+ if not usbPowerOnOff('127.0.0.1', '7788', usb_port, "off"):
+ logger.error("board power off failed")
+ return False
+
+ #瀵圭鍙d笂鐢
+ if not usbPowerOnOff('127.0.0.1', '7788', usb_port, "on"):
+ logger.error("board power on failed")
+ return False
+ logger.info("board power on end")
+
+
+def getBoardType(ser):
+ ret = sendCmd(ser, '\r', READ_TIMEOUT)
+ # if 'HMOS' in ret or 'OHOS' in ret or '#' in ret:
+ # ostype = 'OHOS'
+ # elif 'hisilicon' in ret:
+ # ostype = 'uboot'
+ if 'hisilicon' in ret:
+ ostype = 'uboot'
+ elif 'HMOS' in ret or 'OHOS' in ret or '#' in ret:
+ ostype = 'OHOS'
+ elif ' #' in ret:
+ ostype = 'linux'
+ else:
+ ostype = 'bootrom'
+ logger.info("board type is: %s" % ostype)
+ return ostype
+
+def sendCmd(ser, cmd, timeout):
+ logger.info("cmd is: %s " % cmd)
+ ser.write((cmd + '\n').encode())
+ time.sleep(5)
+ ret = ''
+ i = 0
+ while True:
+ out = ser.read(ser.inWaiting())
+ if not out:
+ break
+ if i > 12:
+ break
+ ret = ret + out.decode(encoding="utf-8", errors="ignore")
+ time.sleep(timeout)
+ i = i + 1
+ logger.info("result is: %s " % ret)
+ return ret
+
+
+
+if __name__ == "__main__":
+ param_file = sys.argv[1]
+ if not param_file:
+ logger.printLog("Missing params file")
+ sys.exit(-1)
+ try:
+ uphandle = liteOsUpgrade_linux(param_file)
+ uphandle._excuteApp()
+ except Exception as e:
+ logger.printLog(e)
+ sys.exit(-1)
+
diff --git a/DeployDevice/src/func/presetup/presetup_app.py b/DeployDevice/src/func/presetup/presetup_app.py
new file mode 100644
index 0000000000000000000000000000000000000000..a3aeafea67b3893c6704d1248f2f71ec0477cf33
--- /dev/null
+++ b/DeployDevice/src/func/presetup/presetup_app.py
@@ -0,0 +1,111 @@
+#-*- coding:utf-8 -*-
+import uuid
+import sys
+import subprocess
+
+from core.base import BaseApp, dec_stepmsg
+from util.log_info import logger
+from aw.Download.Download import *
+from aw.Common.Constant import CONSTANT
+from aw.Telnet.TelnetClient import TelConnect
+
+lock_suffix = CONSTANT.File.LOCK_SUFFIX
+suc_file = CONSTANT.File.SUC_FILE
+failed_file = CONSTANT.File.FAILED_FILE
+READ_TIMEOUT = 15
+
+class presetup(BaseApp):
+ '''
+ @author: zwx877058
+ '''
+
+ def __init__(self, param_file):
+ super().__init__(param_file)
+ self.param_List = ["Telnet_IP",
+ "Telnet_Port"]
+
+ @dec_stepmsg("presetup device")
+ def excute(self):
+ '''
+ #===================================================================================
+ # @Method: excute(self)
+ # @Precondition: none
+ # @Func: 鍒濆鍖栭缃墽琛屽叆鍙
+ # @PostStatus: none
+ # @eg: excute()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ step_index = self.params_dict.get("step_list").index("presetup_app")
+
+ # 鎵ц鍒濆鍖
+ try:
+ chip_type = self.params_dict.get("chip_type")
+ if not self.defaultInitL1():
+ CONSTANT.ENVERRMESSAGE = "presetup fail"
+ logger.printLog(CONSTANT.ENVERRMESSAGE)
+ return False
+ return True
+ except Exception as e:
+ logger.error(e)
+ raise e
+
+ def defaultInitL1(self):
+ '''
+ #===================================================================================
+ # @Method: defaultInitL1(self)
+ # @Precondition: none
+ # @Func: 鍏蜂綋鎵ц鍒濆鍖栭缃殑姝ラ鍜屽唴瀹
+ # @PostStatus: none
+ # @eg: defaultInitL1()
+ # @return: True or Flase
+ #===================================================================================
+ '''
+ cmd_finish = ' #'
+ tel_IP = self.params_dict.get("Telnet_IP")
+ tel_port = self.params_dict.get("Telnet_Port")
+ device_ip = self.params_dict.get("Device_IP")
+ device_netmask = self.params_dict.get("Device_Netmask")
+ device_gatewayip = self.params_dict.get("Device_GatewayIP")
+ flash_type = self.params_dict.get("flash_type")
+
+ if not tel_IP or not tel_port:
+ logger.error("Telnet_IP or Telnet_Port is NULL !!")
+ return False
+ if not device_netmask:
+ device_netmask = "255.255.252.0"
+
+ #璁剧疆鍗曟澘澶х綉IP
+ telc = TelConnect(tel_IP, tel_port)
+ board_type = telc.getBoardType(cmd_finish, READ_TIMEOUT)
+ if board_type == "uboot":
+ reset_cmd = "reset"
+ if not telc.sendCmdAndCheckResult(reset_cmd.encode('utf-8'), cmd_finish, READ_TIMEOUT):
+ logger.error("board current type not command, and set %s fail!!" % reset_cmd)
+ return False
+ elif board_type == "bootrom":
+ logger.error("board current type not support command !!")
+ return False
+ ret = telc.sendCmd(b'ifconfig\n', cmd_finish, READ_TIMEOUT)
+ gateway = "eth0"
+ if "et1" in ret:
+ gateway = "et1"
+ init_cmd = "ifconfig %s %s netmask %s gateway %s" % (gateway,device_ip, device_netmask, device_gatewayip)
+ if not telc.sendCmdAndCheckResult(init_cmd.encode('utf-8'), cmd_finish, READ_TIMEOUT):
+ logger.error("set ip failed!!!")
+ return False
+ ret = telc.sendCmd(b'ifconfig\n', cmd_finish, READ_TIMEOUT)
+ logger.info("set ip result is: %s" % ret)
+ return True
+
+if __name__ == "__main__":
+ param_file = sys.argv[1]
+ if not param_file:
+ logger.printLog("Missing params file")
+ sys.exit(-1)
+ try:
+ uphandle = presetup(param_file)
+ uphandle._excuteApp()
+ except Exception as e:
+ logger.printLog(e)
+ sys.exit(-1)
\ No newline at end of file
diff --git a/DeployDevice/src/test.py b/DeployDevice/src/test.py
new file mode 100644
index 0000000000000000000000000000000000000000..f38f0b83090d837a150838fb9dc26cae9d747f33
--- /dev/null
+++ b/DeployDevice/src/test.py
@@ -0,0 +1,7 @@
+from Action.core.Constant import *
+
+import sys
+if __name__ == "__main__":
+
+ print("cur: " + CONSTANT.OSType.default_log_dir)
+
diff --git a/DeployDevice/src/util/__init__.py b/DeployDevice/src/util/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/DeployDevice/src/util/config.py b/DeployDevice/src/util/config.py
new file mode 100644
index 0000000000000000000000000000000000000000..6d701e9921569e10543998243d8749337c5fef0e
--- /dev/null
+++ b/DeployDevice/src/util/config.py
@@ -0,0 +1,213 @@
+# -*- coding:utf-8 -*-
+"""
+======================================================================================
+copyright (C) 2018-2019, Huawei Technologies Co.
+========================================================================================
+@鏂囦欢鍚嶇О: config.py
+@鎻忚堪: 鍔犺浇妗嗘灦绾у父閲 鍜 绯荤粺绾у父閲
+@浣滆: zwx503461
+@鐢熸垚鏃ユ湡: 20181021
+======================================================================================
+"""
+import os
+import platform
+
+# =========================瑙f瀽config鏂囦欢,鑾峰彇鍏ㄥ眬甯镐寒========================
+def getAllParam(param_file):
+ '''
+ #===================================================================================
+ # @Method: getAllParam(param_file)
+ # @Precondition: none
+ # @Func: 瑙f瀽鍙傛暟鏂囦欢鑾峰彇鎵鏈夊弬鏁
+ # @PostStatus: none
+ # @Param: param_file锛氬弬鏁版枃浠
+ # @eg: getAllParam(xxx.properties)
+ # @return: params_dict锛氭墍鏈夌殑鍙傛暟
+ #===================================================================================
+ '''
+ params_dict = {}
+ with open(param_file, 'Ur', encoding="utf-8") as file:
+ for line in file.readlines():
+ line = line.strip()
+ if len(line) != 0:
+ if line.find("=") != -1:
+ str_list = line.split('=')
+ if str_list[0].find("#") != -1:
+ continue
+ else:
+ key = str_list[0].strip()
+ value = line[len(str_list[0]) + 1:].strip()
+ if len(key) != 0 and len(value) != 0:
+ params_dict[key] = value
+ return params_dict
+
+
+cur_path = os.path.dirname(os.path.dirname(__file__))
+
+adb_config_path = os.path.join(cur_path, 'config', 'config_adb.config')
+box_config_path = os.path.join(cur_path, 'config', 'config_box.config')
+device_config_path = os.path.join(cur_path, 'config', 'config_device.config')
+global_config_path = os.path.join(cur_path, 'config', 'config_global.config')
+linux_config_path = os.path.join(cur_path, 'config', 'config_linux.config')
+windows_config_path = os.path.join(cur_path, 'config', 'config_windows.config')
+errorcode_config_path = os.path.join(cur_path, 'config', 'config_errorcode.config')
+errorcode_device_config_path = os.path.join(cur_path, 'config', 'config_errorcode_device.config')
+
+adb_config_param = getAllParam(adb_config_path)
+box_config_param = getAllParam(box_config_path)
+device_config_param = getAllParam(device_config_path)
+global_config_param = getAllParam(global_config_path)
+linux_config_param = getAllParam(linux_config_path)
+windows_config_param = getAllParam(windows_config_path)
+errorcode_config_param = getAllParam(errorcode_config_path)
+errorcode_device_config_param = getAllParam(errorcode_device_config_path)
+
+# print('adb_config_param is %s' % (adb_config_param))
+# print('box_config_param is %s' % (box_config_param))
+# print('device_config_param is %s' % (device_config_param))
+# print('global_config_param is %s' % (global_config_param))
+# print('linux_config_param is %s' % (linux_config_param))
+# print('windows_config_param is %s' % (windows_config_param))
+
+# =========================鑾峰彇妗嗘灦绾у父閲=======================
+SHORT_TIMEOUT = int(adb_config_param.get('SHORT_TIMEOUT'))
+INSTALL_APK_TIMEOUT = int(adb_config_param.get('INSTALL_APK_TIMEOUT'))
+REMOTE_PATH_MAX_LENGTH = int(adb_config_param.get('REMOTE_PATH_MAX_LENGTH'))
+SYNC_DATA_MAX = int(adb_config_param.get('SYNC_DATA_MAX'))
+ID_OKAY = adb_config_param.get('ID_OKAY').encode('ascii')
+ID_FAIL = adb_config_param.get('ID_FAIL').encode('ascii')
+ID_STAT = adb_config_param.get('ID_STAT').encode('ascii')
+ID_RECV = adb_config_param.get('ID_RECV').encode('ascii')
+ID_DATA = adb_config_param.get('ID_DATA').encode('ascii')
+ID_DONE = adb_config_param.get('ID_DONE').encode('ascii')
+ID_SEND = adb_config_param.get('ID_SEND').encode('ascii')
+ID_LIST = adb_config_param.get('ID_LIST').encode('ascii')
+ID_DENT = adb_config_param.get('ID_DENT').encode('ascii')
+
+GT3000_DEFAULT_PORT = int(box_config_param.get('GT3000_DEFAULT_PORT'))
+OK = box_config_param.get('OK')
+
+DEVICE_STATE_ERECOVERY = device_config_param.get('DEVICE_STATE_ERECOVERY')
+DEVICE_STATE_UNKNOW = device_config_param.get('DEVICE_STATE_UNKNOW')
+DEVICE_STATE_BOOTLOADER = device_config_param.get('DEVICE_STATE_BOOTLOADER')
+DEVICE_STATE_OFFLINE = device_config_param.get('DEVICE_STATE_OFFLINE')
+DEVICE_STATE_ONLINE = device_config_param.get('DEVICE_STATE_ONLINE')
+DEVICE_STATE_RECOVERY = device_config_param.get('DEVICE_STATE_RECOVERY')
+DEVICE_STATE_UNAUTH = device_config_param.get('DEVICE_STATE_UNAUTH')
+PLATFORM_HISI = device_config_param.get('PLATFORM_HISI')
+PLATFORM_QCOM = device_config_param.get('PLATFORM_QCOM')
+PLATFORM_SC = device_config_param.get('PLATFORM_SC')
+DEVICE_STATE_FASTBOOT = device_config_param.get('DEVICE_STATE_FASTBOOT')
+
+DEFAULT_HOST = global_config_param.get('DEFAULT_HOST')
+DEFAULT_PORT = int(global_config_param.get('DEFAULT_PORT'))
+DEFAULT_ENCODING = global_config_param.get('DEFAULT_ENCODING')
+LINUX_ERROR_TITLE = global_config_param.get('LINUX_ERROR_TITLE')
+WINDOWS_ERROR_TITLE = global_config_param.get('WINDOWS_ERROR_TITLE')
+LOCK_SUFFIX = global_config_param.get('LOCK_SUFFIX')
+SUC_FILE = global_config_param.get('SUC_FILE')
+FAILED_FILE = global_config_param.get('FAILED_FILE')
+ARIA2CBIN = global_config_param.get('ARIA2CBIN')
+
+SUCCESS_CODE = errorcode_config_param.get('SUCCESS_CODE')
+ERROR_CUSTPARAM_IS_NONE = errorcode_config_param.get('ERROR_CUSTPARAM_IS_NONE')
+ERROR_PARAMS_NO_SN = errorcode_config_param.get('ERROR_PARAMS_NO_SN')
+ERROR_VERSION_USE_CHINAESE = errorcode_config_param.get('ERROR_VERSION_USE_CHINAESE')
+ERROR_VERSION_IS_NONE = errorcode_config_param.get('ERROR_VERSION_IS_NONE')
+ERROR_VERSION_PATH_TOO_LONG = errorcode_config_param.get('ERROR_VERSION_PATH_TOO_LONG')
+ERROR_CUSTPARAM_NOT_IN_ALLPARAMS = errorcode_config_param.get('ERROR_CUSTPARAM_NOT_IN_ALLPARAMS')
+ERROR_DOWNLOAD_IMG_FAIL = errorcode_config_param.get('ERROR_DOWNLOAD_IMG_FAIL')
+ERROR_DOWNLOAD_ROOT_FAIL = errorcode_config_param.get('ERROR_DOWNLOAD_ROOT_FAIL')
+ERROR_DOWNLOAD_APK_FAIL = errorcode_config_param.get('ERROR_DOWNLOAD_APK_FAIL')
+ERROR_MAKE_DIR_FAIL = errorcode_config_param.get('ERROR_MAKE_DIR_FAIL')
+ERROR_FLASH_IMAGE_FAIL = errorcode_config_param.get('ERROR_FLASH_IMAGE_FAIL')
+ERROR_FLASH_BASE_FAIL = errorcode_config_param.get('ERROR_FLASH_BASE_FAIL')
+ERROR_FLASH_CUST_FAIL = errorcode_config_param.get('ERROR_FLASH_CUST_FAIL')
+ERROR_FLASH_PRELOAD_FAIL = errorcode_config_param.get('ERROR_FLASH_PRELOAD_FAIL')
+ERROR_NO_IMG_FILE = errorcode_config_param.get('ERROR_NO_IMG_FILE')
+ERROR_NO_SCRIPT_FILE = errorcode_config_param.get('ERROR_NO_SCRIPT_FILE')
+ERROR_DEVICE_NOT_FOUND = errorcode_config_param.get('ERROR_DEVICE_NOT_FOUND')
+ERROR_MODIFY_SCRIPT_FAIL = errorcode_config_param.get('ERROR_MODIFY_SCRIPT_FAIL')
+ERROR_INVALID_APK_FILE = errorcode_config_param.get('ERROR_INVALID_APK_FILE')
+ERROR_LOCALPATH_NOT_EXIST = errorcode_config_param.get('ERROR_LOCALPATH_NOT_EXIST')
+ERROR_INSTALL_APK_FAIL = errorcode_config_param.get('ERROR_INSTALL_APK_FAIL')
+ERROR_DOWNLOAD_COTA_FAIL = errorcode_config_param.get('ERROR_DOWNLOAD_COTA_FAIL')
+ERROR_DEVICE_UNAUTHORIZE = errorcode_config_param.get('ERROR_DEVICE_UNAUTHORIZE')
+ERROR_PUSH_FILE_FAIL = errorcode_config_param.get('ERROR_PUSH_FILE_FAIL')
+ERROR_NO_UPGRADE_FILE_OR_PACKAGE = errorcode_config_param.get('ERROR_NO_UPGRADE_FILE_OR_PACKAGE')
+ERROR_DOWNLOAD_VERSION_FAIL = errorcode_config_param.get('ERROR_DOWNLOAD_VERSION_FAIL')
+ERROR_BOOT_UP_TIME_OUT = errorcode_config_param.get('ERROR_BOOT_UP_TIME_OUT')
+ERROR_MODEM_CHECK_FAIL = errorcode_config_param.get('ERROR_MODEM_CHECK_FAIL')
+ERROR_LAUNCHER_CHECK_FAIL = errorcode_config_param.get('ERROR_LAUNCHER_CHECK_FAIL')
+ERROR_CANNOT_INTO_FASTBOOT_MODE = errorcode_config_param.get('ERROR_CANNOT_INTO_FASTBOOT_MODE')
+ERROR_RESETFACTORY_TIME_OUT = errorcode_config_param.get('ERROR_RESETFACTORY_TIME_OUT')
+ERROR_OTHER_ERROR = errorcode_config_param.get('ERROR_OTHER_ERROR')
+ERROR_VALIDATEPARAMS_FAIL = errorcode_config_param.get('ERROR_VALIDATEPARAMS_FAIL')
+ERROR_PARSE_RESOURCEPOOL_PARMS_FAIL = errorcode_config_param.get('ERROR_PARSE_RESOURCEPOOL_PARMS_FAIL')
+ERROR_DEVICE_IS_FASTBOOT_CAN_NOT_DO_APK_UPGRDE = errorcode_config_param.get('ERROR_DEVICE_IS_FASTBOOT_CAN_NOT_DO_APK_UPGRDE')
+ERROR_EXCUTE_USERCUST_SCRIPT_FAIL_IN_RESOUCEPOOL = errorcode_config_param.get('ERROR_EXCUTE_USERCUST_SCRIPT_FAIL_IN_RESOUCEPOOL')
+ERROR_NO_USERCUST_SCRIPT_IN_RESOUCEPOOL = errorcode_config_param.get('ERROR_NO_USERCUST_SCRIPT_IN_RESOUCEPOOL')
+
+
+ERROR_UNINSTALL_XDEVICE_ERROR = errorcode_device_config_param.get('ERROR_UNINSTALL_XDEVICE_ERROR')
+ERROR_INSTALL_XDEVICE_ERROR = errorcode_device_config_param.get('ERROR_INSTALL_XDEVICE_ERROR')
+ERROR_PHONE_START_FAILED = errorcode_config_param.get('ERROR_PHONE_START_FAILED')
+ERROR_ANDROID_STARTING = errorcode_device_config_param.get('ERROR_ANDROID_STARTING')
+ERROR_PHONE_FASTBOOT = errorcode_device_config_param.get('EERROR_PHONE_FASTBOOT')
+ERROR_NO_ROOT_PERMISSION = errorcode_device_config_param.get('ERROR_NO_ROOT_PERMISSION')
+ERROR_ADB_TIMEOUT = errorcode_device_config_param.get('ERROR_ADB_TIMEOUT')
+ERROR_PHONE_NOTFOUND = errorcode_device_config_param.get('ERROR_PHONE_NOTFOUND')
+ERROR_PHONE_SIMULATE_NOTFOUND = errorcode_device_config_param.get('ERROR_PHONE_SIMULATE_NOTFOUND')
+ERROR_CHECK_PARAM_ERROR = errorcode_device_config_param.get('ERROR_CHECK_PARAM_ERROR')
+ERROR_PHONE_OTHER_ERROR = errorcode_device_config_param.get('ERROR_PHONE_OTHER_ERROR')
+
+# =========================鑾峰彇绯荤粺绾у父閲=======================
+os_name = platform.system()
+
+PASSWORD = linux_config_param.get('PASSWORD')
+ACCOUNT = linux_config_param.get('ACCOUNT')
+WORKSPACEG = windows_config_param.get('WORKSPACEG')
+ENV_PATH = windows_config_param.get('ENV_PATH')
+LOCAL_APK_PATH = windows_config_param.get('LOCAL_APK_PATH')
+LOCAL_COTA_PATH = windows_config_param.get('LOCAL_COTA_PATH')
+MST_PATH = windows_config_param.get('MST_PATH')
+MST_PATHG = windows_config_param.get('MST_PATHG')
+DIR_PATH = windows_config_param.get('DIR_PATH')
+
+# 妫鏌ユ仮澶嶅父閲
+LINUX_ECM_FILE = linux_config_param.get('LINUX_ECM_FILE')
+LINUX_AGENT_FILE = linux_config_param.get('LINUX_ECM_FILE')
+
+ANDROID_ADB_SERVER_PORT = windows_config_param.get('ANDROID_ADB_SERVER_PORT')
+DEVICE_TEST_HOME = windows_config_param.get('DEVICE_TEST_HOME')
+DEVICETESTOOLS_DIR = windows_config_param.get('DEVICETESTOOLS_DIR')
+ES_REC_SCRIPT = windows_config_param.get('ES_REC_SCRIPT')
+WINDOWS_AGENT_DIR = windows_config_param.get('WINDOWS_AGENT_DIR')
+WINDOWS_AGENT_FILE = windows_config_param.get('WINDOWS_AGENT_FILE')
+WINDOWS_AGENT_VERSION_FILE = windows_config_param.get('WINDOWS_AGENT_VERSION_FILE')
+WINDOWS_ES_DIR = windows_config_param.get('WINDOWS_ES_DIR')
+WINDOWS_ES_VERSION_FILE = windows_config_param.get('WINDOWS_ES_VERSION_FILE')
+WINDOWS_ECM_DIR = windows_config_param.get('WINDOWS_ECM_DIR')
+WINDOWS_ECM_VERSION_FILE = windows_config_param.get('WINDOWS_ECM_VERSION_FILE')
+
+if os_name == 'Linux':
+ SCRIPT_FILE = linux_config_param.get('SCRIPT_FILE')
+ TEST_PATH = linux_config_param.get('TEST_PATH')
+ WORKSPACE = linux_config_param.get('WORKSPACE')
+ FLASH_SCRIPT_PATH = linux_config_param.get('FLASH_SCRIPT_PATH')
+ SPLASH2_PATH = linux_config_param.get('SPLASH2_PATH')
+ FASTBOOT_EXEC = linux_config_param.get('FASTBOOT_EXEC')
+ DEFAULT_BAUDRATE = int(linux_config_param.get('DEFAULT_BAUDRATE'))
+ DEFAULT_PORT = int(linux_config_param.get('DEFAULT_PORT'))
+ P4_NAME = linux_config_param.get('P4_NAME')
+
+if os_name == 'Windows':
+ SCRIPT_FILE = windows_config_param.get('SCRIPT_FILE')
+ WORKSPACE = windows_config_param.get('WORKSPACE')
+ TEST_PATH = windows_config_param.get('TEST_PATH')
+ FLASH_SCRIPT_PATH = windows_config_param.get('FLASH_SCRIPT_PATH')
+ FASTBOOT_EXEC = windows_config_param.get('FASTBOOT_EXEC')
+ SPLASH2_PATH = windows_config_param.get('SPLASH2_PATH')
+ DEFAULT_BAUDRATE = int(windows_config_param.get('DEFAULT_BAUDRATE'))
+ DEFAULT_PORT = int(windows_config_param.get('DEFAULT_PORT'))
+ P4_NAME = windows_config_param.get('P4_NAME')
diff --git a/DeployDevice/src/util/file_locker.py b/DeployDevice/src/util/file_locker.py
new file mode 100644
index 0000000000000000000000000000000000000000..90804c097e7987b6e7a8665bad0289602758b158
--- /dev/null
+++ b/DeployDevice/src/util/file_locker.py
@@ -0,0 +1,98 @@
+#encoding=utf-8
+from util.log_info import logger
+import os
+import time
+import errno
+
+class FileLockException(Exception):
+ pass
+
+class FileLock(object):
+ """ A file locking mechanism that has context-manager support so
+ you can use it in a with statement. This should be relatively cross
+ compatible as it doesn't rely on msvcrt or fcntl for the locking.
+ """
+
+
+ def __init__(self, timeout=7200, delay=3):
+ """ Prepare the file locker. Specify the file to lock and optionally
+ the maximum timeout and the delay between each attempt to lock.
+ """
+ self.is_locked = False
+ self.timeout = timeout
+ self.delay = delay
+
+ def _setLockFileName(self, file_name):
+ self.lockfile = file_name
+
+ def acquire(self):
+ """ Acquire the lock, if possible. If the lock is in use, it check again
+ every `wait` seconds. It does this until it either gets the lock or
+ exceeds `timeout` number of seconds, in which case it throws
+ an exception.
+ """
+ start_time = time.time()
+ if os.path.isfile(self.lockfile):
+ try:
+ mark_file_mtime = os.path.getmtime(self.lockfile)
+ if (start_time - mark_file_mtime > self.timeout):
+ os.remove(self.lockfile)
+ except Exception as e:
+ logger.warning("the lock file is locked by other process")
+
+ while True:
+ try:
+ #open file , other application can't open it
+ self.fd = os.open(self.lockfile, os.O_CREAT|os.O_EXCL|os.O_RDWR)
+ break
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
+ if (time.time() - start_time) >= self.timeout:
+ raise FileLockException("Timeout occured.")
+ time.sleep(self.delay)
+ self.is_locked = True
+
+
+ def release(self):
+ """ Get rid of the lock by deleting the lockfile.
+ When working in a `with` statement, this gets automatically
+ called at the end.
+ """
+ #
+ if self.is_locked :
+ os.close(self.fd)
+ os.unlink(self.lockfile)
+ self.is_locked = False
+
+ def lockFile(self, file_name):
+ """ Activated when used in the with statement.
+ Should automatically acquire a lock to be used in the with block.
+ """
+ self._setLockFileName(file_name)
+ if not self.is_locked:
+ self.acquire()
+ return self
+
+ def releaseFile(self):
+ """ Activated at the end of the with statement.
+ It automatically releases the lock if it isn't locked.
+ """
+ if self.is_locked:
+ self.release()
+
+ def __del__(self):
+ """ Make sure that the FileLock instance doesn't leave a lockfile
+ lying around.
+ """
+ self.release()
+
+
+
+#鐢ㄦ硶姣旇緝鏈夋剰鎬濓紝浣跨敤with鍏抽敭瀛椼傚with鍏抽敭瀛楁潵璇达紝FileLock绫诲厛鎵ц__enter__鍑芥暟锛岀劧鍚庯紝鎵цwith鍧楅噷鐨勯偅浜涗唬鐮侊紝鎵ц瀹屼簡涔嬪悗锛屽啀鎵ц__exit__鍑芥暟锛岀瓑浠蜂簬鐩稿綋浜庡涓嬪舰寮忥細
+#try:
+# 鎵ц __enter__鐨勫唴瀹
+# 鎵ц with_block.
+#finally:
+# 鎵ц __exit__鍐呭
+#FileLock鍦╛_enter__鍑芥暟鐙崰寮忓垱寤烘垨鎵撳紑涓涓枃浠讹紝杩欎釜鏂囦欢涓嶄細琚叾浠栫▼搴忔垨鑰呰繘绋嬪啀娆″垱寤烘垨鑰呮墦寮锛岀敱姝ゅ舰鎴恖ock锛屾墽琛屽畬浠g爜锛屽湪__exit__閲岋紝鍏抽棴骞跺垹闄ゆ枃浠
\ No newline at end of file
diff --git a/DeployDevice/src/util/find_fail_task.py b/DeployDevice/src/util/find_fail_task.py
new file mode 100644
index 0000000000000000000000000000000000000000..d9bc06314477a9127d56681372fb8b19c50015a1
--- /dev/null
+++ b/DeployDevice/src/util/find_fail_task.py
@@ -0,0 +1,43 @@
+import os
+import time
+# import shutil
+local_path = 'D:\Local\ATLog'
+wait_count = 0
+total_count = 0
+fail_count = 0
+log_path = 'D:/MobileUpgrade/fail_upgrade_list.log'
+
+if os.path.exists(log_path):
+ print("鍒犻櫎浠ュ線鏃ュ織")
+ os.remove(log_path)
+
+
+with open(log_path,'a+') as fw:
+ fw.write('寮濮嬮亶鍘嗘棩蹇'.center(100,'*'))
+ fw.write('\n')
+for dir_path, dir_names, file_names in os.walk(local_path):
+ if 'upgrade.log' in file_names:
+ total_count += 1
+ # print(dir_path, dir_names, file_names)
+ try:
+ items = dir_path.split(os.sep)
+ block_name, task_name = (items[-1],items[-2])
+ except Exception as e:
+ print(dir_path)
+ print(str(e))
+ with open(os.path.join(dir_path, 'upgrade.log'),'r') as fr:
+ if 'upgrade failed' in fr.read():
+ fail_count += 1
+ with open(log_path,'a+') as fw:
+ print(f'鍙戠幇澶辫触浠诲姟:{task_name}')
+ fw.write(f'澶辫触浠诲姟璺緞锛歿dir_path}\n')
+ wait_count += 1
+ if wait_count == 5:
+ wait_count = 0
+ # time.sleep(30)
+
+with open(log_path,'a+') as fw:
+ fw.write('澶辫触鏃ュ織閬嶅巻缁撴潫'.center(100,'*'))
+ fw.write('\n')
+ fw.write(f'鎬诲叡妫绱㈡棩蹇楋細{total_count}涓猏n')
+ fw.write(f'鍏朵腑瀛樺湪澶辫触鐨勬棩蹇楋細{fail_count}涓猏n')
\ No newline at end of file
diff --git a/DeployDevice/src/util/log_info.py b/DeployDevice/src/util/log_info.py
new file mode 100644
index 0000000000000000000000000000000000000000..d119e3de0cdbb9bf72034f7f67b9463b4d5d3606
--- /dev/null
+++ b/DeployDevice/src/util/log_info.py
@@ -0,0 +1,142 @@
+# encoding=utf-8
+from util import time_info
+
+import os
+import sys
+
+
+class Singleton():
+ _instance = None
+ def __new__(cls, *args, **kw):
+ if not hasattr(cls, '_instance'):
+ cls._instance = super(Singleton, cls).__new__(cls, *args, **kw)
+ else:
+ return cls._instance
+
+class Logger():
+
+ __info = "[INFO ]"
+ __error = "[ERROR ]"
+ __debug = "[DEBUG ]"
+ __warning = "[WARNING ]"
+
+ __user = "[USER]"
+
+ log_file_path = ""
+
+ def __init__(self):
+ pass
+
+
+ def switchFilePath(self, path):
+ self.log_file_path = path
+ self.printLog("Write detail log to File: %s" % path)
+
+
+ def __printMessage(self, type, msg, log_level='developer'):
+ '''
+ #====================================================================================
+ # @Method: __printMessage()
+ # @Precondition: none
+ # @Func: print the log
+ # @PostStatus: none
+ # @Param: type, log type:info, debug, error or worning
+ # @Param: msg, log message
+ # @Example: logger.__printMessage(self.__info, "test")
+ # @Author: zwx205888
+ # @ModifyRecord: None
+ #====================================================================================
+ '''
+
+ time_str = time_info.get_now_time_str_info()
+ filename = "unknow file"
+ lineno_str = "unknow line number"
+ try:
+ f = sys._getframe(2)
+ filename = os.path.basename(f.f_code.co_filename)
+ lineno_str = str(f.f_lineno)
+ except Exception as e:
+ print(e)
+ log_message = "%s : [%s - %s line: %s - %s]" % (type, time_str, filename, lineno_str, msg)
+# print(log_message)
+ self.printIntoLogFile(log_message, log_level)
+
+ def printIntoLogFile(self, log_message, log_level):
+ if log_level == 'user':
+ print(log_message)
+
+ param_file_path, _ = os.path.split(self.log_file_path)
+ if not os.path.exists(param_file_path):
+ os.makedirs(param_file_path)
+ with open(self.log_file_path, 'a', encoding='utf-8') as f:
+ f.write(log_message + '\n')
+
+ def printLog(self, log_message):
+ self.__printMessage(self.__info, log_message, 'user')
+
+ def info(self, msg):
+ '''
+ #====================================================================================
+ # @Method: info()
+ # @Precondition: none
+ # @Func: print the log of info type
+ # @PostStatus: none
+ # @Param: msg, log message
+ # @Example: logger.info("test")
+ # @Author: zwx205888
+ # @ModifyRecord: None
+ #====================================================================================
+ '''
+ self.__printMessage(self.__info, msg)
+
+ def error(self, msg):
+ '''
+ #====================================================================================
+ # @Method: error()
+ # @Precondition: none
+ # @Func: print the log of error type
+ # @PostStatus: none
+ # @Param: msg, log message
+ # @Example: logger.error("test")
+ # @Author: zwx205888
+ # @ModifyRecord: None
+ #====================================================================================
+ '''
+ self.__printMessage(self.__error, msg)
+
+ def debug(self, msg):
+ '''
+ #====================================================================================
+ # @Method: debug()
+ # @Precondition: none
+ # @Func: print the log of debug type
+ # @PostStatus: none
+ # @Param: msg, log message
+ # @Example: logger.debug("test")
+ # @Author: zwx205888
+ # @ModifyRecord: None
+ #====================================================================================
+ '''
+
+ self.__printMessage(self.__debug, msg)
+
+ def warning(self, msg):
+ '''
+ #====================================================================================
+ # @Method: warning()
+ # @Precondition: none
+ # @Func: print the log of warning type
+ # @PostStatus: none
+ # @Param: msg, log message
+ # @Example: logger.warning("test")
+ # @Author: zwx205888
+ # @ModifyRecord: None
+ #====================================================================================
+ '''
+
+ self.__printMessage(self.__warning, msg)
+
+'''
+# use logger object
+'''
+logger = Logger()
diff --git a/DeployDevice/src/util/time_info.py b/DeployDevice/src/util/time_info.py
new file mode 100644
index 0000000000000000000000000000000000000000..e3ce932710dcab4cdb35e2f8f643eb81128908e6
--- /dev/null
+++ b/DeployDevice/src/util/time_info.py
@@ -0,0 +1,113 @@
+#encoding=utf-8
+'''
+======================================================================================
+鐗堟潈 (C) 2015-2020, Huawei Technologies Co., HUTAF xDevice
+========================================================================================
+@FileName: time_info.py
+@Function: 鏃堕棿鏍煎紡鍖栨柟娉,浠ュ強timeout娉ㄩ噴
+@Author:
+@Date:
+======================================================================================
+'''
+
+import datetime
+import sys
+import threading
+import time
+from util.log_info import logger
+thead = []
+
+
+def get_timestamp():
+ return time.time()
+
+def get_time_str_info(time_stamp):
+ st = time.localtime(time_stamp)
+ result = time.strftime("%Y-%m-%d %H:%M:%S", st)
+ return result
+
+def time_info_to_timestamp(timeinfo):
+ st = time.strptime(timeinfo, "%Y-%m-%d %H:%M:%S")
+ return time.mktime(st)
+
+def get_now_time_str_info():
+ now = datetime.datetime.now()
+ time_str = now.strftime("%Y-%m-%d %H:%M:%S")
+ microsecond = now.microsecond
+ result = "%s,%s" % (time_str, microsecond)
+ return result
+
+def get_now_time_info():
+ now = datetime.datetime.now()
+ time_str = now.strftime("%Y-%m-%d %H:%M:%S")
+ return time_str
+
+class KThread(threading.Thread):
+ def __init__(self, *args, **kwargs):
+ threading.Thread.__init__(self, *args, **kwargs)
+ self.killed = False
+
+ def start(self):
+ self.__run_backup = self.run
+ self.run = self.__run # Force the Thread to install our trace.
+ threading.Thread.start(self)
+
+ def __run(self):
+ sys.settrace(self.global_trace)
+ self.__run_backup()
+ self.run = self.__run_backup
+
+ def global_trace(self, frame, why, arg):
+ if why == "call":
+ return self.local_trace
+ else:
+ return None
+
+ def local_trace(self, frame, why, arg):
+ if self.killed:
+ if why == "line":
+ raise SystemExit()
+ return self.local_trace
+
+ def kill(self):
+ self.killed = True
+
+class Timeout(Exception):
+ def __init__(self, arg):
+ for i in thead:
+ if i is not None:
+ i.kill()
+ i = None
+ super(Timeout, self).__init__(arg)
+
+def timeout(seconds = 300):
+ def timeout_decorator(func):
+ def _new_func(oldfunc, result, oldfunc_args, oldfunc_kwargs):
+ result.append(oldfunc(*oldfunc_args, **oldfunc_kwargs))
+
+ def _(*args, **kwargs):
+ result = []
+ new_kwargs = { # create new args for _new_func, because we want to get the func return val to result list
+ "oldfunc": func,
+ "result": result,
+ "oldfunc_args": args,
+ "oldfunc_kwargs": kwargs
+ }
+ thd = KThread(target=_new_func, args=(), kwargs=new_kwargs)
+ thd.setDaemon(True)
+ thd.start()
+ thd.join(seconds)
+ alive = thd.isAlive()
+ thd.kill()
+ if alive:
+ raise Timeout(u"function run too long, timeout %d seconds." % seconds)
+ else:
+ if len(result) == 0:
+ logger.info(u"function run too long, timeout %d seconds." % seconds)
+ raise Exception("TESTCASE FAILED")
+ else:
+ return result[0]
+ _.__name__ = func.__name__
+ _.__doc__ = func.__doc__
+ return _
+ return timeout_decorator
\ No newline at end of file
diff --git a/DeployDevice/temp.txt b/DeployDevice/temp.txt
new file mode 100644
index 0000000000000000000000000000000000000000..c7374e5bef63d6d44d3ad647080536d54caf9308
--- /dev/null
+++ b/DeployDevice/temp.txt
@@ -0,0 +1 @@
+https://devrepo.devcloud.cn-north-4.huaweicloud.com/DevRepoServer/v1/files/download?file_id=bc385ef075f545ccaceae883b9ce0770&type=archive&filename=l1.tar.gz
\ No newline at end of file
diff --git a/OAT.xml b/OAT.xml
index 8671286f8b270db98a67064ba5b76e8255270916..28e1217bc91673832d056aa848cdb98ccce2aa05 100644
--- a/OAT.xml
+++ b/OAT.xml
@@ -1,5 +1,5 @@
-
+
@@ -26,21 +63,21 @@
-
-
+
+
-
-
-
+
+
+
-
-
+
+
-
-
+
+
-
+
\ No newline at end of file