Skip to content

Commit

Permalink
Use plugin API for storemagic, so autorestore is configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Nov 30, 2011
1 parent bf33fa8 commit e1c2632
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions IPython/extensions/storemagic.py
Expand Up @@ -17,11 +17,13 @@
""" """


from IPython.core.error import TryNext, UsageError from IPython.core.error import TryNext, UsageError
from IPython.core.plugin import Plugin
from IPython.utils import pickleshare from IPython.utils import pickleshare
from IPython.utils.traitlets import Bool, Instance


import inspect,pickle,os,sys,textwrap import inspect,pickle,os,sys,textwrap
from IPython.core.fakemodule import FakeModule from IPython.core.fakemodule import FakeModule

def restore_aliases(ip): def restore_aliases(ip):
staliases = ip.db.get('stored_aliases', {}) staliases = ip.db.get('stored_aliases', {})
for k,v in staliases.items(): for k,v in staliases.items():
Expand Down Expand Up @@ -183,6 +185,24 @@ def magic_store(self, parameter_s=''):
self.db[ 'autorestore/' + args[0] ] = obj self.db[ 'autorestore/' + args[0] ] = obj
print "Stored '%s' (%s)" % (args[0], obj.__class__.__name__) 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): def load_ipython_extension(ip):
ip.define_magic('store', magic_store) """Load the extension in IPython."""
restore_data(ip) 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.