Tried activating autosave extension, but got error message
houshuang opened this issue · 11 comments
weird - what do you see in ls ~/.ipython/extensions
?
[~] ls ~/.ipython/extensions
21:51:07
autosave.py
On Fri, Dec 14, 2012 at 10:00 PM, Min RK notifications@github.com wrote:
ls ~/.ipython/extensions
http://reganmian.net/blog -- Random Stuff that Matters
hm, I can't imagine why that wouldn't work, then.
What do you get for:
get_ipython().extension_manager.ipython_extension_dir
And what IPython version?
In [77]:
get_ipython().extension_manager.ipython_extension_dir
Out[77]:
u'/Users/Stian/.ipython/extensions'
Version 0.13.1, using EPD (but have upgraded iPython using enpkg).
On Fri, Dec 14, 2012 at 10:14 PM, Min RK notifications@github.com wrote:
get_ipython().extension_manager.ipython_extension_dir
http://reganmian.net/blog -- Random Stuff that Matters
One more thing - what are the contents of that autosave.py in your
extensions folder?
"""Extension for managing periodic autosave of IPython notebooks
Usage:
%load_ext autosave
autosave every 30 seconds:
%autosave 30
disable autosave:
%autosave 0
invoke save from Python:
%savenb
"""
from IPython.core.magic import magics_class, line_magic, Magics
from IPython.display import Javascript, display
_autosave_js_t = """
// clear previous interval, if there was one
if (IPython.autosave_extension_interval) {{
clearInterval(IPython.autosave_extension_interval);
IPython.autosave_extension_interval = null;
}}
// set new interval
if ({0}) {{
console.log("scheduling autosave every {0} ms");
IPython.notebook.save_notebook();
IPython.autosave_extension_interval = setInterval(function() {{
console.log("autosave");
IPython.notebook.save_notebook();
}}, {0});
}} else {{
console.log("canceling autosave");
}}
"""
@magics_class
class AutoSaveMagics(Magics):
interval = 60
enabled = False
@staticmethod
def autosave_js(interval):
if interval:
print("autosaving every %is" % interval)
else:
print("autosave disabled")
display(Javascript(_autosave_js_t.format(1000 * interval)))
@line_magic
def autosave(self, line):
"""Schedule notebook autosave
Usage:
%autosave [interval]
If `interval` is given, IPython will autosave the notebook every
interval
seconds.
If interval
is 0, autosave is disabled.
If no interval is specified, autosave is toggled.
"""
line = line.strip()
if not line:
# empty line, toggle
self.enabled = bool(1 - self.enabled)
else:
interval = int(line)
if interval:
self.enabled = True
self.interval = interval
else:
self.enabled = False
self.autosave_js(self.enabled * self.interval)
@line_magic
def savenb(self, line):
"""save the current notebook
This magic invokes the same javascript as the 'Save' button in the
notebook UI.
"""
display(Javascript("IPython.notebook.save_notebook();"))
_loaded = False
def load_ipython_extension(ip):
"""Load the extension in IPython."""
global _loaded
if not _loaded:
ip.register_magics(AutoSaveMagics)
_loaded = True
print ("Usage: %autosave [seconds]")
On Fri, Dec 14, 2012 at 10:51 PM, Min RK notifications@github.com wrote:
One more thing - what are the contents of that autosave.py in your
extensions folder?—
Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-11393726.
http://reganmian.net/blog -- Random Stuff that Matters
Okay, then everything seems to be working perfectly. What if you define your own extension, just put an empty foo.py
in your extension folder, and try %load_ext foo
. If that doesn't work, something is wrong with your IPython installation, and you should bring that up as an IPython issue.
That went fine.
In [15]:
%load_ext foo
In [ ]:
On Fri, Dec 14, 2012 at 11:47 PM, Min RK notifications@github.com wrote:
%load_ext foo
http://reganmian.net/blog -- Random Stuff that Matters
Well, now that doesn't make even the slightest bit of sense. %load_ext autosave
doesn't work, even after %load_ext foo
does?
Of course, now it works perfectly. Apart from playing with different
notebooks, I am quite sure I have not touched the IPython setup. I'm sorry
if I have wasted your time, but glad that it works.
okay - I wonder why it didn't work. Might be something funky if you run %install_ext and %load_ext in the same session.