Show More
@@ -0,0 +1,68 b'' | |||||
|
1 | import IPython.ipapi | |||
|
2 | ip = IPython.ipapi.get() | |||
|
3 | ||||
|
4 | import os,pprint | |||
|
5 | ||||
|
6 | def export(filename = None): | |||
|
7 | ||||
|
8 | lines = ['import IPython.ipapi', 'ip = IPython.ipapi.get()',''] | |||
|
9 | ||||
|
10 | vars = ip.db.keys('autorestore/*') | |||
|
11 | vars.sort() | |||
|
12 | varstomove = [] | |||
|
13 | get = ip.db.get | |||
|
14 | ||||
|
15 | macros = [] | |||
|
16 | variables = [] | |||
|
17 | ||||
|
18 | for var in vars: | |||
|
19 | k = os.path.basename(var) | |||
|
20 | v = get(var) | |||
|
21 | ||||
|
22 | if k.startswith('_'): | |||
|
23 | continue | |||
|
24 | if isinstance(v, IPython.macro.Macro): | |||
|
25 | macros.append((k,v)) | |||
|
26 | if type(v) in [int, str, float]: | |||
|
27 | variables.append((k,v)) | |||
|
28 | ||||
|
29 | ||||
|
30 | ||||
|
31 | if macros: | |||
|
32 | lines.extend(['# === Macros ===' ,'']) | |||
|
33 | for k,v in macros: | |||
|
34 | lines.append("ip.defmacro('%s'," % k) | |||
|
35 | for line in v.value.splitlines(): | |||
|
36 | lines.append(' ' + repr(line+'\n')) | |||
|
37 | lines.extend([')', '']) | |||
|
38 | ||||
|
39 | if variables: | |||
|
40 | lines.extend(['','# === Variables ===','']) | |||
|
41 | for k,v in variables: | |||
|
42 | varstomove.append(k) | |||
|
43 | lines.append('%s = %s' % (k,repr(v))) | |||
|
44 | ||||
|
45 | lines.append('ip.to_user_ns("%s")' % (' '.join(varstomove))) | |||
|
46 | ||||
|
47 | bkms = ip.db.get('bookmarks',{}) | |||
|
48 | ||||
|
49 | if bkms: | |||
|
50 | lines.extend(['','# === Bookmarks ===','']) | |||
|
51 | lines.append("ip.db['bookmarks'] = %s " % pprint.pformat(bkms, indent = 2) ) | |||
|
52 | ||||
|
53 | aliases = ip.db.get('stored_aliases', {} ) | |||
|
54 | ||||
|
55 | if aliases: | |||
|
56 | lines.extend(['','# === Alias definitions ===','']) | |||
|
57 | for k,v in aliases.items(): | |||
|
58 | lines.append("ip.defalias('%s', %s)" % (k, repr(v[1]))) | |||
|
59 | ||||
|
60 | ||||
|
61 | ||||
|
62 | out = '\n'.join(lines) | |||
|
63 | ||||
|
64 | if filename: | |||
|
65 | open(filename,'w').write(out) | |||
|
66 | else: | |||
|
67 | print out | |||
|
68 |
@@ -333,7 +333,7 b' class IPApi:' | |||||
333 | """ |
|
333 | """ | |
334 |
|
334 | |||
335 | import IPython.macro |
|
335 | import IPython.macro | |
336 |
|
|
336 | ||
337 | if len(args) == 1: |
|
337 | if len(args) == 1: | |
338 | return IPython.macro.Macro(args[0]) |
|
338 | return IPython.macro.Macro(args[0]) | |
339 | elif len(args) == 2: |
|
339 | elif len(args) == 2: |
@@ -7,9 +7,13 b'' | |||||
7 | * Extensions/ipy_completers.py: introduced Olivier Lauzanne's |
|
7 | * Extensions/ipy_completers.py: introduced Olivier Lauzanne's | |
8 | safer & faster 'import' completer. |
|
8 | safer & faster 'import' completer. | |
9 |
|
9 | |||
10 | * Introduced new ipapi methods, _ip.defmacro(name, value) |
|
10 | * ipapi.py: Introduced new ipapi methods, _ip.defmacro(name, value) | |
11 | and _ip.defalias(name, command). |
|
11 | and _ip.defalias(name, command). | |
12 |
|
12 | |||
|
13 | * Extensions/ipy_exportdb.py: New extension for exporting all the | |||
|
14 | %store'd data in a portable format (normal ipapi calls like | |||
|
15 | defmacro() etc.) | |||
|
16 | ||||
13 | 2007-04-19 Ville Vainio <vivainio@gmail.com> |
|
17 | 2007-04-19 Ville Vainio <vivainio@gmail.com> | |
14 |
|
18 | |||
15 | * upgrade_dir.py: skip junk files like *.pyc |
|
19 | * upgrade_dir.py: skip junk files like *.pyc |
General Comments 0
You need to be logged in to leave comments.
Login now