##// END OF EJS Templates
Restore pspersistence, including %store magic, as an extension.
Thomas Kluyver -
Show More
@@ -174,7 +174,7 b' class AliasManager(Configurable):'
174 174 "because it is a keyword or builtin." % name)
175 175 if not (isinstance(cmd, basestring)):
176 176 raise InvalidAliasError("An alias command must be a string, "
177 "got: %r" % name)
177 "got: %r" % cmd)
178 178 nargs = cmd.count('%s')
179 179 if nargs>0 and cmd.find('%l')>=0:
180 180 raise InvalidAliasError('The %s and %l specifiers are mutually '
@@ -5,22 +5,18 b''
5 5 Stores variables, aliases etc. in PickleShare database.
6 6 """
7 7
8 from IPython.core import ipapi
9 8 from IPython.core.error import TryNext, UsageError
10 ip = ipapi.get()
11
12 import pickleshare
9 from IPython.utils import pickleshare
13 10
14 11 import inspect,pickle,os,sys,textwrap
15 12 from IPython.core.fakemodule import FakeModule
16 13
17 def restore_aliases(self):
18 ip = self.getapi()
14 def restore_aliases(ip):
19 15 staliases = ip.db.get('stored_aliases', {})
20 16 for k,v in staliases.items():
21 17 #print "restore alias",k,v # dbg
22 18 #self.alias_table[k] = v
23 ip.define_alias(k,v)
19 ip.alias_manager.define_alias(k,v)
24 20
25 21
26 22 def refresh_variables(ip):
@@ -39,17 +35,12 b' def refresh_variables(ip):'
39 35
40 36
41 37 def restore_dhist(ip):
42 db = ip.db
43 ip.user_ns['_dh'] = db.get('dhist',[])
38 ip.user_ns['_dh'] = ip.db.get('dhist',[])
44 39
45 def restore_data(self):
46 ip = self.getapi()
40 def restore_data(ip):
47 41 refresh_variables(ip)
48 restore_aliases(self)
49 restore_dhist(self)
50 raise TryNext
51
52 ip.set_hook('late_startup_hook', restore_data)
42 restore_aliases(ip)
43 restore_dhist(ip)
53 44
54 45 def magic_store(self, parameter_s=''):
55 46 """Lightweight persistence for python variables.
@@ -88,7 +79,7 b" def magic_store(self, parameter_s=''):"
88 79
89 80 opts,argsl = self.parse_options(parameter_s,'drz',mode='string')
90 81 args = argsl.split(None,1)
91 ip = self.getapi()
82 ip = self.shell
92 83 db = ip.db
93 84 # delete
94 85 if opts.has_key('d'):
@@ -158,11 +149,13 b" def magic_store(self, parameter_s=''):"
158 149 except KeyError:
159 150 # it might be an alias
160 151 # This needs to be refactored to use the new AliasManager stuff.
161 if args[0] in self.alias_table:
152 if args[0] in self.alias_manager:
153 name = args[0]
154 nargs, cmd = self.alias_manager.alias_table[ name ]
162 155 staliases = db.get('stored_aliases',{})
163 staliases[ args[0] ] = self.alias_table[ args[0] ]
156 staliases[ name ] = cmd
164 157 db['stored_aliases'] = staliases
165 print "Alias stored:", args[0], self.alias_table[ args[0] ]
158 print "Alias stored: %s (%s)" % (name, cmd)
166 159 return
167 160 else:
168 161 raise UsageError("Unknown variable '%s'" % args[0])
@@ -180,4 +173,6 b" def magic_store(self, parameter_s=''):"
180 173 self.db[ 'autorestore/' + args[0] ] = obj
181 174 print "Stored '%s' (%s)" % (args[0], obj.__class__.__name__)
182 175
183 ip.define_magic('store',magic_store)
176 def load_ipython_extension(ip):
177 ip.define_magic('store', magic_store)
178 restore_data(ip)
General Comments 0
You need to be logged in to leave comments. Login now