Show More
@@ -21,7 +21,7 b' import sys' | |||||
21 | from urllib2 import urlopen |
|
21 | from urllib2 import urlopen | |
22 |
|
22 | |||
23 | # Our own packages |
|
23 | # Our own packages | |
24 | from IPython.core.error import TryNext |
|
24 | from IPython.core.error import TryNext, StdinNotImplementedError | |
25 | from IPython.core.macro import Macro |
|
25 | from IPython.core.macro import Macro | |
26 | from IPython.core.magic import Magics, magics_class, line_magic |
|
26 | from IPython.core.magic import Magics, magics_class, line_magic | |
27 | from IPython.core.oinspect import find_file, find_source_lines |
|
27 | from IPython.core.oinspect import find_file, find_source_lines | |
@@ -57,6 +57,9 b' class CodeMagics(Magics):' | |||||
57 | so that magics are loaded in their transformed version to valid |
|
57 | so that magics are loaded in their transformed version to valid | |
58 | Python. If this option is given, the raw input as typed as the |
|
58 | Python. If this option is given, the raw input as typed as the | |
59 | command line is used instead. |
|
59 | command line is used instead. | |
|
60 | ||||
|
61 | -f: force overwrite. If file exists, %save will prompt for overwrite | |||
|
62 | unless -f is given. | |||
60 |
|
63 | |||
61 | This function uses the same syntax as %history for input ranges, |
|
64 | This function uses the same syntax as %history for input ranges, | |
62 | then saves the lines to the filename you specify. |
|
65 | then saves the lines to the filename you specify. | |
@@ -67,14 +70,19 b' class CodeMagics(Magics):' | |||||
67 | If `-r` option is used, the default extension is `.ipy`. |
|
70 | If `-r` option is used, the default extension is `.ipy`. | |
68 | """ |
|
71 | """ | |
69 |
|
72 | |||
70 | opts,args = self.parse_options(parameter_s,'r',mode='list') |
|
73 | opts,args = self.parse_options(parameter_s,'fr',mode='list') | |
71 | raw = 'r' in opts |
|
74 | raw = 'r' in opts | |
|
75 | force = 'f' in opts | |||
72 | ext = u'.ipy' if raw else u'.py' |
|
76 | ext = u'.ipy' if raw else u'.py' | |
73 | fname, codefrom = unquote_filename(args[0]), " ".join(args[1:]) |
|
77 | fname, codefrom = unquote_filename(args[0]), " ".join(args[1:]) | |
74 | if not fname.endswith((u'.py',u'.ipy')): |
|
78 | if not fname.endswith((u'.py',u'.ipy')): | |
75 | fname += ext |
|
79 | fname += ext | |
76 | if os.path.isfile(fname): |
|
80 | if os.path.isfile(fname) and not force: | |
77 | overwrite = self.shell.ask_yes_no('File `%s` exists. Overwrite (y/[N])? ' % fname, default='n') |
|
81 | try: | |
|
82 | overwrite = self.shell.ask_yes_no('File `%s` exists. Overwrite (y/[N])? ' % fname, default='n') | |||
|
83 | except StdinNotImplementedError: | |||
|
84 | print "File `%s` exists. Use `%%save -f %s` to force overwrite" % (fname, parameter_s) | |||
|
85 | return | |||
78 | if not overwrite : |
|
86 | if not overwrite : | |
79 | print 'Operation cancelled.' |
|
87 | print 'Operation cancelled.' | |
80 | return |
|
88 | return |
General Comments 0
You need to be logged in to leave comments.
Login now