|
24 | 24 | # 2020-4-10 SummerGift Code clear up |
25 | 25 | # |
26 | 26 |
|
| 27 | +import logging |
| 28 | +import os |
| 29 | +import shutil |
27 | 30 | import tarfile |
28 | 31 | import zipfile |
29 | | -import os |
30 | 32 | import pkgsdb |
31 | | -import platform |
32 | | -import shutil |
33 | | -import logging |
34 | | - |
35 | | - |
36 | | -def is_windows(): |
37 | | - if platform.system() == "Windows": |
38 | | - return True |
39 | | - else: |
40 | | - return False |
41 | | - |
42 | | - |
43 | | -def remove_folder(folder_path): |
44 | | - if os.path.isdir(folder_path): |
45 | | - if is_windows(): |
46 | | - cmd = 'rd /s /q ' + folder_path |
47 | | - os.system(cmd) |
48 | | - else: |
49 | | - shutil.rmtree(folder_path) |
| 33 | +from cmds.cmd_package.cmd_package_utils import is_windows, remove_folder |
50 | 34 |
|
51 | 35 |
|
52 | 36 | def unpack(archive_filename, path, package_info, package_name): |
53 | 37 | package_version = package_info['ver'] |
54 | | - |
55 | 38 | package_temp_path = os.path.join(path, "package_temp") |
56 | | - os.makedirs(package_temp_path) |
| 39 | + try: |
| 40 | + remove_folder(package_temp_path) |
| 41 | + os.makedirs(package_temp_path) |
| 42 | + except Exception as e: |
| 43 | + logging.warning('Error message : {0}'.format(e)) |
57 | 44 |
|
58 | 45 | logging.info("BSP packages path {0}".format(path)) |
59 | 46 | logging.info("BSP package temp path: {0}".format(package_temp_path)) |
@@ -124,13 +111,23 @@ def unpack(archive_filename, path, package_info, package_name): |
124 | 111 | # rename package folder name |
125 | 112 | package_name_with_version = package_name + '-' + package_version |
126 | 113 | rename_path = os.path.join(package_temp_path, package_name_with_version) |
127 | | - os.rename(os.path.join(package_temp_path, dir_name), rename_path) |
128 | 114 |
|
129 | | - # copy package to bsp packages path. |
130 | | - shutil.move(rename_path, os.path.join(path, package_name_with_version)) |
| 115 | + logging.info("origin name: {0}".format(os.path.join(package_temp_path, dir_name))) |
| 116 | + logging.info("rename name: {0}".format(rename_path)) |
| 117 | + |
| 118 | + try: |
| 119 | + os.rename(os.path.join(package_temp_path, dir_name), rename_path) |
| 120 | + except Exception as e: |
| 121 | + # remove temp folder and archive file |
| 122 | + logging.warning('{0}'.format(e)) |
| 123 | + |
| 124 | + if not os.path.isdir(os.path.join(path, package_name_with_version)): |
| 125 | + # copy package to bsp packages path. |
| 126 | + shutil.move(rename_path, os.path.join(path, package_name_with_version)) |
131 | 127 |
|
132 | 128 | # remove temp folder |
133 | 129 | remove_folder(package_temp_path) |
| 130 | + |
134 | 131 | return True |
135 | 132 |
|
136 | 133 |
|
|
0 commit comments