Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. def _handle_file_save(path, save, overwrite, *args):
  2. """
  3. Handles file collisions when saving files. If "overwrite" is true,
  4. overwrites file, if "overwrite" is false or the file to be overwritten
  5. is locked from editing, appends a number on end of filename to avoid
  6. file collision.
  7.  
  8. Args:
  9. path (str): the path to the file to be saved
  10. save(): The save function used to save file
  11. overwrite (bool): true if user wants to overwrite file
  12. args: generic tuple of arguments used for different save functions
  13.  
  14. """
  15. if os.path.isfile(path):
  16. if overwrite:
  17. try:
  18. print "Saving "" + path + """
  19. save(path, args)
  20. # Signifies problem writing file (lack of permissions, open
  21. # in another program, etc.)
  22. except EnvironmentError:
  23. # save as incremented file number
  24. print "Whoops! Looks like %s is locked!" % path
  25. path = gen_alt_filename(path)
  26. save(path, args)
  27. else:
  28. # save as incremented file number
  29. path = gen_alt_filename(path)
  30. print "Saving as "" + path + "" instead"
  31. save(path, args)
  32. else:
  33. print "Saving "" + path + """
  34. save(path, args)
  35. print "n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement