Metapipe/freeInstaller.py

74 lines
3.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import shutil
import sys
if getattr(sys, 'frozen', False):
# 在捆绑中运行PyInstaller
source_folder = os.path.dirname(sys.executable)
source_folder = os.path.join(source_folder, "metapipeFree")
else:
# 在正常Python环境中运行
source_folder = os.path.dirname(os.path.abspath(__file__))
source_folder_data = os.path.join(source_folder, "data")
source_folder_icons = os.path.join(source_folder, "Icons")
source_folder_scripts = os.path.join(source_folder, "scripts")
destination_folder = "C:/Arts and Spells/Metapipe Free 3.0.0"
destination_folder_data = destination_folder + "/data"
destination_folder_icons = destination_folder + "/Icons"
destination_folder_scripts = "C:/Arts and Spells/Scripts"
def move_files(source_folder, destination_folder):
files = os.listdir(source_folder)
os.makedirs(destination_folder, exist_ok=True)
os.makedirs(destination_folder_scripts, exist_ok=True)
for file_name in files:
source = os.path.join(source_folder, file_name)
destination = os.path.join(destination_folder, file_name)
if os.path.isfile(source): # 检查项是否为文件
try:
shutil.copy(source, destination)
except PermissionError as e:
print(f"Permission error: {e}")
# 根据需要处理权限错误
def run():
if not source_folder == destination_folder:
try:
os.makedirs(destination_folder, exist_ok=True)
move_files(source_folder, destination_folder)
move_files(source_folder_data, destination_folder_data)
move_files(source_folder_icons, destination_folder_icons)
move_files(source_folder_scripts, destination_folder_scripts)
print("Installation completed successfully.")
except Exception as e:
print(f"An Error occurred: {e}")
else:
print("Installation already completed.")
shelfCH = 0
shelves_folder = os.path.expanduser("~/Documents/maya/2023/prefs/shelves")
if os.path.exists(shelves_folder):
shutil.copy(os.path.join(source_folder, "shelf_MetapipeFree.mel"), shelves_folder)
shelfCH = 1
shelves_folder = os.path.expanduser("~/Documents/maya/2023/zh_CN/prefs/shelves")
if os.path.exists(shelves_folder):
shutil.copy(os.path.join(source_folder, "shelf_MetapipeFree.mel"), shelves_folder)
shelfCH = 1
shelves_folder = os.path.expanduser("~/Documents/maya/2023/ja_JP/prefs/shelves")
if os.path.exists(shelves_folder):
shutil.copy(os.path.join(source_folder, "shelf_MetapipeFree.mel"), shelves_folder)
shelfCH = 1
shelves_folder = os.path.expanduser("~/Documents/maya/2023/en_US/prefs/shelves")
if os.path.exists(shelves_folder):
shutil.copy(os.path.join(source_folder, "shelf_MetapipeFree.mel"), shelves_folder)
shelfCH = 1
if shelfCH == 0:
print("ERROR: Maya folder is not in Default Place. Please find shelf folder of Maya and copy and paste 'shelf_MetaPipeFree' file manually.")