Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
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) 
Beispiel #4
0
def openBackupDir():
    '''
    open backup directory in explorer
    '''
    backupPath=blackboxHelper.getBackupSettings("@backupPath", backupSettings)
    operation=blackboxHelper.getBackupSettings("@operation", backupSettings)
    scriptName = (nuke.root().name().split("/")[-1]).replace(".nk","")

    # global dir
    if operation=="0.0":
        backupPath
        try:
            blackboxHelper.openFolder(backupPath+"/"+scriptName)
        except Exception, e:
            nuke.message("couldn't open backupPath. no such directory")
Beispiel #5
0
def openBackupDir():
    '''
    open backup directory in explorer
    '''
    backupPath = blackboxHelper.getBackupSettings("@backupPath",
                                                  backupSettings)
    operation = blackboxHelper.getBackupSettings("@operation", backupSettings)
    scriptName = (nuke.root().name().split("/")[-1]).replace(".nk", "")

    # global dir
    if operation == "0.0":
        backupPath
        try:
            blackboxHelper.openFolder(backupPath + "/" + scriptName)
        except Exception, e:
            nuke.message("couldn't open backupPath. no such directory")
Beispiel #6
0
    def __init__(self):
        '''
            init values
            '''
        enableBackup = blackboxHelper.getBackupSettings(
            "@enableBackup", backupSettings)
        backupPath = blackboxHelper.getBackupSettings("@backupPath",
                                                      backupSettings)
        operation = blackboxHelper.getBackupSettings("@operation",
                                                     backupSettings)
        numberOfBackups = int(
            blackboxHelper.getBackupSettings("@numberOfBackups",
                                             backupSettings))

        if enableBackup == "1.0":
            enableBackup = True
        else:
            enableBackup = False

        nukescripts.PythonPanel.__init__(self, "Blackbox Settings",
                                         "Blackbox Settings")
        self.setMinimumSize(450, 160)

        self.enableBackup = nuke.Boolean_Knob("enableBackup", "enable backup",
                                              enableBackup)
        self.backupDirOp = nuke.Enumeration_Knob("operation", "operation", [
            "backup directory on global place", "backup directory per script"
        ])
        self.backupDirOp.setValue(str(operation))
        self.backupDirOp.resize(300, 30)
        self.backupPath = nuke.File_Knob('backupPath', 'backupPath')
        self.backupPath.setValue(backupPath)

        if operation == "0.0":
            self.backupPath.setVisible(True)
        else:
            self.backupPath.setVisible(False)

        self.numberOfBackups = nuke.String_Knob('numberOfBackups',
                                                'number of backups')
        self.numberOfBackups.setValue(str(numberOfBackups))

        self.addKnob(self.enableBackup)
        self.addKnob(self.backupDirOp)
        self.addKnob(self.backupPath)
        self.addKnob(self.numberOfBackups)
Beispiel #7
0
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)
Beispiel #8
0
    def __init__( self ):
            '''
            init values
            '''
            enableBackup=blackboxHelper.getBackupSettings("@enableBackup", backupSettings)
            backupPath=blackboxHelper.getBackupSettings("@backupPath", backupSettings)
            operation=blackboxHelper.getBackupSettings("@operation", backupSettings)
            numberOfBackups=int(blackboxHelper.getBackupSettings("@numberOfBackups", backupSettings))
            
            if enableBackup == "1.0":
                enableBackup=True
            else:
                enableBackup=False

            nukescripts.PythonPanel.__init__(self, "Blackbox Settings", "Blackbox Settings")
            self.setMinimumSize(450,160)
        
            self.enableBackup = nuke.Boolean_Knob("enableBackup","enable backup",enableBackup)
            self.backupDirOp=nuke.Enumeration_Knob("operation","operation",["backup directory on global place","backup directory per script"])
            self.backupDirOp.setValue(str(operation))
            self.backupDirOp.resize(300, 30)
            self.backupPath = nuke.File_Knob('backupPath', 'backupPath')
            self.backupPath.setValue(backupPath)
            
            if operation == "0.0":
                self.backupPath.setVisible(True)
            else:
                self.backupPath.setVisible(False)
            
            self.numberOfBackups = nuke.String_Knob('numberOfBackups', 'number of backups')
            self.numberOfBackups.setValue(str(numberOfBackups))
            
            self.addKnob(self.enableBackup)
            self.addKnob(self.backupDirOp)
            self.addKnob(self.backupPath)
            self.addKnob(self.numberOfBackups)
Beispiel #9
0
def deleteOlderBackupVersions(path):
    '''
    delete all the older versions which are older than {all backups - max. backup number}
    '''
    numberOfBackups=int(blackboxHelper.getBackupSettings("@numberOfBackups", backupSettings))

    i=0
    files=""
    for file in os.listdir(path):
        if file.endswith(".nk"):
           files+="%s," %file
           i+=1

    filesArr = files.split(",")
    #little hack, delete last comma
    filesArr.pop()
    
    #only keep the latest versions
    if len(filesArr)>numberOfBackups:
        toDelete = len(filesArr) - int(numberOfBackups)
        for f in range(0,toDelete):
            os.remove(path+"/"+filesArr[f])
Beispiel #10
0
def deleteOlderBackupVersions(path):
    '''
    delete all the older versions which are older than {all backups - max. backup number}
    '''
    numberOfBackups = int(
        blackboxHelper.getBackupSettings("@numberOfBackups", backupSettings))

    i = 0
    files = ""
    for file in os.listdir(path):
        if file.endswith(".nk"):
            files += "%s," % file
            i += 1

    filesArr = files.split(",")
    #little hack, delete last comma
    filesArr.pop()

    #only keep the latest versions
    if len(filesArr) > numberOfBackups:
        toDelete = len(filesArr) - int(numberOfBackups)
        for f in range(0, toDelete):
            os.remove(path + "/" + filesArr[f])
Beispiel #11
0
# In a nutshell you won't have more than one backup per minute and thus not having 3 million backups of your nuke script.
# save backup only for every minute and not for every second.
# If set to true the name of the backup path contains only date_Hour-Minute. So you cannot produce a backup for every second.
# This results in not having 3 Million copies if you always press the save button.
# If set to true backups saved within a minute get overwritten.
backupMinute = True
'''
init backup settings values; create blank file with defaults if blackbox.set doesn't exist
'''
if not os.path.isfile(backupSettings):
    if not os.path.isdir(backupSettingsPath):
        os.makedirs(backupSettingsPath)
    loadBackupSettings = open(backupSettings, 'w')
    open(backupSettings, "w").write(
        "@enableBackup=1.0\n@backupPath=\n@operation=1.0\n@numberOfBackups=10")
enableBackup = blackboxHelper.getBackupSettings("@enableBackup",
                                                backupSettings)
backupPath = blackboxHelper.getBackupSettings("@backupPath", backupSettings)
operation = blackboxHelper.getBackupSettings("@operation", backupSettings)
numberOfBackups = blackboxHelper.getBackupSettings("@numberOfBackups",
                                                   backupSettings)


class blackboxSettingsPanel(nukescripts.PythonPanel):
    '''
    blackbox panel
    '''
    def __init__(self):
        '''
            init values
            '''
        enableBackup = blackboxHelper.getBackupSettings(
Beispiel #12
0
# save backup only for every minute and not for every second.
# If set to true the name of the backup path contains only date_Hour-Minute. So you cannot produce a backup for every second.
# This results in not having 3 Million copies if you always press the save button.
# If set to true backups saved within a minute get overwritten.
backupMinute = True


'''
init backup settings values; create blank file with defaults if blackbox.set doesn't exist
'''
if not os.path.isfile(backupSettings):
    if not os.path.isdir(backupSettingsPath):
        os.makedirs(backupSettingsPath)
    loadBackupSettings = open(backupSettings,'w')
    open(backupSettings,"w").write("@enableBackup=1.0\n@backupPath=\n@operation=1.0\n@numberOfBackups=10")
enableBackup=blackboxHelper.getBackupSettings("@enableBackup", backupSettings)
backupPath=blackboxHelper.getBackupSettings("@backupPath", backupSettings)
operation=blackboxHelper.getBackupSettings("@operation", backupSettings)
numberOfBackups=blackboxHelper.getBackupSettings("@numberOfBackups", backupSettings)

class blackboxSettingsPanel(nukescripts.PythonPanel):
    '''
    blackbox panel
    '''
    def __init__( self ):
            '''
            init values
            '''
            enableBackup=blackboxHelper.getBackupSettings("@enableBackup", backupSettings)
            backupPath=blackboxHelper.getBackupSettings("@backupPath", backupSettings)
            operation=blackboxHelper.getBackupSettings("@operation", backupSettings)