-
Notifications
You must be signed in to change notification settings - Fork 11
/
aTools_install.mel
175 lines (174 loc) · 8.05 KB
/
aTools_install.mel
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// ========================================================================================================================
// Author: Alan Camilo
// www.alancamilo.com
// Modified: Michael Klimenko
//
// Requirements: aTools Package
//
// ------------------------------------------------------------------------------------------------------------------------
// To install aTools, please follow the instructions in the file how_to_install.txt
//
// ------------------------------------------------------------------------------------------------------------------------
// To unistall aTools, go to menu (the last button on the right), Uninstall
//
// ========================================================================================================================
python("\n\
#aTools_install.mel\n\
\n\
from maya import cmds, mel\n\
import os, shutil, urllib.request, urllib.error, urllib.parse, shutil, zipfile, importlib\n\
\n\
def hasInternet(url):\n\
try:\n\
proxy = urllib.request.ProxyHandler({})\n\
opener = urllib.request.build_opener(proxy)\n\
urllib.request.install_opener(opener)\n\
response = urllib.request.urlopen(url, timeout=60)\n\
return True\n\
except: pass\n\
return False\n\
\n\
def launchInstall():\n\
INSTALL_URL = 'https://raw.githubusercontent.com/MKlimenko/aTools_python3/master/aToolsInstall.py' \n\
aToolsInstall = None\n\
if hasInternet(INSTALL_URL):\n\
try: \n\
aToolsInstall = urllib.request.urlopen(INSTALL_URL, timeout=60).read()\n\
except IOError: pass\n\
if aToolsInstall: exec(aToolsInstall)\n\
else: \n\
cmds.confirmDialog(title=\"aTools Install\", message=\"Internet connection not detected, offline installation will begin.\\n\\nIf you want aTools to auto update in the future, configure your firewall so that Maya can access the internet.\", button=\"Next\")\n\
offlineInstallWindow()\n\
\n\
\n\
def offlineInstallWindow():\n\
windowName = 'aToolsOfflineInstallationWindow'\n\
w = 500\n\
aToolsZipURL = 'https://github.com/MKlimenko/aTools_python3/releases/download/v2.04/aTools.zip'\n\
delWindow(windowName)\n\
window = cmds.window(windowName, title='aTools - Offline Installation')\n\
form = cmds.formLayout(numberOfDivisions=100)\n\
pos = 10 \n\
elements = [] \n\
elements.append([cmds.text( label='aTools - Offline Installation Instructions:', font='boldLabelFont'), 0])\n\
elements.append([cmds.text(label=\'1) Download <a href=\\'%s\\'>aTools.zip</a>\'%aToolsZipURL, align='left', hyperlink=True), 30])\n\
elements.append([cmds.text(label=\'In case you don\\'t have internet access at all, use the link below somewhere else.\', align='left'), 15])\n\
elements.append([cmds.textField(text=aToolsZipURL, w=w-20, editable=False), 20])\n\
elements.append([cmds.text(label=\'2) Create a folder for aTools.zip and keep the file there, aTools will remember this\\nlocation to install updates automatically. All you\\'ll need to do is replace aTools.zip when\\nnew versions come out. Subscribe in the above link to receive alerts.\', align='left'), 40])\n\
elements.append([cmds.text(label=\'If more people in your network are going to install aTools, place aTools.zip in a folder that\\neveryone has access to, so only one person will need to keep aTools.zip up-to-date.\', align='left'), 45])\n\
elements.append([cmds.text(label='3) OK, so where did you put it?', align='left'), 45])\n\
elements.append([cmds.rowLayout(numberOfColumns=3), 20])\n\
cmds.textField('aToolsZipField', text='...aTools.zip', w=w-85)\n\
cmds.button(label='Browse', command=browse, w=60)\n\
cmds.setParent('..')\n\
elements.append([cmds.button( label='Install aTools', w=150, command=lambda *args:install(windowName)), 30])\n\
\n\
for loopElement in elements:\n\
element = loopElement[0]\n\
pos += loopElement[1]\n\
cmds.formLayout(form, edit=True, attachForm=[(element, 'top', pos), (element, 'left', 10)] )\n\
\n\
cmds.showWindow(window) \n\
cmds.window(windowName, edit=True, widthHeight=(w, pos+40))\n\
\n\
\n\
def browse(*args):\n\
result = cmds.fileDialog2(fileFilter='aTools.zip', dialogStyle=2, fileMode=1, okCaption='OK')\n\
if result: cmds.textField('aToolsZipField', edit=True, text=result[0])\n\
\n\
def install(windowName):\n\
offlineFilePath = formatPath(cmds.textField('aToolsZipField', query=True, text=True))\n\
if offlineFilePath.split(os.sep)[-1] != 'aTools.zip':\n\
cmds.confirmDialog(message='Only aTools.zip is acceptable. Rename the file if needed.')\n\
return\n\
if not os.path.isfile(offlineFilePath): \n\
cmds.confirmDialog(message=\'Couldn\\'t find aTools.zip in there, please check if the path is correct.\')\n\
return\n\
delWindow(windowName)\n\
aToolsOfflineInstall(offlineFilePath)\n\
\n\
def delWindow(windowName):\n\
if cmds.window(windowName, query=True, exists=True): cmds.deleteUI(windowName)\n\
\n\
\n\
\n\
def formatPath(path):\n\
path = path.replace('/', os.sep)\n\
path = path.replace('\\\\', os.sep)\n\
return path\n\
\n\
def download(downloadUrl, saveFile):\n\
\n\
try: response = urllib.request.urlopen(downloadUrl, timeout=60) \n\
except: pass\n\
\n\
if response is None: \n\
cmds.warning('Error trying to install.')\n\
return \n\
\n\
fileSize = int(response.info().get('Content-Length')[0])\n\
fileSizeDl = 0\n\
blockSize = 128\n\
output = open(saveFile,'wb') \n\
progBar = mel.eval('$tmp = $gMainProgressBar') \n\
\n\
cmds.progressBar( progBar,\n\
edit=True,\n\
beginProgress=True,\n\
status='Downloading aTools...',\n\
progress=0,\n\
maxValue=100 ) \n\
\n\
while True:\n\
buffer = response.read(blockSize)\n\
if not buffer:\n\
output.close()\n\
cmds.progressBar(progBar, edit=True, progress=100) \n\
cmds.progressBar(progBar, edit=True, endProgress=True) \n\
break\n\
\n\
fileSizeDl += len(buffer)\n\
output.write(buffer)\n\
p = float(fileSizeDl) / fileSize *100\n\
\n\
cmds.progressBar(progBar, edit=True, progress=p) \n\
\n\
return output\n\
\n\
\n\
def aToolsOfflineInstall(offlineFilePath):\n\
\n\
mayaAppDir = mel.eval('getenv MAYA_APP_DIR') \n\
aToolsPath = mayaAppDir + os.sep + 'scripts'\n\
aToolsFolder = aToolsPath + os.sep + 'aTools' + os.sep\n\
tmpZipFile = '%s%stmp.zip'%(aToolsPath, os.sep)\n\
offlineFileUrl = r'file:///%s'%offlineFilePath\n\
\n\
if os.path.isfile(tmpZipFile): os.remove(tmpZipFile) \n\
if os.path.isdir(aToolsFolder): shutil.rmtree(aToolsFolder) \n\
\n\
output = download(offlineFileUrl, tmpZipFile) \n\
\n\
zfobj = zipfile.ZipFile(tmpZipFile)\n\
for name in zfobj.namelist():\n\
uncompressed = zfobj.read(name)\n\
\n\
filename = formatPath('%s%s%s'%(aToolsPath, os.sep, name)) \n\
d = os.path.dirname(filename)\n\
\n\
if not os.path.exists(d): os.makedirs(d)\n\
if filename.endswith(os.sep): continue\n\
\n\
output = open(filename,'wb')\n\
output.write(uncompressed)\n\
output.close()\n\
\n\
zfobj.close()\n\
if os.path.isfile(tmpZipFile): os.remove(tmpZipFile)\n\
from aTools import setup; importlib.reload(setup); setup.install([offlineFilePath, True]) \n\
cmds.confirmDialog(message=\'A file aTools_offline_install.mel has been created in the same aTools.zip location. If other people in your network are installing aTools, just ask them to drag\\'n drop this file into Maya\\'s viewport.\')\n\
cmds.evalDeferred(\"from aTools.animTools.animBar import animBarUI; importlib.reload(animBarUI); animBarUI.show(\\'refresh\\')\") \n\
\n\
\n\
launchInstall()\n\
");