Quantcast

[IPython-User] feature request : auto save ipython notebook file

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[IPython-User] feature request : auto save ipython notebook file

Abhishek Pratap-2
Unless I am missing this just becoz I am new to Ipython I am wondering
if there anyway by which we can kick off an auto save feature for the
notebook. I shift machines couple of times a day and often forget to
save the workbook on machine 1 in which case unable to get the the
full notebook I worked from a different machine.

Thanks!
-Abhi
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: feature request : auto save ipython notebook file

Brian Granger-3
We are working on this one.

On Thu, Mar 22, 2012 at 3:28 PM, Abhishek Pratap <[hidden email]> wrote:

> Unless I am missing this just becoz I am new to Ipython I am wondering
> if there anyway by which we can kick off an auto save feature for the
> notebook. I shift machines couple of times a day and often forget to
> save the workbook on machine 1 in which case unable to get the the
> full notebook I worked from a different machine.
>
> Thanks!
> -Abhi
> _______________________________________________
> IPython-User mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/ipython-user



--
Brian E. Granger
Cal Poly State University, San Luis Obispo
[hidden email] and [hidden email]
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: feature request : auto save ipython notebook file

Abhishek Pratap-2
ok cool

-A

On Thu, Mar 22, 2012 at 3:44 PM, Brian Granger <[hidden email]> wrote:

> We are working on this one.
>
> On Thu, Mar 22, 2012 at 3:28 PM, Abhishek Pratap <[hidden email]> wrote:
>> Unless I am missing this just becoz I am new to Ipython I am wondering
>> if there anyway by which we can kick off an auto save feature for the
>> notebook. I shift machines couple of times a day and often forget to
>> save the workbook on machine 1 in which case unable to get the the
>> full notebook I worked from a different machine.
>>
>> Thanks!
>> -Abhi
>> _______________________________________________
>> IPython-User mailing list
>> [hidden email]
>> http://mail.scipy.org/mailman/listinfo/ipython-user
>
>
>
> --
> Brian E. Granger
> Cal Poly State University, San Luis Obispo
> [hidden email] and [hidden email]
> _______________________________________________
> IPython-User mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/ipython-user
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: feature request : auto save ipython notebook file

Fernando Perez
In reply to this post by Brian Granger-3
On Thu, Mar 22, 2012 at 3:44 PM, Brian Granger <[hidden email]> wrote:
> We are working on this one.

But note that what we're discussing is a *background* autosave, that
would save the notebook with a *different* filename than the real one,
to be used only in case of a crash.  What the OP is asking for is an
autosave that automatically saves the notebook he is working on
directly, and that's something I've said multiple times I absolutely
will not have on by default, because it risks saving a state that may
be unwanted. Since we have no undo/history capability, this would be
disastrous.

Fortunately, the OP can have autosave right now, just put this in your
startup file:

def autosave(interval=5):
    """Autosave the notebook every interval (in minutes)"""
    from IPython.core.display import Javascript
    interval *= 60*1000 # JS wants intervals in miliseconds
    tpl = 'setInterval ( "IPython.notebook.save_notebook()", %i );'
    return Javascript(tpl % interval)

and call it anywhere in your notebook to activate it.

Alternately, just put this (in this case, using 5 minutes):

<script type="text/javascript">
setInterval ( "IPython.notebook.save_notebook()", 5*60*1000 );
</script>

in the first cell of your notebook and make it a markdown cell.
You're done, autosave is on for that notebook everytime you open it.

Remember: you have full access to the notebook 'application' itself
from within javascript, so if there's something we don't yet provide
with a UI element ourselves, it's likely just a few lines of code away
for you.

Cheers,

f
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: feature request : auto save ipython notebook file

Brian Granger-3
On Thu, Mar 22, 2012 at 4:05 PM, Fernando Perez <[hidden email]> wrote:

> On Thu, Mar 22, 2012 at 3:44 PM, Brian Granger <[hidden email]> wrote:
>> We are working on this one.
>
> But note that what we're discussing is a *background* autosave, that
> would save the notebook with a *different* filename than the real one,
> to be used only in case of a crash.  What the OP is asking for is an
> autosave that automatically saves the notebook he is working on
> directly, and that's something I've said multiple times I absolutely
> will not have on by default, because it risks saving a state that may
> be unwanted. Since we have no undo/history capability, this would be
> disastrous.

Yes, I missed this distinction and I completely agree with you.

> Fortunately, the OP can have autosave right now, just put this in your
> startup file:
>
> def autosave(interval=5):
>    """Autosave the notebook every interval (in minutes)"""
>    from IPython.core.display import Javascript
>    interval *= 60*1000 # JS wants intervals in miliseconds
>    tpl = 'setInterval ( "IPython.notebook.save_notebook()", %i );'
>    return Javascript(tpl % interval)
>
> and call it anywhere in your notebook to activate it.

Nice, very clever!

> Alternately, just put this (in this case, using 5 minutes):
>
> <script type="text/javascript">
> setInterval ( "IPython.notebook.save_notebook()", 5*60*1000 );
> </script>
>
> in the first cell of your notebook and make it a markdown cell.
> You're done, autosave is on for that notebook everytime you open it.

Not quite a pretty but also does the job.

> Remember: you have full access to the notebook 'application' itself
> from within javascript, so if there's something we don't yet provide
> with a UI element ourselves, it's likely just a few lines of code away
> for you.

Very good point.  You can also enter the requisite javascript in the
javascript console if that floats your boat.

Cheers,

Brian

> Cheers,
>
> f
> _______________________________________________
> IPython-User mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/ipython-user



--
Brian E. Granger
Cal Poly State University, San Luis Obispo
[hidden email] and [hidden email]
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
mqk
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: feature request : auto save ipython notebook file

mqk
Apologies for reviving this 3+ months old thread...

I have exactly the same issue as the OP, and have implemented the autosave function in the startup file, as suggested by Fernando. Works great, but I think it may be preferable to have the auto-saves be to a slightly different filename, like $FILENAME.ipynb.autosave or something like that. This would prevent the saving of unwanted changes that Fernando was rightly concerned about. I'm aware of the aversion among devs to cluttering up the directory with autosave files, but I don't share that particular sentiment and would like to try and implement it for myself.

I see that I can pass a keyword 'name' to save_notebook(), but I'm unsure of how to get at the notebook's name in the autosave() function. I'm sure it's a trivial thing. Any suggestions?

Thanks,
Mike
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: feature request : auto save ipython notebook file

Matthias Bussonnier


On Fri, Jun 29, 2012 at 9:16 PM, mqk <[hidden email]> wrote:
Apologies for reviving this 3+ months old thread...

I have exactly the same issue as the OP, and have implemented the autosave
function in the startup file, as suggested by Fernando. Works great, but I
think it may be preferable to have the auto-saves be to a slightly different
filename, like $FILENAME.ipynb.autosave or something like that. This would
prevent the saving of unwanted changes that Fernando was rightly concerned
about. I'm aware of the aversion among devs to cluttering up the directory
with autosave files, but I don't share that particular sentiment and would
like to try and implement it for myself.

I see that I can pass a keyword 'name' to save_notebook(), but I'm unsure of
how to get at the notebook's name in the autosave() function. I'm sure it's
a trivial thing. Any suggestions?

I'm not that sure, if I remember correctly 'save_notebook' is used to rename the notebook, and you will loose your normal file if you try to do that.
Right now  the notebook server handler should be refactored to have a 'save a copy' I think. But we need to discuss that, maybe at scipy.

You can try to dig  around duplicate notebook, but I don't think it will be of any help either as it won't send the new content to the server.

--
Matthias



Thanks,
Mike

--
View this message in context: http://python.6.n6.nabble.com/IPython-User-feature-request-auto-save-ipython-notebook-file-tp4646741p4980042.html
Sent from the IPython - User mailing list archive at Nabble.com.
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user


_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Loading...