No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

autosave_backup.py 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #python imports
  2. import shutil
  3. import os
  4. #nuke import
  5. import nuke
  6. #user defined global variable
  7. max_autosave_files=3
  8. #global variable to hold the next autosave number
  9. next_autosave_version=0
  10. def backup_autosave():
  11. global next_autosave_version
  12. #get autosave file
  13. autosave_file = nuke.toNode("preferences")["AutoSaveName"].evaluate()
  14. #compute next autosave file name
  15. file = autosave_file + str(next_autosave_version)
  16. #check if original autosave file exists
  17. if os.path.exists(autosave_file):
  18. try:
  19. shutil.copy(autosave_file, file)
  20. except:
  21. nuke.message("Attention! Autosave file could not be copied!")
  22. nuke.tprint("Copied autosave file to: %s"%file)
  23. #start from the beginning if max files are reached
  24. if next_autosave_version==max_autosave_files:
  25. next_autosave_version=0
  26. else:
  27. next_autosave_version+=1
  28. elif nuke.Root()['name'].value():
  29. #warn if there is no autosave at all
  30. has_autosave=False
  31. for i in range(max_autosave_files):
  32. if os.path.exists(autosave_file + str(i)):
  33. has_autosave=True
  34. if not has_autosave and nuke.modified():
  35. nuke.message("Attention! You do not have an autosave file!")