home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1757 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.7 KB  |  98 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 re
  8. import fnmatch
  9. import sys
  10.  
  11. def selflaunch(ip, line):
  12.     tup = line.split(None, 1)
  13.     if len(tup) == 1:
  14.         print 'Launching nested ipython session'
  15.         os.system(sys.executable)
  16.         return None
  17.     cmd = sys.executable + ' ' + tup[1]
  18.     print '>', cmd
  19.     os.system(cmd)
  20.  
  21.  
  22. class PyLauncher:
  23.     
  24.     def __init__(self, script):
  25.         self.script = os.path.abspath(script)
  26.  
  27.     
  28.     def __call__(self, ip, line):
  29.         if self.script.endswith('.ipy'):
  30.             ip.runlines(open(self.script).read())
  31.         else:
  32.             tup = line.split(None, 1)
  33.             if len(tup) == 2:
  34.                 tail = ' ' + tup[1]
  35.             else:
  36.                 tail = ''
  37.             selflaunch(ip, 'py ' + self.script + tail)
  38.  
  39.     
  40.     def __repr__(self):
  41.         return 'PyLauncher("%s")' % self.script
  42.  
  43.  
  44.  
  45. def rehashdir_f(self, arg):
  46.     
  47.     def isjunk(fname):
  48.         junk = [
  49.             '*~']
  50.         for j in junk:
  51.             if fnmatch.fnmatch(fname, j):
  52.                 return True
  53.         
  54.         return False
  55.  
  56.     created = []
  57.     if not arg:
  58.         arg = '.'
  59.     
  60.     path = map(os.path.abspath, arg.split(';'))
  61.     alias_table = self.shell.alias_table
  62.     savedir = os.getcwd()
  63.     
  64.     try:
  65.         if os.name == 'posix':
  66.             for pdir in path:
  67.                 os.chdir(pdir)
  68.                 for ff in os.listdir(pdir):
  69.                     if isexec(ff) and not isjunk(ff):
  70.                         src = os.path.splitext(ff)[0]
  71.                         tgt = os.path.abspath(ff)
  72.                         created.append(src)
  73.                         alias_table[src] = (0, tgt)
  74.                         continue
  75.                     None if os.name == 'posix' else (None,)
  76.                 
  77.             
  78.         else:
  79.             for pdir in path:
  80.                 os.chdir(pdir)
  81.                 for ff in os.listdir(pdir):
  82.                     if isexec(ff) and not isjunk(ff):
  83.                         src = execre.sub('\\1', ff)
  84.                         tgt = os.path.abspath(ff)
  85.                         src = src.lower()
  86.                         created.append(src)
  87.                         alias_table[src] = (0, tgt)
  88.                         continue
  89.                 
  90.             
  91.         self.shell.alias_table_validate()
  92.     finally:
  93.         os.chdir(savedir)
  94.  
  95.     return created
  96.  
  97. ip.expose_magic('rehashdir', rehashdir_f)
  98.