示例#1
0
def rollbackOTL(node=None):
    """Pulls a rollback window for the user to select a version to rollback to. EXACTLY ONE node may be selected, and it MUST be a digital asset.
	    The node must already exist in the database.
	"""
    print 'RollbackOTL'

    #Need to check if a particular node is a digital asset first. Rollback is will only work as a DA, with model, rigs and animation.
    if node != None:

        if not ham.isDigitalAsset(node):
            ui.infoWindow('Wait! You can only rollback Digital Assets!')
            print "NOT A DIGITAL ASSET."
        else:
            # First, we need to see if this is checked out or not. If it is checked out, then we can proceed. If not, state so.
            # For the productions path
            libraryPath = node.type().definition().libraryFilePath()
            filename = os.path.basename(libraryPath)

            asset_name, ext = os.path.splitext(filename)
            #print "asset_name " + asset_name
            toCheckout = os.path.join(ASSETSDIR, asset_name, 'otl')
            #print "toCheckout " + toCheckout
            myCheckout = False

            myCheckout = amu.isCheckedOut(toCheckout)
            if myCheckout:  #If it has been checked out
                myCheckout = amu.checkedOutByMe(toCheckout)
                if myCheckout:  #If user was the last to checkout
                    #Here we rollback.
                    versionedFolders = os.path.join(toCheckout, "src")
                    #print "versionedFolders ", versionedFolders
                    versions = glob.glob(os.path.join(versionedFolders, '*'))
                    #print "selections ", versions
                    #Wooohoooo!!!
                    selections = []
                    selectionInfo = []
                    nodeInfoDest = toCheckout

                    for vr in versions:
                        selections.append(os.path.basename(vr))
                        comment = amu.getVersionComment(
                            nodeInfoDest, os.path.basename(vr))
                        selectionInfo.append(comment)
                    selections.sort()
                    dialog = VersionDialog()
                    dialog.addItems(selections, selectionInfo)
                    dialog.show()
                    dialog.setParams(versionedFolders, asset_name, toCheckout,
                                     True)
                    pyqt_houdini.exec_(dialog)

                else:
                    hou.ui.displayMessage('Already checked out.')
                    return
            else:
                hou.ui.displayMessage('Please checkout asset first.')
    else:
        print "Node does not exist"
def rollbackOTL(node = None):
	"""Pulls a rollback window for the user to select a version to rollback to. EXACTLY ONE node may be selected, and it MUST be a digital asset.
	    The node must already exist in the database.
	"""
	print 'RollbackOTL'

	#Need to check if a particular node is a digital asset first. Rollback is will only work as a DA, with model, rigs and animation.
	if node != None:

		if not ham.isDigitalAsset(node):
			ui.infoWindow('Wait! You can only rollback Digital Assets!')
			print "NOT A DIGITAL ASSET."
		else:
			# First, we need to see if this is checked out or not. If it is checked out, then we can proceed. If not, state so.
			# For the productions path			
			libraryPath = node.type().definition().libraryFilePath()
			filename = os.path.basename(libraryPath)

			asset_name, ext = os.path.splitext(filename)
			#print "asset_name " + asset_name
			toCheckout = os.path.join(ASSETSDIR, asset_name, 'otl')
			#print "toCheckout " + toCheckout
			myCheckout = False

			myCheckout = amu.isCheckedOut(toCheckout)
			if myCheckout: #If it has been checked out
				myCheckout = amu.checkedOutByMe(toCheckout)
				if myCheckout: #If user was the last to checkout
					#Here we rollback.
					versionedFolders = os.path.join(toCheckout, "src")
					#print "versionedFolders ", versionedFolders
					versions = glob.glob(os.path.join(versionedFolders, '*'))
					#print "selections ", versions
					#Wooohoooo!!!
					selections = []
					selectionInfo = []
					nodeInfoDest = toCheckout

					for vr in versions:
						selections.append(os.path.basename(vr))
						comment = amu.getVersionComment(nodeInfoDest,os.path.basename(vr))
						selectionInfo.append(comment)
					selections.sort()
					dialog = VersionDialog()
					dialog.addItems(selections,selectionInfo)
					dialog.show()
					dialog.setParams(versionedFolders,asset_name,toCheckout,True)
					pyqt_houdini.exec_(dialog)
					
				else:
					hou.ui.displayMessage('Already checked out.')
					return
			else:
				hou.ui.displayMessage('Please checkout asset first.')
	else:
		print "Node does not exist"
def rollbackOTL(node = None):
	"""Pulls a rollback window for the user to select a version to rollback to. EXACTLY ONE node may be selected, and it MUST be a digital asset.
	    The node must already exist in the database.
	"""
	print 'RollbackOTL'

	ham.updateDB()

	#Need to check if a particular node is a digital asset first. Rollback is will only work as a DA, with model, rigs and animation.
	if node != None:

		if not ham.isDigitalAsset(node):
			ui.infoWindow('Wait! You can only rollback Digital Assets!')
			print "NOT A DIGITAL ASSET."
		else:
			# First, we need to see if this is checked out or not. If it is checked out, then we can proceed. If not, state so.
			# For the productions path			
			libraryPath = node.type().definition().libraryFilePath()
			filename = os.path.basename(libraryPath)

			asset_name, ext = os.path.splitext(filename)
			#print "asset_name " + asset_name
			toCheckout = os.path.join(ASSETSDIR, asset_name, 'otl')
			#print "toCheckout " + toCheckout
			myCheckout = False

			myCheckout = amu.isCheckedOut(toCheckout)
			if myCheckout: #If it has been checked out
				myCheckout = amu.checkedOutByMe(toCheckout)
				if myCheckout: #If user was the last to checkout
					#Here we rollback.
					versionedFolders = os.path.join(toCheckout, "src")
					#print "versionedFolders ", versionedFolders
					versions = glob.glob(os.path.join(versionedFolders, '*'))
					#print "selections ", versions
					#Wooohoooo!!!
					selections = []
					for vr in versions:
						selections.append(os.path.basename(vr))
					selections.sort()
					answer = hou.ui.selectFromList(selections, message='Select version to rollback:', exclusive=True)
					if answer:
						version = answer[0]
						versionStr = "%03d" % version

						newVersion = os.path.join(versionedFolders, "v" + versionStr)
						checkoutFilePath = os.path.join(amu.getUserCheckoutDir(), asset_name)


						rollingBack = hou.ui.displayMessage('WARNING: You are about to remove your most recent changes. Proceed at your own risk.', buttons=('Actually, I don\'t want to', 'Yes. Roll me back'), severity=hou.severityType.Warning, title=("Woah there, pardner!"))
						

						if (rollingBack):
							print "rollingBack"
							# Temporarily set the version to the rollback version, and check out.
							oldVersion = int(amu.tempSetVersion(toCheckout, version))
							oldVersionStr = "%03d" % oldVersion

							tempFilePath = os.path.join(checkoutFilePath + "_otl_" + versionStr)
							filePath = os.path.join(checkoutFilePath + "_otl_" + oldVersionStr)
							# Now that we've set the version, we will 
							amu.discard(filePath) # Hey! This is working!!!
							amu.checkout(toCheckout, True)

							# Reset the version number, and rename the checkout path to the most recent version.
							amu.tempSetVersion(toCheckout, oldVersion)
							correctCheckoutDest = amu.getCheckoutDest(toCheckout)
							os.rename(tempFilePath, correctCheckoutDest)
				else:
					hou.ui.displayMessage('Already checked out.')
					return
			else:
				hou.ui.displayMessage('Please checkout asset first.')				


			
	else:
		print "Node does not exist"