|
6 | 6 | import ctypes
|
7 | 7 |
|
8 | 8 |
|
9 |
| -def resource_path(relative_path): |
| 9 | +def getResourcePath(relativePath: str | os.PathLike[str]) -> None: |
10 | 10 | if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
|
11 |
| - base_path = sys._MEIPASS |
| 11 | + basePath = sys._MEIPASS |
12 | 12 | else:
|
13 |
| - base_path = os.path.dirname(__file__) |
| 13 | + basePath = os.path.dirname(__file__) |
14 | 14 |
|
15 |
| - return os.path.join(base_path, relative_path) |
| 15 | + return os.path.join(basePath, relativePath) |
16 | 16 |
|
17 | 17 |
|
18 |
| -def extract_file(resource_name, dest_folder): |
19 |
| - resource_full_path = resource_path(resource_name) |
20 |
| - if not os.path.exists(resource_full_path): |
21 |
| - raise FileNotFoundError(f"Resource '{resource_name}' not found.") |
| 18 | +def extractFile(resourceName: str | os.PathLike[str], destinationFolder: str | os.PathLike[str]) -> None: |
| 19 | + fullResourcePath = getResourcePath(resourceName) |
| 20 | + if not os.path.exists(fullResourcePath): |
| 21 | + raise FileNotFoundError(f"Resource '{resourceName}' not found.") |
22 | 22 |
|
23 |
| - shutil.copy(resource_full_path, os.path.join(dest_folder, resource_name)) |
| 23 | + shutil.copy(fullResourcePath, os.path.join(destinationFolder, resourceName)) |
24 | 24 |
|
25 | 25 |
|
26 |
| -def move_folder(src_folder, dest_folder): |
27 |
| - if not os.path.exists(src_folder): |
28 |
| - print(f"Source folder '{src_folder}' does not exist.") |
29 |
| - return |
| 26 | +def move_folder(sourceFolder: str | os.PathLike[str], destinationFolder: str | os.PathLike[str]) -> None: |
| 27 | + if not os.path.exists(sourceFolder): |
| 28 | + raise FileNotFoundError(f"Source folder '{sourceFolder}' not found.") |
30 | 29 |
|
31 |
| - if not os.path.exists(dest_folder): |
32 |
| - print(f"Destination folder '{dest_folder}' does not exist. Creating it.") |
33 |
| - os.makedirs(dest_folder) |
34 |
| - |
35 |
| - dest_path = os.path.join(dest_folder, os.path.basename(src_folder)) |
| 30 | + dest_path = os.path.join(destinationFolder, os.path.basename(sourceFolder)) |
36 | 31 | if os.path.exists(dest_path):
|
37 | 32 | print("Path exists, removing it...")
|
38 | 33 | shutil.rmtree(dest_path)
|
39 | 34 |
|
40 |
| - shutil.move(src_folder, dest_folder) |
41 |
| - print(f"Successfully moved '{src_folder}' to '{dest_folder}'.") |
| 35 | + shutil.move(sourceFolder, destinationFolder) |
| 36 | + print(f"Successfully moved '{sourceFolder}' to '{destinationFolder}'.") |
42 | 37 |
|
43 | 38 |
|
44 |
| -def main(): |
| 39 | +def main() -> None: |
45 | 40 | if not ctypes.windll.shell32.IsUserAnAdmin():
|
46 | 41 | ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
|
47 | 42 |
|
48 |
| - destination_folder = os.path.expandvars(r"%appdata%\Autodesk\ApplicationPlugins") |
49 |
| - os.makedirs(destination_folder, exist_ok=True) |
50 |
| - with tempfile.TemporaryDirectory() as temp_dir: |
51 |
| - extract_file("SynthesisExporter.zip", temp_dir) |
52 |
| - with zipfile.ZipFile(os.path.join(temp_dir, "SynthesisExporter.zip"), "r") as zip_ref: |
53 |
| - zip_ref.extractall(temp_dir) |
| 43 | + destinationFolder = os.path.expandvars(r"%appdata%\Autodesk\ApplicationPlugins") |
| 44 | + os.makedirs(destinationFolder, exist_ok=True) |
| 45 | + with tempfile.TemporaryDirectory() as tempDir: |
| 46 | + extractFile("SynthesisExporter.zip", tempDir) |
| 47 | + with zipfile.ZipFile(os.path.join(tempDir, "SynthesisExporter.zip"), "r") as zip: |
| 48 | + zip.extractall(tempDir) |
54 | 49 |
|
55 |
| - src_folder = os.path.join(temp_dir, "synthesis.bundle") |
56 |
| - move_folder(src_folder, destination_folder) |
| 50 | + sourceFolder = os.path.join(tempDir, "synthesis.bundle") |
| 51 | + move_folder(sourceFolder, destinationFolder) |
57 | 52 |
|
58 | 53 |
|
59 | 54 | if __name__ == "__main__":
|
|
0 commit comments