home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1739 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.2 KB  |  100 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import IPython.ipapi as IPython
  5. ip = IPython.ipapi.get()
  6. import os
  7. import pprint
  8.  
  9. def export(filename = None):
  10.     lines = [
  11.         'import IPython.ipapi',
  12.         'ip = IPython.ipapi.get()',
  13.         '']
  14.     vars = ip.db.keys('autorestore/*')
  15.     vars.sort()
  16.     varstomove = []
  17.     get = ip.db.get
  18.     macros = []
  19.     variables = []
  20.     for var in vars:
  21.         k = os.path.basename(var)
  22.         v = get(var)
  23.         if k.startswith('_'):
  24.             continue
  25.         
  26.         if isinstance(v, IPython.macro.Macro):
  27.             macros.append((k, v))
  28.         
  29.         if type(v) in [
  30.             int,
  31.             str,
  32.             float]:
  33.             variables.append((k, v))
  34.             continue
  35.     
  36.     if macros:
  37.         lines.extend([
  38.             '# === Macros ===',
  39.             ''])
  40.     
  41.     for k, v in macros:
  42.         lines.append("ip.defmacro('%s'," % k)
  43.         for line in v.value.splitlines():
  44.             lines.append(' ' + repr(line + '\n'))
  45.         
  46.         lines.extend([
  47.             ')',
  48.             ''])
  49.     
  50.     if variables:
  51.         lines.extend([
  52.             '',
  53.             '# === Variables ===',
  54.             ''])
  55.         for k, v in variables:
  56.             varstomove.append(k)
  57.             lines.append('%s = %s' % (k, repr(v)))
  58.         
  59.         lines.append('ip.to_user_ns("%s")' % ' '.join(varstomove))
  60.     
  61.     bkms = ip.db.get('bookmarks', { })
  62.     if bkms:
  63.         lines.extend([
  64.             '',
  65.             '# === Bookmarks ===',
  66.             ''])
  67.         lines.append("ip.db['bookmarks'] = %s " % pprint.pformat(bkms, indent = 2))
  68.     
  69.     aliases = ip.db.get('stored_aliases', { })
  70.     if aliases:
  71.         lines.extend([
  72.             '',
  73.             '# === Alias definitions ===',
  74.             ''])
  75.         for k, v in aliases.items():
  76.             
  77.             try:
  78.                 lines.append("ip.defalias('%s', %s)" % (k, repr(v[1])))
  79.             continue
  80.             except (AttributeError, TypeError):
  81.                 continue
  82.             
  83.  
  84.         
  85.     
  86.     env = ip.db.get('stored_env')
  87.     if env:
  88.         lines.extend([
  89.             '',
  90.             '# === Stored env vars ===',
  91.             ''])
  92.         lines.append("ip.db['stored_env'] = %s " % pprint.pformat(env, indent = 2))
  93.     
  94.     out = '\n'.join(lines)
  95.     if filename:
  96.         open(filename, 'w').write(out)
  97.     else:
  98.         print out
  99.  
  100.