##// END OF EJS Templates
ask_yes_no on %%file overwrite
MinRK -
Show More
@@ -16,6 +16,7 b' builtin.'
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17
17
18 # Stdlib
18 # Stdlib
19 import io
19 import os
20 import os
20 import re
21 import re
21 import sys
22 import sys
@@ -25,7 +26,7 b' from pprint import pformat'
25 from IPython.core import magic_arguments
26 from IPython.core import magic_arguments
26 from IPython.core import oinspect
27 from IPython.core import oinspect
27 from IPython.core import page
28 from IPython.core import page
28 from IPython.core.error import UsageError
29 from IPython.core.error import UsageError, StdinNotImplementedError
29 from IPython.core.magic import (
30 from IPython.core.magic import (
30 Magics, compress_dhist, magics_class, line_magic, cell_magic
31 Magics, compress_dhist, magics_class, line_magic, cell_magic
31 )
32 )
@@ -699,13 +700,24 b' class OSMagics(Magics):'
699 """
700 """
700 args = magic_arguments.parse_argstring(self.file, line)
701 args = magic_arguments.parse_argstring(self.file, line)
701 args.filename = unquote_filename(args.filename)
702 args.filename = unquote_filename(args.filename)
703 force = args.force
702
704
703 if os.path.exists(args.filename):
705 if os.path.exists(args.filename):
704 if args.force:
706 if not force:
705 print("Overwriting %s" % args.filename)
707 try:
706 else:
708 force = self.shell.ask_yes_no(
707 error("%s already exists! Force overwrite with %%%%file -f\n" % args.filename)
709 "%s exists, overwrite (y/[n])?",
710 default='n'
711 )
712 except StdinNotImplementedError:
713 force = True
714
715 if not force:
716 # prompted, but still no
717 print "Force overwrite with %%file -f " + args.filename
708 return
718 return
719
720 print("Overwriting %s" % args.filename)
709 else:
721 else:
710 print("Writing %s" % args.filename)
722 print("Writing %s" % args.filename)
711
723
General Comments 0
You need to be logged in to leave comments. Login now