##// END OF EJS Templates
%%file always overwrites
MinRK -
Show More
@@ -681,10 +681,6 b' class OSMagics(Magics):'
681
681
682 @magic_arguments.magic_arguments()
682 @magic_arguments.magic_arguments()
683 @magic_arguments.argument(
683 @magic_arguments.argument(
684 '-f', '--force', action='store_true', default=False,
685 help='Force overwrite without prompting'
686 )
687 @magic_arguments.argument(
688 '-a', '--amend', action='store_true', default=False,
684 '-a', '--amend', action='store_true', default=False,
689 help='Open file for amending if it exists'
685 help='Open file for amending if it exists'
690 )
686 )
@@ -699,30 +695,16 b' class OSMagics(Magics):'
699 For frontends that do not support stdin (Notebook), -f is implied.
695 For frontends that do not support stdin (Notebook), -f is implied.
700 """
696 """
701 args = magic_arguments.parse_argstring(self.file, line)
697 args = magic_arguments.parse_argstring(self.file, line)
702 args.filename = unquote_filename(args.filename)
698 filename = unquote_filename(args.filename)
703 force = args.force
704
699
705 if os.path.exists(args.filename):
700 if os.path.exists(filename):
706 if args.amend:
701 if args.amend:
707 print "Amending to %s" % args.filename
702 print "Amending to %s" % filename
708 else:
703 else:
709 if not force:
704 print "Overwriting %s" % filename
710 try:
711 force = self.shell.ask_yes_no(
712 "%s exists, overwrite (y/[n])?",
713 default='n'
714 )
715 except StdinNotImplementedError:
716 force = True
717
718 if not force:
719 # prompted, but still no
720 print "Force overwrite with %%file -f " + args.filename
721 return
722 print "Overwriting %s" % args.filename
723 else:
705 else:
724 print "Writing %s" % args.filename
706 print "Writing %s" % filename
725
707
726 mode = 'a' if args.amend else 'w'
708 mode = 'a' if args.amend else 'w'
727 with io.open(args.filename, mode, encoding='utf-8') as f:
709 with io.open(filename, mode, encoding='utf-8') as f:
728 f.write(cell)
710 f.write(cell)
General Comments 0
You need to be logged in to leave comments. Login now