forked from JakobJK/modelChecker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
120 lines (93 loc) · 3.79 KB
/
setup.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'''
installer for modelChecker
'''
import os
import sys
import shutil
from os import path
from os import rename
from os import unlink
from distutils.dir_util import copy_tree
from time import sleep
homedir = os.path.expanduser('~')
mayaVersions = ['2016','2017','2018','2019','2020']
os = sys.platform
setupFilePath = path.dirname(path.abspath('__file__')) + '/'
def getOS():
if os == 'linux' or os == 'linux2':
# linux
mayaUserPath = homedir + '/Library/Preferences/Autodesk/maya/'
if path.exists(mayaUserPath):
return mayaUserPath
else:
print('Maya user path not found')
elif os == 'darwin':
# OS X
mayaUserPath = homedir + '/Library/Preferences/Autodesk/maya/'
if path.exists(mayaUserPath):
return mayaUserPath
else:
print('Maya user path not found')
elif os == 'win32':
# Windows
mayaUserPath = homedir + '/Documents/maya/'
if path.exists(mayaUserPath):
return mayaUserPath
else:
print('Maya user path not found')
def install():
mayaUserPath = getOS()
for mayaversion in mayaVersions:
### Insert config in "shelf_Custom.mel" file to add modelChecker button to Custom shelf
#
allMayaShelvesPath = []
allMayaShelvesPath.append(mayaUserPath + mayaversion + '/prefs/shelves/')
for mayaShelfPath in allMayaShelvesPath:
if path.exists(mayaShelfPath):
file1 = mayaShelfPath + 'shelf_Custom.mel'
file2 = setupFilePath + 'shelfIcon.mel'
file3 = mayaShelfPath + 'shelf_Custom.mel.tmp'
# Backup shelf_Custom.mel
shutil.copy(file1, file1 + '.bak')
# Append config text to file
filenames = [file1, file2]
with open(file3, 'w') as outfile:
for fname in filenames:
with open(fname) as infile:
outfile.write(infile.read())
# Remove first closure bracket to sanity code
# Read in the file
with open(file3, 'r') as file :
filedata = file.read()
# Replace the target string
filedata = filedata.replace('}', '', 1)
# Write the file out again
with open(file3, 'w') as file:
file.write(filedata)
# Restore original name
unlink(file1)
rename(file3, file1)
print('Adding modelChecker button to Maya ' + mayaversion + ' custom shelf...')
sleep(0.3)
# copy icon to Maya icons default folder
iconFile = 'modelChecker_icon.png'
iconSrc = setupFilePath + '/src/' + iconFile
iconTarget = mayaUserPath + mayaversion + '/prefs/icons/' + iconFile
shutil.copy(iconSrc, iconTarget)
print('Copying ' + iconFile + ' to ' + mayaUserPath + mayaversion + '/prefs/icons/')
sleep(0.3)
### Copy src contents to destination
#
allMayaScriptPath = []
allMayaScriptPath.append(mayaUserPath + mayaversion + '/scripts/')
for p in allMayaScriptPath:
if path.exists(p):
# copy subdirectory example
src = setupFilePath + '/src/'
target = p + '/modelChecker/'
copy_tree(src, target)
print('Copying modelChecker.py to ' + mayaUserPath + mayaversion + '/scripts/modelChecker/' )
sleep(0.3)
print('modelChecker installed successfully for Maya ' + mayaversion + '!\n')
getOS()
install()