Last active
December 11, 2020 17:49
-
-
Save gabosalinas/2914b04978e31044e59ed031905550dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from maya import cmds | |
from maya import mel | |
import urllib2 | |
import shutil | |
import zipfile | |
import os | |
from datetime import datetime | |
def formatPath(path): | |
path = path.replace("/", os.sep) | |
path = path.replace("\\", os.sep) | |
return path | |
def download(downloadUrl, saveFile):#downloadUrl, saveFile=DOWNLOAD_URL, tmpZipFile | |
try: response = urllib2.urlopen(downloadUrl, timeout=60) | |
except: pass | |
if response is None: | |
cmds.warning("Error trying to install.") | |
return | |
#fileSize = int(response.info().getheaders("Content-Range")[0]) | |
#fileSizeDl = 0 | |
blockSize = 128 | |
output = open(saveFile,'wb') | |
#progBar = mel.eval('$tmp = $gMainProgressBar') | |
''' | |
cmds.progressBar( progBar, | |
edit=True, | |
beginProgress=True, | |
status='Downloading ...', | |
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) | |
msg = 'Actualizacion terminada: <pipeline 03122020>' | |
cmds.confirmDialog( title='Avisonivi', message=msg, button=['OK'], defaultButton='OK' ) | |
return output | |
def validateDrive (driveLetter): | |
return os.path.isdir( driveLetter) | |
def warningDialog (): | |
titlemsg='Avisonivi' | |
savefilemsg = 'Cargaremos el pipe. Si ya tienes shelfs de la produccion, borralos, reinicia maya y ejecuta de nuevo el instalador.\nQuedara un zip de la descarga como backup en Z:/PIPELINE/tempfiles. ' | |
savefiledialog = cmds.confirmDialog( title=titlemsg, message=savefilemsg, button=['Run installer','Cancel execution'], defaultButton='Run installer', cancelButton='false', dismissString='false' ) | |
print savefiledialog | |
if savefiledialog=='Cancel execution' : | |
return False | |
else: | |
return True | |
def install(pipedrive): | |
pipedir = os.path.join(pipedrive,os.sep,'PIPELINE') | |
#targetdir = os.path.join(pipedir,'TARGETDIR') | |
today = datetime.now() | |
todaystr = today.strftime("%d_%m_%Y-%H%M%S") | |
tmpZipFile = ("%s%s%s%stmp-%s.zip"%(pipedir, os.sep, 'tempfiles' , os.sep ,todaystr )).replace('\\','/') | |
tempDir = os.path.dirname(tmpZipFile) | |
DOWNLOAD_URL = "https://drive.google.com/uc?export=download&id=1pX1bgMoi2hdEAvu7Ewos-AAVPbSybRZ2" | |
if not os.path.isdir ( tempDir ) : | |
os.makedirs(tempDir) | |
output = download(DOWNLOAD_URL, tmpZipFile) | |
#uncompress file | |
zfobj = zipfile.ZipFile(tmpZipFile) | |
for name in zfobj.namelist(): | |
uncompressed = zfobj.read(name) | |
# save uncompressed data to disk | |
filename = formatPath("%s%s%s"%(pipedrive, 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() | |
#refresh | |
def startInstall(): | |
pipedrive = 'Z:' | |
if not validateDrive(pipedrive): | |
msg='Mapea unidad Z y reintenta.' | |
cmds.confirmDialog( title='Avisonivi', message=msg, button=['OK'], defaultButton='OK' ) | |
return False | |
if not warningDialog(): | |
return False | |
install(pipedrive) | |
mel.eval ( 'loadNewShelf "Z:/PIPELINE/MAYA/SHELF/shelf_NIVIS_ANIM_02.mel";') | |
startInstall() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment