Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def _handle_file_save(path, save, overwrite, *args):
- """
- Handles file collisions when saving files. If "overwrite" is true,
- overwrites file, if "overwrite" is false or the file to be overwritten
- is locked from editing, appends a number on end of filename to avoid
- file collision.
- Args:
- path (str): the path to the file to be saved
- save(): The save function used to save file
- overwrite (bool): true if user wants to overwrite file
- args: generic tuple of arguments used for different save functions
- """
- if os.path.isfile(path):
- if overwrite:
- try:
- print "Saving "" + path + """
- save(path, args)
- # Signifies problem writing file (lack of permissions, open
- # in another program, etc.)
- except EnvironmentError:
- # save as incremented file number
- print "Whoops! Looks like %s is locked!" % path
- path = gen_alt_filename(path)
- save(path, args)
- else:
- # save as incremented file number
- path = gen_alt_filename(path)
- print "Saving as "" + path + "" instead"
- save(path, args)
- else:
- print "Saving "" + path + """
- save(path, args)
- print "n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement