##// END OF EJS Templates
disallow no-prefix `ipython foo=bar` argument style....
disallow no-prefix `ipython foo=bar` argument style. This style is in rc1, but will be removed in rc2. Since they don't match any flag pattern, rc1-style arguments will be interpreted by IPython as files to be run. So `ipython gui=foo -i` will exec gui=foo, and pass '-i' to gui=foo. Presumably this file won't exist, so there will be an error: Error in executing file in user namespace: gui=foo Assignments *must* have two leading '-', as in: ipython --foo=bar all flags (non-assignments) can be specified with one or two leading '-', as in: ipython -i --pylab -pdb --pprint script.py or ipython --i -pylab --pdb -pprint script.py but help only reports two-leading, as single-leading options will likely be removed on moving to argparse, where they will be replaced by single-letter aliases. The common remaining invalid option will be: ipython -foo=bar and a suggestion for 'did you mean --foo=bar'? will be presented in these cases.

File last commit:

r2267:928c921b
r4197:368e365a
Show More
ipy_exportdb.py
77 lines | 2.0 KiB | text/x-python | PythonLexer
from IPython.core import ipapi
from IPython.core import macro
ip = ipapi.get()
import os,pprint
def export(filename = None):
lines = ['import IPython.core.ipapi', 'ip = IPython.core.ipapi.get()','']
vars = ip.db.keys('autorestore/*')
vars.sort()
varstomove = []
get = ip.db.get
macros = []
variables = []
for var in vars:
k = os.path.basename(var)
v = get(var)
if k.startswith('_'):
continue
if isinstance(v, macro.Macro):
macros.append((k,v))
if type(v) in [int, str, float]:
variables.append((k,v))
if macros:
lines.extend(['# === Macros ===' ,''])
for k,v in macros:
lines.append("ip.defmacro('%s'," % k)
for line in v.value.splitlines():
lines.append(' ' + repr(line+'\n'))
lines.extend([')', ''])
if variables:
lines.extend(['','# === Variables ===',''])
for k,v in variables:
varstomove.append(k)
lines.append('%s = %s' % (k,repr(v)))
lines.append('ip.push("%s")' % (' '.join(varstomove)))
bkms = ip.db.get('bookmarks',{})
if bkms:
lines.extend(['','# === Bookmarks ===',''])
lines.append("ip.db['bookmarks'] = %s " % pprint.pformat(bkms, indent = 2) )
aliases = ip.db.get('stored_aliases', {} )
if aliases:
lines.extend(['','# === Alias definitions ===',''])
for k,v in aliases.items():
try:
lines.append("ip.define_alias('%s', %s)" % (k, repr(v[1])))
except (AttributeError, TypeError):
pass
env = ip.db.get('stored_env')
if env:
lines.extend(['','# === Stored env vars ===',''])
lines.append("ip.db['stored_env'] = %s " % pprint.pformat(env, indent = 2) )
out = '\n'.join(lines)
if filename:
open(filename,'w').write(out)
else:
print out