def makeBackup(): ''' make backup of script ''' #get script name and make folder if not exist script = nuke.root().name() scriptName = (nuke.root().name().split("/")[-1]).replace(".nk","") operation=blackboxHelper.getBackupSettings("@operation", backupSettings) backupPath=blackboxHelper.getBackupSettings("@backupPath", backupSettings) numberOfBackups=int(blackboxHelper.getBackupSettings("@numberOfBackups", backupSettings)) if backupMinute == True: t = time.strftime("%y%m%d-%H%M") else: t = time.strftime("%y%m%d-%H%M%S") # global dir if operation=="0.0": if not os.path.isdir(backupPath+"/"+scriptName): os.makedirs(backupPath+"/"+scriptName) try: nuke.removeOnScriptSave(makeBackup) nuke.scriptSave(backupPath+"/"+scriptName+"/bckp_"+t+"_"+scriptName+".nk") nuke.addOnScriptSave(makeBackup) except Exception, e: nuke.message("couldn't write a backup file") deleteOlderBackupVersions(backupPath+"/"+scriptName)
def do_backup(): """ Saves script into BACKUP_DIR folder after each save. If more then KEEP_VERSIONS files are present, deletes them Returns: None """ if not os.path.isdir(BACKUP_DIR): try: os.mkdir(BACKUP_DIR) except: nuke.message("Cannot create backup folder {}".format(BACKUP_DIR)) current_time_str = time.strftime("%Y%m%d_%H%M") backup_file_url = "{}/bckp_{}_{}.nknc".format(BACKUP_DIR, get_script_name(), current_time_str) try: import shutil nuke.removeOnScriptSave(do_backup) #remove call on save to limit recursion nuke.scriptSave(backup_file_url) nuke.addOnScriptSave(do_backup) delete_old_version() except IOError as e: nuke.message("Cannot write file {}, {}".format(backup_file_url,e))
def makeBackup(): ''' make backup of script ''' #get script name and make folder if not exist script = nuke.root().name() scriptName = (nuke.root().name().split("/")[-1]).replace(".nk", "") operation = blackboxHelper.getBackupSettings("@operation", backupSettings) backupPath = blackboxHelper.getBackupSettings("@backupPath", backupSettings) numberOfBackups = int( blackboxHelper.getBackupSettings("@numberOfBackups", backupSettings)) if backupMinute == True: t = time.strftime("%y%m%d-%H%M") else: t = time.strftime("%y%m%d-%H%M%S") # global dir if operation == "0.0": if not os.path.isdir(backupPath + "/" + scriptName): os.makedirs(backupPath + "/" + scriptName) try: nuke.removeOnScriptSave(makeBackup) nuke.scriptSave(backupPath + "/" + scriptName + "/bckp_" + t + "_" + scriptName + ".nk") nuke.addOnScriptSave(makeBackup) except Exception, e: nuke.message("couldn't write a backup file") deleteOlderBackupVersions(backupPath + "/" + scriptName)
def init_app(self): """ Called as the application is being initialized """ # this app should not do anything if nuke is run without gui. if nuke.env['gui']: # remove callbacks from sharedNuke menu.py nuke.removeOnScriptLoad(nozonscripts.setOCIO) nuke.removeOnScriptSave(nozonscripts.setOCIO) nuke.removeOnCreate(nozonscripts.setOCIOContext, nodeClass='OCIODisplay') # first deal with nuke root settings: we don't need a context for this self._setOCIOSettingsOnRootNode( ) # if I don't do this and do a File/New in Nuke, the new instance of nuke does not set the OCIO settings on the root node. self._add_root_callbacks() self.log_debug("Loading tk-nuke-ocio app.") if self.context.entity is not None: self.event = self.context.entity['name'] self.camera_colorspace = self._getCameraColorspaceFromShotgun() self._setOCIOSettingsOnRootNode() self._setOCIODisplayContext() self._add_callbacks() self.log_debug( "The camera colorspace for '%s' has been fetched from Shotgun and is '%s'" % (self.event, self.camera_colorspace)) else: pass
def unset_open_file_callback(self, func=None, callback=None): """ unset_open_file_callback will remove a callback function for when a file is opened """ if func: nuke.removeOnScriptSave(func) nuke.removeOnScriptLoad(func)
def savebackup(): save = backupfolder() + '/' + time.strftime( '%Y_%m_%d_%H_%M', time.localtime( time.time())) + '_' + os.path.basename( nuke.root().name()).split('.')[0] + '.nk' try: nuke.removeOnScriptSave(savebackup) nuke.scriptSave(save) nuke.addOnScriptSave(savebackup) except: nuke.message('Backup failed!(Pr_ToolKit)')
def toggleBackupProcess(): ''' enable/disable blackbox - set by value in blackbox.set ''' #reload settings enableBackup=blackboxHelper.getBackupSettings("@enableBackup", backupSettings) backupPath=blackboxHelper.getBackupSettings("@backupPath", backupSettings) operation=blackboxHelper.getBackupSettings("@operation", backupSettings) numberOfBackups=blackboxHelper.getBackupSettings("@numberOfBackups", backupSettings) if enableBackup == "1.0": nuke.addOnScriptSave(makeBackup) else: nuke.removeOnScriptSave(makeBackup)
def make_backup(): script_name = get_script_name() script_backup_dir = "{}/{}".format(backup_dir, script_name) current_time = time.strftime("%y%m%d-%H%M") if not os.path.isdir(script_backup_dir): os.makedirs(script_backup_dir) try: nuke.removeOnScriptSave(make_backup) nuke.scriptSave("{}/backup_{}_{}.nk".format(script_backup_dir, current_time, script_name)) nuke.addOnScriptSave(make_backup) except: nuke.message("Could't write a backup file!!") delete_older_backup_versions(script_backup_dir)
def toggleBackupProcess(): ''' enable/disable blackbox - set by value in blackbox.set ''' #reload settings enableBackup = blackboxHelper.getBackupSettings("@enableBackup", backupSettings) backupPath = blackboxHelper.getBackupSettings("@backupPath", backupSettings) operation = blackboxHelper.getBackupSettings("@operation", backupSettings) numberOfBackups = blackboxHelper.getBackupSettings("@numberOfBackups", backupSettings) if enableBackup == "1.0": nuke.addOnScriptSave(makeBackup) else: nuke.removeOnScriptSave(makeBackup)
def make_save(): """ 保存备份文件 """ script_name = get_script_name() project_name = script_name.split("_")[0] shot_name = "_".join(script_name.split("_")[1:-3]) script_backup_dir = "{}/{}/{}".format(backup_dir, project_name, shot_name) current_time = time.strftime("%m%d_%H%M") if not os.path.isdir(script_backup_dir): os.makedirs(script_backup_dir) try: nuke.removeOnScriptSave(make_save) nuke.scriptSave("{}/{}_{}.nk".format(script_backup_dir, script_name, current_time)) nuke.addOnScriptSave(make_save) except: nuke.message(u"没有需要备份的文件") del_older_backup_version(script_backup_dir)
def make_backup(): """ make backup of script :returns: none """ script_name = get_current_script_name() script_backup_dir = "{}/{}".format(BACKUP_DIR, script_name) current_time = time.strftime("%Y%m%d-%H%M") if not os.path.isdir(script_backup_dir): os.makedirs(script_backup_dir) try: nuke.removeOnScriptSave(make_backup) nuke.scriptSave("{}/bckp_{}_{}.nk".format(script_backup_dir, current_time, script_name)) nuke.addOnScriptSave(make_backup) except: nuke.message("Couldn't write a backup file") delete_older_backup_versions(script_backup_dir)
def tank_ensure_callbacks_registered(engine=None): """ Make sure that we have callbacks tracking context state changes. The OnScriptLoad callback really only comes into play when you're opening a file or creating a new script, when there is no current script open in your Nuke session. If there is a script currently open then this will spawn a new Nuke instance and the callback won't be called. """ global g_tank_callbacks_registered # Register only if we're missing an engine (to allow going from disabled to something else) # or if the engine specifically requests for it. if not engine or engine.get_setting("automatic_context_switch"): if not g_tank_callbacks_registered: nuke.addOnScriptLoad(sgtk_on_load_callback) nuke.addOnScriptSave(__sgtk_on_save_callback) g_tank_callbacks_registered = True elif engine and not engine.get_setting("automatic_context_switch"): # we have an engine but the automatic context switching has been disabled, we should ensure the callbacks # are removed. if g_tank_callbacks_registered: nuke.removeOnScriptLoad(sgtk_on_load_callback) nuke.removeOnScriptSave(__sgtk_on_save_callback) g_tank_callbacks_registered = False
def tank_ensure_callbacks_registered(engine=None): """ Make sure that we have callbacks tracking context state changes. The OnScriptLoad callback really only comes into play when you're opening a file or creating a new script, when there is no current script open in your Nuke session. If there is a script currently open then this will spawn a new Nuke instance and the callback won't be called. """ # Register only if we're missing an engine (to allow going from disabled to something else) # or if the engine specifically requests for it. if not engine or engine.get_setting("automatic_context_switch"): global g_tank_callbacks_registered if not g_tank_callbacks_registered: nuke.addOnScriptLoad(sgtk_on_load_callback) nuke.addOnScriptSave(__sgtk_on_save_callback) g_tank_callbacks_registered = True elif engine and not engine.get_setting("automatic_context_switch"): # we have an engine but the automatic context switching has been disabled, we should ensure the callbacks # are removed. global g_tank_callbacks_registered if g_tank_callbacks_registered: nuke.removeOnScriptLoad(sgtk_on_load_callback) nuke.removeOnScriptSave(__sgtk_on_save_callback) g_tank_callbacks_registered = False
nuke.removeOnScriptSave(makeBackup) nuke.scriptSave(backupPath + "/" + scriptName + "/bckp_" + t + "_" + scriptName + ".nk") nuke.addOnScriptSave(makeBackup) except Exception, e: nuke.message("couldn't write a backup file") deleteOlderBackupVersions(backupPath + "/" + scriptName) # per script else: backupPath = "/".join( nuke.root().name().split("/")[:-1]) + "/_backups_%s" % scriptName if not os.path.isdir(backupPath): os.makedirs(backupPath) try: nuke.removeOnScriptSave(makeBackup) nuke.scriptSave(backupPath + "/bckp_" + t + "_" + scriptName + ".nk") nuke.addOnScriptSave(makeBackup) except Exception, e: nuke.message("couldn't write a backup file") deleteOlderBackupVersions(backupPath) def toggleBackupProcess(): ''' enable/disable blackbox - set by value in blackbox.set ''' #reload settings enableBackup = blackboxHelper.getBackupSettings("@enableBackup",
os.makedirs(backupPath+"/"+scriptName) try: nuke.removeOnScriptSave(makeBackup) nuke.scriptSave(backupPath+"/"+scriptName+"/bckp_"+t+"_"+scriptName+".nk") nuke.addOnScriptSave(makeBackup) except Exception, e: nuke.message("couldn't write a backup file") deleteOlderBackupVersions(backupPath+"/"+scriptName) # per script else: backupPath = "/".join(nuke.root().name().split("/")[:-1])+"/_backups_%s" % scriptName if not os.path.isdir(backupPath): os.makedirs(backupPath) try: nuke.removeOnScriptSave(makeBackup) nuke.scriptSave(backupPath+"/bckp_"+t+"_"+scriptName+".nk") nuke.addOnScriptSave(makeBackup) except Exception, e: nuke.message("couldn't write a backup file") deleteOlderBackupVersions(backupPath) def toggleBackupProcess(): ''' enable/disable blackbox - set by value in blackbox.set ''' #reload settings enableBackup=blackboxHelper.getBackupSettings("@enableBackup", backupSettings) backupPath=blackboxHelper.getBackupSettings("@backupPath", backupSettings) operation=blackboxHelper.getBackupSettings("@operation", backupSettings)