Skip to content
Browse files

Use plugin API for storemagic, so autorestore is configurable.

  • Loading branch information...
1 parent bf33fa8 commit e1c26325fb736e6d38b2a9d87ccc77562b4bf2ee @takluyver committed Nov 30, 2011
Showing with 23 additions and 3 deletions.
  1. +23 −3 IPython/extensions/storemagic.py
View
26 IPython/extensions/storemagic.py
@@ -17,11 +17,13 @@
"""
from IPython.core.error import TryNext, UsageError
+from IPython.core.plugin import Plugin
from IPython.utils import pickleshare
+from IPython.utils.traitlets import Bool, Instance
import inspect,pickle,os,sys,textwrap
from IPython.core.fakemodule import FakeModule
-
+
def restore_aliases(ip):
staliases = ip.db.get('stored_aliases', {})
for k,v in staliases.items():
@@ -183,6 +185,24 @@ def magic_store(self, parameter_s=''):
self.db[ 'autorestore/' + args[0] ] = obj
print "Stored '%s' (%s)" % (args[0], obj.__class__.__name__)
+
+class StoreMagic(Plugin):
+ shell = Instance('IPython.core.interactiveshell.InteractiveShellABC')
+ autorestore = Bool(False, config=True)
+
+ def __init__(self, shell, config):
+ super(StoreMagic, self).__init__(shell=shell, config=config)
+ shell.define_magic('store', magic_store)
+
+ if self.autorestore:
+ restore_data(shell)
+
+_loaded = False
+
def load_ipython_extension(ip):
- ip.define_magic('store', magic_store)
- restore_data(ip)
+ """Load the extension in IPython."""
+ global _loaded
+ if not _loaded:
+ plugin = StoreMagic(shell=ip, config=ip.config)
+ ip.plugin_manager.register_plugin('storemagic', plugin)
+ _loaded = True

0 comments on commit e1c2632

Please sign in to comment.
Something went wrong with that request. Please try again.