-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdownload_test_files.py
30 lines (26 loc) · 1.31 KB
/
download_test_files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import argparse
import shutil
from ftp_helper import *
if __name__ == '__main__':
print("Download test files from ftp")
parser = argparse.ArgumentParser()
parser.add_argument('--module', help='Set Module to test')
arg_dict = parser.parse_args()
test_script_zip = "test_script.tar.gz"
image_zip = "{}.tar.gz".format(arg_dict.module)
#connect ftp
hsot, port, key = rs_ftp_host()
sftp = SFTP(hsot, port, key)
sftp.connect()
dest_download_path = os.path.join(os.getcwd(), "SRC")
sftp.download(os.path.join(rs_ftp_server(), test_script_zip), dest_download_path)
sftp.download(os.path.join(rs_ftp_server(), image_zip), dest_download_path)
sftp.disconnect()
shutil.unpack_archive(os.path.join(dest_download_path, test_script_zip), os.path.join(os.getcwd(), "script"), format="gztar")
image_dest_unpack_path = os.path.join(dest_download_path, arg_dict.module)
os.remove(os.path.join(dest_download_path, test_script_zip))
try:
shutil.unpack_archive(os.path.join(dest_download_path, image_zip), image_dest_unpack_path, format="gztar")
os.remove(os.path.join(dest_download_path, image_zip))
except Exception as e:
print("Unzip image zip failed: {}, mabye there is no {} exists or build failed".format(e, image_zip))