From 8ec4bfb6b46fda892f52f7780939fa1c91363b28 Mon Sep 17 00:00:00 2001 From: "m.klimenko" Date: Tue, 1 Mar 2022 22:30:26 +0300 Subject: [PATCH] Add modified aToolsInstall --- aToolsInstall.py | 84 ++++++++++++++++++++++++++++++++++++++++++++++ aTools_install.mel | 2 +- 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 aToolsInstall.py diff --git a/aToolsInstall.py b/aToolsInstall.py new file mode 100644 index 0000000..2313aa7 --- /dev/null +++ b/aToolsInstall.py @@ -0,0 +1,84 @@ +from maya import cmds, mel +import os, shutil, urllib.request, urllib.error, urllib.parse, shutil, zipfile, importlib + +def formatPath(path): + path = path.replace('/', os.sep) + path = path.replace('\\', os.sep) + return path + +def download(downloadUrl, saveFile): + + try: response = urllib.request.urlopen(downloadUrl, timeout=60) + except: pass + + if response is None: + cmds.warning('Error trying to install.') + return + + fileSize = int(response.info().get('Content-Length')[0]) + fileSizeDl = 0 + blockSize = 128 + output = open(saveFile,'wb') + progBar = mel.eval('$tmp = $gMainProgressBar') + + cmds.progressBar( progBar, + edit=True, + beginProgress=True, + status='Downloading aTools...', + progress=0, + maxValue=100 ) + + while True: + buffer = response.read(blockSize) + if not buffer: + output.close() + cmds.progressBar(progBar, edit=True, progress=100) + cmds.progressBar(progBar, edit=True, endProgress=True) + break + + fileSizeDl += len(buffer) + output.write(buffer) + p = float(fileSizeDl) / fileSize *100 + + cmds.progressBar(progBar, edit=True, progress=p) + + return output + + +def aToolsInstall(): + + mayaAppDir = mel.eval('getenv MAYA_APP_DIR') + aToolsPath = mayaAppDir + os.sep + "scripts" + aToolsFolder = aToolsPath + os.sep + "aTools" + os.sep + tmpZipFile = "%s%stmp.zip"%(aToolsPath, os.sep) + DOWNLOAD_URL = "http://www.trickorscript.com/aTools/aTools.zip" + + if os.path.isfile(tmpZipFile): os.remove(tmpZipFile) + if os.path.isdir(aToolsFolder): shutil.rmtree(aToolsFolder) + + output = download(DOWNLOAD_URL, tmpZipFile) + + zfobj = zipfile.ZipFile(tmpZipFile) + for name in zfobj.namelist(): + uncompressed = zfobj.read(name) + + filename = formatPath('%s%s%s'%(aToolsPath, os.sep, name)) + d = os.path.dirname(filename) + + if not os.path.exists(d): os.makedirs(d) + if filename.endswith(os.sep): continue + + output = open(filename,'wb') + output.write(uncompressed) + output.close() + + #delete temp + zfobj.close() + if os.path.isfile(tmpZipFile): os.remove(tmpZipFile) + + from aTools import setup; setup.install() + + #refresh + cmds.evalDeferred("from aTools.animTools.animBar import animBarUI; importlib.reload(animBarUI); animBarUI.show('refresh')") + +aToolsInstall() \ No newline at end of file diff --git a/aTools_install.mel b/aTools_install.mel index adeb15c..85735d3 100644 --- a/aTools_install.mel +++ b/aTools_install.mel @@ -23,7 +23,7 @@ def hasInternet(url):\n\ return False\n\ \n\ def launchInstall():\n\ - INSTALL_URL = 'http://www.trickorscript.com/aTools/aToolsInstall.py' \n\ + INSTALL_URL = 'https://raw.githubusercontent.com/MKlimenko/aTools_python3/master/aToolsInstall.py' \n\ aToolsInstall = None\n\ if hasInternet(INSTALL_URL):\n\ try: \n\