def checkUpdates(directory): """ Checks for MNPR updates online and lets the user decide what to do Args: directory (str): Directory of installed MNPR """ print "Checking for updates..." # get local mnpr version localPath = os.path.join(directory, "version.json") with open(localPath, 'r') as f: localMNPR = json.load(f) # get online mnpr version onlinePath = distURL + "/version.json" tempPath = os.path.join(directory, "onlineVersion.json") downloader = urllib.URLopener() try: downloader.retrieve(onlinePath, tempPath) except IOError: print "Maya can't connect to the internet.", return with open(tempPath, 'r') as f: onlineMNPR = json.load(f) os.remove(tempPath) # check versions localVer = localMNPR.pop("version") onlineVer = onlineMNPR.pop("version") if onlineVer <= localVer: return "Nothing to update" # delete unnecessary plugin entries depending on OS mayaV = int(lib.mayaVersion()) localOS = "win" if cmds.about(mac=True): localOS = "mac" elif cmds.about(linux=True): localOS = "linux" # search in local version keys2Delete = [] for key in localMNPR: if "/plugins/" in key: if "/{0}/{1}".format(mayaV, localOS) not in key: keys2Delete.append(key) continue # delete unnecessary local keys for key in keys2Delete: localMNPR.pop(key) # search in online version keys2Delete = [] for key in onlineMNPR: if "/plugins/" in key: if "/{0}/{1}".format(mayaV, localOS) not in key: keys2Delete.append(key) continue # delete unnecessary online keys for key in keys2Delete: onlineMNPR.pop(key) print "LOCAL" pprint.pprint(localMNPR) print "\nONLINE" pprint.pprint(onlineMNPR) # compare the two versions files2Update = [] for key in onlineMNPR: if key in localMNPR: for file in onlineMNPR[key]: if file in localMNPR[key]: if onlineMNPR[key][file]>localMNPR[key][file]: # online file is newer than local file, download files2Update.append("{0}/{1}".format(key, file)) else: # file doesn't exist locally, download files2Update.append("{0}/{1}".format(key, file)) else: for file in onlineMNPR[key]: files2Update.append("{0}/{1}".format(key, file)) files2Delete = [] for key in localMNPR: if key in onlineMNPR: for file in localMNPR[key]: if file not in onlineMNPR[key]: files2Delete.append("{0}/{1}".format(key, file)) else: for file in localMNPR[key]: files2Delete.append("{0}/{1}".format(key, file)) # check if a shelf needs to update, as Maya would then require a restart restartMaya = False for f2u in files2Update: if "/shelves/" in f2u: restartMaya = True for f2d in files2Delete: if "/shelves/" in f2d: restartMaya = True # update prompt mString = "An update for MNPR is available, do you wish to download and install this update?\n\n" mString += "Files to be updated:\n" if files2Update: for fUpdate in files2Update: mString += "-. {0}\n".format(fUpdate) else: mString += "- None -\n" mString += "\nFiles to be deleted:\n" if files2Delete: for fDelete in files2Delete: mString += "-. {0}\n".format(fDelete) else: mString += "- None -\n" reply = cmds.confirmDialog(title='Update is available', message=mString, button=['Yes', 'No'], defaultButton='Yes', cancelButton='No', dismissString='No', icn="information") # don't do anything if reply == "No": print "Nothing has been updated", return if restartMaya: mString = "The shelf will be updated, so Maya will close automatically after the update has concluded\n\n" mString += "No scenes/preferences will be saved upon closure, do you still wish to proceed?" reply = cmds.confirmDialog(title='Shelf update', message=mString, button=['Yes', 'No'], defaultButton='Yes', cancelButton='No', dismissString='No', icn="warning") if reply == "No": print "Nothing has been updated", return if updateMNPR(directory, files2Update, files2Delete): if restartMaya: cmds.quit(abort=True)
# / __/ _ \ / _ \| '_ \___ \ / _ \ __| | | | '_ \ # | (_| (_) | (_) | |_) |__) | __/ |_| |_| | |_) | # \___\___/ \___/| .__/____/ \___|\__|\__,_| .__/ # |_| |_| @summary: This file installs MNPRX by adding the required file directories into the Maya.env file @run: Drag and drop the install.mel file which runs coopSetup @contributors: Santiago Montesdeoca """ from __future__ import print_function import os, shutil, urllib, pprint import maya.cmds as cmds import maya.mel as mel import coopLib as lib # GET MAYA VERSION mayaV = int(lib.mayaVersion()) if mayaV < 2017: cmds.error("Plugin is only supported by Maya 2017, onwards.") # SETTLE OS DEPENDENT CASES localOS = lib.localOS() sep = ':' # separator if localOS == "win": sep = ';' def run(root): """ Insert system paths in the Maya.env Args: root: root directory of the plugin hierarchy