home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1766 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.7 KB  |  57 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 sys
  8. from fnmatch import fnmatch
  9.  
  10. def which(fname):
  11.     fullpath = filter(os.path.isdir, os.environ['PATH'].split(os.pathsep))
  12.     if '.' not in fullpath:
  13.         fullpath = [
  14.             '.'] + fullpath
  15.     
  16.     fn = fname
  17.     for p in fullpath:
  18.         for f in os.listdir(p):
  19.             (head, ext) = os.path.splitext(f)
  20.             if f == fn or fnmatch(head, fn):
  21.                 yield os.path.join(p, f)
  22.                 continue
  23.         
  24.     
  25.  
  26.  
  27. def which_alias(fname):
  28.     for al, tgt in ip.IP.alias_table.items():
  29.         if not al == fname or fnmatch(al, fname):
  30.             continue
  31.         
  32.         if callable(tgt):
  33.             print 'Callable alias', tgt
  34.             d = tgt.__doc__
  35.             if d:
  36.                 print 'Docstring:\n', d
  37.                 continue
  38.             
  39.         
  40.         trg = tgt[1]
  41.         trans = ip.expand_alias(trg)
  42.         cmd = trans.split(None, 1)[0]
  43.         print al, '->', trans
  44.         for realcmd in which(cmd):
  45.             print '  ==', realcmd
  46.         
  47.     
  48.  
  49.  
  50. def which_f(self, arg):
  51.     which_alias(arg)
  52.     for e in which(arg):
  53.         print e
  54.     
  55.  
  56. ip.expose_magic('which', which_f)
  57.