|
14 | 14 | import platform |
15 | 15 | import subprocess |
16 | 16 | import uuid |
17 | | - |
| 17 | +import re |
18 | 18 |
|
19 | 19 | def str_to_bool(str): |
20 | 20 | if str == "False": |
@@ -70,23 +70,53 @@ def get_import_content(f1, src_import, content, import_list): |
70 | 70 | return edit |
71 | 71 |
|
72 | 72 |
|
73 | | -def copyPy(args): |
74 | | - new_src_path = CreateSavePath("new_src") |
75 | | - try: |
76 | | - if str_to_bool(args.is_qt) is False: |
77 | | - src_path_list = ["src"] |
78 | | - src_import_list = ["src."] |
79 | | - else: |
80 | | - src_path_list = ["src", "view", "view/customView", "controller"] |
81 | | - src_import_list = ["src.", "view.", "view.customView.", "controller."] |
82 | | - except: |
83 | | - src_path_list = ["src"] |
84 | | - src_import_list = ["src."] |
85 | | - import_list = [] |
86 | | - for src_path in src_path_list: |
87 | | - for file_name in os.listdir(src_path): |
88 | | - if "py" in file_name and "init" not in file_name and os.path.isfile(os.path.join(src_path, file_name)): |
89 | | - if file_name != "samplesMain.py": |
| 73 | +def writePyContent(args,src_path,new_src_path,src_path_list,src_import_list,import_list): |
| 74 | + for file_name in os.listdir(src_path): |
| 75 | + if os.path.isfile(os.path.join(src_path, file_name)): |
| 76 | + file_name_suffix = re.search(r"\.(\w+)$", file_name).group(1) |
| 77 | + if file_name_suffix == "py": |
| 78 | + if "__init__.py" == file_name : |
| 79 | + if src_path not in src_path_list : |
| 80 | + with open(os.path.join(new_src_path, GetLastDir(src_path)) + ".py", "wb") as f1: |
| 81 | + with open(os.path.join(src_path, file_name), "rb") as f: |
| 82 | + try: |
| 83 | + content_list = str(f.read(), encoding="utf-8").split("\n") |
| 84 | + except: |
| 85 | + pass |
| 86 | + for content in content_list: |
| 87 | + if "import" in content or ("from" in content and "import" in content): |
| 88 | + edit = False |
| 89 | + for src_import in src_import_list: |
| 90 | + if "from" in content: |
| 91 | + prefix_list = content.split("from")[1].split("import")[0].split(".")[ |
| 92 | + :-1] |
| 93 | + prefix = "" |
| 94 | + if len(prefix_list) > 0: |
| 95 | + for text in prefix_list: |
| 96 | + prefix = prefix + text + "." |
| 97 | + if src_import in prefix.strip(): |
| 98 | + f1.write( |
| 99 | + (content.replace(prefix.strip(), "") + '\n').encode("utf-8")) |
| 100 | + if content not in import_list and "#" not in content and \ |
| 101 | + content[ |
| 102 | + 0] != " ": |
| 103 | + import_list.append(content) |
| 104 | + edit = True |
| 105 | + break |
| 106 | + if edit is False: |
| 107 | + f1.write((content + '\n').encode("utf-8")) |
| 108 | + if content not in import_list and "#" not in content and content[0] != " ": |
| 109 | + import_list.append(content) |
| 110 | + elif "JadeLog = JadeLogging" in content: |
| 111 | + if str_to_bool(args.use_jade_log): |
| 112 | + update_log = "\n JadeLog.INFO('{}-更新时间为:{}',True)\r".format( |
| 113 | + args.name + "V" + args.app_version, GetTimeStamp(), True) |
| 114 | + f1.write((content + update_log).encode("utf-8")) |
| 115 | + else: |
| 116 | + f1.write((content).encode("utf-8")) |
| 117 | + else: |
| 118 | + f1.write((content + "\n").encode("utf-8")) |
| 119 | + elif file_name != "samplesMain.py": |
90 | 120 | with open(os.path.join(new_src_path, file_name), "wb") as f1: |
91 | 121 | with open(os.path.join(src_path, file_name), "rb") as f: |
92 | 122 | try: |
@@ -165,6 +195,25 @@ def copyPy(args): |
165 | 195 | f1.write((content + "\n").encode("utf-8")) |
166 | 196 | else: |
167 | 197 | f1.write((content + '\n').encode("utf-8")) |
| 198 | + else: |
| 199 | + if os.path.isdir( os.path.join(src_path, file_name)) and "pycache" not in file_name: |
| 200 | + writePyContent(args, os.path.join(src_path, file_name), new_src_path,src_path_list,src_import_list, import_list) |
| 201 | + |
| 202 | +def copyPy(args): |
| 203 | + new_src_path = CreateSavePath("new_src") |
| 204 | + try: |
| 205 | + if str_to_bool(args.is_qt) is False: |
| 206 | + src_path_list = ["src"] |
| 207 | + src_import_list = ["src."] |
| 208 | + else: |
| 209 | + src_path_list = ["src", "view", "view/customView", "controller"] |
| 210 | + src_import_list = ["src.", "view.", "view.customView.", "controller."] |
| 211 | + except: |
| 212 | + src_path_list = ["src"] |
| 213 | + src_import_list = ["src."] |
| 214 | + import_list = [] |
| 215 | + for src_path in src_path_list: |
| 216 | + writePyContent(args,src_path,new_src_path,src_path_list,src_import_list,import_list) |
168 | 217 | if args.app_version: |
169 | 218 | with open("new_src/samplesVersion.py","wb") as f: |
170 | 219 | f.write('#!/usr/bin/env python\n' |
|
0 commit comments