def rename(node = None): """Renames the selected node. EXACTLY ONE node may be selected, and it MUST be a digital asset. The node must already exist in the database. """ if node != None: if not isDigitalAsset(node): hou.ui.displayMessage("Not a Digital Asset.") else: if isContainer(node): oldlibraryPath = node.type().definition().libraryFilePath() oldfilename = os.path.basename(oldlibraryPath) oldAssetName = oldfilename.split('.')[0] assetDirPath = os.path.join(ASSETSDIR, oldAssetName) dependents = getAssetDependents(oldAssetName) if dependents: hou.ui.displayMessage('The following assets are depenent on this asset: \n\n'+printList(dependents)+'\nModify these assets first before attempting to rename again!!', title='Can NOT rename!', severity=hou.severityType.Error) return nodeDir = os.path.join(os.environ['ASSETS_DIR'], oldAssetName, 'otl') info = amu.getVersionedFolderInfo(nodeDir); if info[0] == "": if passwordWindow('r3n@m3p@ssw0rd', 'Enter the rename password...'): resp = hou.ui.readInput("Enter the New Operator Label", title="Rename OTL") if resp != None and resp[1].strip() != '': name = formatName(resp[1]) newfilename = name.replace(' ', '_') newfilepath = os.path.join(OTLDIR, newfilename+'.otl') oldfilepath = os.path.join(OTLDIR, oldAssetName+'.otl') if os.path.exists(newfilepath): hou.ui.displayMessage("Asset by that name already exists. Cannot rename asset.", title='Asset Name', severity=hou.severityType.Error) elif not amu.canRename(assetDirPath, newfilename): hou.ui.displayMessage("Asset checked out in Maya. Cannot rename asset.", title='Asset Name', severity=hou.severityType.Error) else: node.type().definition().copyToHDAFile(newfilepath, new_name=newfilename, new_menu_name=name) hou.hda.installFile(newfilepath, change_oplibraries_file=True) newnode = hou.node(new_asset_methods.determineHPATH()).createNode(newfilename) node.destroy() hou.hda.uninstallFile(oldlibraryPath, change_oplibraries_file=False) subprocess.check_call( ['rm','-f',oldlibraryPath] ) amu.renameAsset(assetDirPath, newfilename) newNodeDir = os.path.join(os.environ['ASSETS_DIR'], newfilename, 'otl') newStableNode = newfilename + '_otl_stable.otl' newOldStableNode = oldAssetName + '_otl_stable.otl' newDest = os.path.join(newNodeDir, 'stable', newStableNode) newOldDest = os.path.join(newNodeDir, 'stable', newOldStableNode) os.remove(newOldDest) shutil.move(newfilepath,newDest) os.symlink(newDest, newfilepath) else: logname, realname = amu.lockedBy(info[0].encode('utf-8')) whoLocked = 'User Name: ' + logname + '\nReal Name: ' + realname + '\n' errstr = 'Cannot checkout asset. Locked by: \n\n' + whoLocked hou.ui.displayMessage(errstr, title='Asset Locked', severity=hou.severityType.Error) else: hou.ui.displayMessage("Select EXACTLY one node.")
def rename(node = None): """Renames the selected node. EXACTLY ONE node may be selected, and it MUST be a digital asset. The node must already exist in the database. """ updateDB() if node != None: if not isDigitalAsset(node): ui.infoWindow("Not a Digital Asset.") else: if isContainer(node): oldlibraryPath = node.type().definition().libraryFilePath() oldfilename = os.path.basename(oldlibraryPath) oldAssetName = oldfilename.split('.')[0] assetDirPath = os.path.join(ASSETSDIR, oldAssetName) dependents = getAssetDependents(oldAssetName) if dependents: ui.infoWindow('The following assets are depenent on this asset: \n\n'+printList(dependents)+'\nModify these assets first before attempting to rename again!!', wtitle='Can NOT rename!', msev=messageSeverity.Error) return info = getFileInfo(oldfilename) if not info[2]: if ui.passwordWindow('r3n@m3p@ssw0rd', wmessage='Enter the rename password...'): resp = ui.inputWindow("Enter the New Operator Label", wtitle="Rename OTL") if resp != None and resp.strip() != '': name = formatName(resp) newfilename = name.replace(' ', '_') newfilepath = os.path.join(OTLDIR, newfilename+'.otl') if os.path.exists(newfilepath): ui.infoWindow("Asset by that name already exists. Cannot rename asset.", wtitle='Asset Name', msev=messageSeverity.Error) elif not amu.canRename(assetDirPath, newfilename): ui.infoWindow("Asset checked out in Maya. Cannot rename asset.", wtitle='Asset Name', msev=messageSeverity.Error) else: node.type().definition().copyToHDAFile(newfilepath, new_name=newfilename, new_menu_name=name) hou.hda.installFile(newfilepath, change_oplibraries_file=True) newnode = hou.node(determineHPATH()).createNode(newfilename) node.destroy() hou.hda.uninstallFile(oldlibraryPath, change_oplibraries_file=False) subprocess.check_call( ['rm','-f',oldlibraryPath] ) amu.renameAsset(assetDirPath, newfilename) else: logname, realname = amu.lockedBy(info[3].encode('utf-8')) whoLocked = 'User Name: ' + logname + '\nReal Name: ' + realname + '\n' errstr = 'Cannot checkout asset. Locked by: \n\n' + whoLocked ui.infoWindow(errstr, wtitle='Asset Locked', msev=messageSeverity.Error) else: ui.infoWindow("Select EXACTLY one node.")
def rename(): """Renames the selected node. EXACTLY ONE node may be selected, and it MUST be a digital asset. The node must already exist in the database. """ updateDB() node = getSelectedNode() if node != None: if not isDigitalAsset(node): hou.ui.displayMessage("Not a Digital Asset.") else: if isContainer(node): oldlibraryPath = node.type().definition().libraryFilePath() oldfilename = os.path.basename(oldlibraryPath) oldAssetName = oldfilename.split('.')[0] assetDirPath = os.path.join(ASSETSDIR, oldAssetName) info = getFileInfo(oldfilename) if not info[2]: pok, presp = hou.ui.readMultiInput("Enter the rename password...", input_labels=('Password:'******'OK', 'Cancel'), title="Rename Password") presp = presp[0] if pok != 0 or presp != 'r3n@m3p@ssw0rd': hou.ui.displayMessage("Incorrect password. Better luck next time.", title='Incorrect Password', severity=hou.severityType.Error) return ok, resp = hou.ui.readInput("Enter the New Operator Label", buttons=('OK', 'Cancel'), title="Rename OTL") if ok == 0 and resp.strip() != '': name = formatName(resp) newfilename = name.replace(' ', '_') newfilepath = os.path.join(OTLDIR, newfilename+'.otl') if os.path.exists(newfilepath): hou.ui.displayMessage("Asset by that name already exists. Cannot rename asset.", title='Asset Name', severity=hou.severityType.Error) elif not amu.canRename(assetDirPath, newfilename): hou.ui.displayMessage("Asset checked out in Maya. Cannot rename asset.", title='Asset Name', severity=hou.severityType.Error) else: node.type().definition().copyToHDAFile(newfilepath, new_name=newfilename, new_menu_name=name) hou.hda.installFile(newfilepath, change_oplibraries_file=True) newnode = hou.node(determineHPATH()).createNode(newfilename) node.destroy() hou.hda.uninstallFile(oldlibraryPath, change_oplibraries_file=False) os.system('rm -f '+oldlibraryPath) amu.renameAsset(assetDirPath, newfilename) else: hou.ui.displayMessage(lockedBy(info[3].encode('utf-8'))) else: hou.ui.displayMessage("Select EXACTLY one node.")
def rename(): """Renames the selected node. EXACTLY ONE node may be selected, and it MUST be a digital asset. The node must already exist in the database. """ updateDB() node = getSelectedNode() if node != None: if not isDigitalAsset(node): ui.infoWindow("Not a Digital Asset.") else: if isContainer(node): oldlibraryPath = node.type().definition().libraryFilePath() oldfilename = os.path.basename(oldlibraryPath) oldAssetName = oldfilename.split('.')[0] assetDirPath = os.path.join(ASSETSDIR, oldAssetName) info = getFileInfo(oldfilename) if not info[2]: if ui.passwordWindow('r3n@m3p@ssw0rd', wmessage='Enter the rename password...'): resp = ui.inputWindow("Enter the New Operator Label", wtitle="Rename OTL") if resp != None and resp.strip() != '': name = formatName(resp) newfilename = name.replace(' ', '_') newfilepath = os.path.join(OTLDIR, newfilename+'.otl') if os.path.exists(newfilepath): ui.infoWindow("Asset by that name already exists. Cannot rename asset.", wtitle='Asset Name', msev=messageSeverity.Error) elif not amu.canRename(assetDirPath, newfilename): ui.infoWindow("Asset checked out in Maya. Cannot rename asset.", wtitle='Asset Name', msev=messageSeverity.Error) else: node.type().definition().copyToHDAFile(newfilepath, new_name=newfilename, new_menu_name=name) hou.hda.installFile(newfilepath, change_oplibraries_file=True) newnode = hou.node(determineHPATH()).createNode(newfilename) node.destroy() hou.hda.uninstallFile(oldlibraryPath, change_oplibraries_file=False) os.system('rm -f '+oldlibraryPath) amu.renameAsset(assetDirPath, newfilename) else: ui.infoWindow(lockedBy(info[3].encode('utf-8'))) else: ui.infoWindow("Select EXACTLY one node.")
def rename(node=None): """Renames the selected node. EXACTLY ONE node may be selected, and it MUST be a digital asset. The node must already exist in the database. """ if node != None: if not isDigitalAsset(node): hou.ui.displayMessage("Not a Digital Asset.") else: if isContainer(node): oldlibraryPath = node.type().definition().libraryFilePath() oldfilename = os.path.basename(oldlibraryPath) oldAssetName = oldfilename.split('.')[0] assetDirPath = os.path.join(ASSETSDIR, oldAssetName) dependents = getAssetDependents(oldAssetName) if dependents: hou.ui.displayMessage( 'The following assets are depenent on this asset: \n\n' + printList(dependents) + '\nModify these assets first before attempting to rename again!!', title='Can NOT rename!', severity=hou.severityType.Error) return nodeDir = os.path.join(os.environ['ASSETS_DIR'], oldAssetName, 'otl') info = amu.getVersionedFolderInfo(nodeDir) if info[0] == "": if passwordWindow('r3n@m3p@ssw0rd', 'Enter the rename password...'): resp = hou.ui.readInput("Enter the New Operator Label", title="Rename OTL") if resp != None and resp[1].strip() != '': name = formatName(resp[1]) newfilename = name.replace(' ', '_') newfilepath = os.path.join(OTLDIR, newfilename + '.otl') oldfilepath = os.path.join(OTLDIR, oldAssetName + '.otl') if os.path.exists(newfilepath): hou.ui.displayMessage( "Asset by that name already exists. Cannot rename asset.", title='Asset Name', severity=hou.severityType.Error) elif not amu.canRename(assetDirPath, newfilename): hou.ui.displayMessage( "Asset checked out in Maya. Cannot rename asset.", title='Asset Name', severity=hou.severityType.Error) else: node.type().definition().copyToHDAFile( newfilepath, new_name=newfilename, new_menu_name=name) hou.hda.installFile( newfilepath, change_oplibraries_file=True) newnode = hou.node( new_asset_methods.determineHPATH( )).createNode(newfilename) node.destroy() hou.hda.uninstallFile( oldlibraryPath, change_oplibraries_file=False) subprocess.check_call( ['rm', '-f', oldlibraryPath]) amu.renameAsset(assetDirPath, newfilename) newNodeDir = os.path.join( os.environ['ASSETS_DIR'], newfilename, 'otl') newStableNode = newfilename + '_otl_stable.otl' newOldStableNode = oldAssetName + '_otl_stable.otl' newDest = os.path.join(newNodeDir, 'stable', newStableNode) newOldDest = os.path.join( newNodeDir, 'stable', newOldStableNode) os.remove(newOldDest) shutil.move(newfilepath, newDest) os.symlink(newDest, newfilepath) else: logname, realname = amu.lockedBy(info[0].encode('utf-8')) whoLocked = 'User Name: ' + logname + '\nReal Name: ' + realname + '\n' errstr = 'Cannot checkout asset. Locked by: \n\n' + whoLocked hou.ui.displayMessage(errstr, title='Asset Locked', severity=hou.severityType.Error) else: hou.ui.displayMessage("Select EXACTLY one node.")
def rename(node=None): """Renames the selected node. EXACTLY ONE node may be selected, and it MUST be a digital asset. The node must already exist in the database. """ updateDB() if node != None: if not isDigitalAsset(node): hou.ui.displayMessage("Not a Digital Asset.") else: if isContainer(node): oldlibraryPath = node.type().definition().libraryFilePath() oldfilename = os.path.basename(oldlibraryPath) oldAssetName = oldfilename.split(".")[0] assetDirPath = os.path.join(ASSETSDIR, oldAssetName) dependents = getAssetDependents(oldAssetName) if dependents: hou.ui.displayMessage( "The following assets are depenent on this asset: \n\n" + printList(dependents) + "\nModify these assets first before attempting to rename again!!", title="Can NOT rename!", severity=hou.severityType.Error, ) return info = getFileInfo(oldfilename) if not info[2]: # TODO: replace ui function if ui.passwordWindow("r3n@m3p@ssw0rd", "Enter the rename password..."): resp = hou.ui.displayMessage("Enter the New Operator Label", title="Rename OTL") if resp != None and resp.strip() != "": name = formatName(resp) newfilename = name.replace(" ", "_") newfilepath = os.path.join(OTLDIR, newfilename + ".otl") if os.path.exists(newfilepath): hou.ui.displayMessage( "Asset by that name already exists. Cannot rename asset.", title="Asset Name", severity=hou.severityType.Error, ) elif not amu.canRename(assetDirPath, newfilename): hou.ui.displayMessage( "Asset checked out in Maya. Cannot rename asset.", title="Asset Name", severity=hou.severityType.Error, ) else: node.type().definition().copyToHDAFile( newfilepath, new_name=newfilename, new_menu_name=name ) hou.hda.installFile(newfilepath, change_oplibraries_file=True) newnode = hou.node(determineHPATH()).createNode(newfilename) node.destroy() hou.hda.uninstallFile(oldlibraryPath, change_oplibraries_file=False) subprocess.check_call(["rm", "-f", oldlibraryPath]) amu.renameAsset(assetDirPath, newfilename) else: logname, realname = amu.lockedBy(info[3].encode("utf-8")) whoLocked = "User Name: " + logname + "\nReal Name: " + realname + "\n" errstr = "Cannot checkout asset. Locked by: \n\n" + whoLocked hou.ui.displayMessage(errstr, title="Asset Locked", severity=hou.severityType.Error) else: hou.ui.displayMessage("Select EXACTLY one node.")