;ò
ÎÑAHc           @   s{   d  Z  d k Z e i i ƒ  Z d k Z d k Z d k Z d k	 Z	 d „  Z
 d f  d „  ƒ  YZ d „  Z e i d e ƒ d S(   s†   IPython extension: add %rehashdir magic

Usage:

%rehashdir c:/bin c:/tools
  - Add all executables under c:/bin and c:/tools to alias table, in 
  order to make them directly executable from any directory.
  
This also serves as an example on how to extend ipython
with new magic functions.

Unlike rest of ipython, this requires Python 2.4 (optional
extensions are allowed to do that).

Nc         C   sq   | i t d ƒ } t | ƒ d j o d GHt i t i ƒ d Sn t i d | d } d G| GHt i | ƒ d S(   s[    Launch python script with 'this' interpreter
    
    e.g. d:oo\ipykit.exe a.py
    
    i   s    Launching nested ipython sessionNs    s   >(
   s   lines   splits   Nones   tups   lens   oss   systems   syss
   executables   cmd(   s   ips   lines   tups   cmd(    (    sQ   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_rehashdir.pys
   selflaunch   s     	s
   PyLauncherc           B   s)   t  Z d  Z d „  Z d „  Z d „  Z RS(   s²    Invoke selflanucher on the specified script
    
    This is mostly useful for associating with scripts using::
        _ip.defalias('foo',PyLauncher('foo_script.py'))
    
    c         C   s   t  i i | ƒ |  _ d  S(   N(   s   oss   paths   abspaths   scripts   self(   s   selfs   script(    (    sQ   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_rehashdir.pys   __init__0   s    c         C   sŒ   |  i i d ƒ o  | i t |  i ƒ i ƒ  ƒ nV | i t	 d ƒ } t | ƒ d j o d | d } n d } t | d |  i | ƒ d  S(   Ns   .ipyi   i   s    s    s   py (   s   selfs   scripts   endswiths   ips   runliness   opens   reads   lines   splits   Nones   tups   lens   tails
   selflaunch(   s   selfs   ips   lines   tups   tail(    (    sQ   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_rehashdir.pys   __call__2   s     c         C   s   d |  i Sd  S(   Ns   PyLauncher("%s")(   s   selfs   script(   s   self(    (    sQ   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_rehashdir.pys   __repr__>   s    (   s   __name__s
   __module__s   __doc__s   __init__s   __call__s   __repr__(    (    (    sQ   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_rehashdir.pys
   PyLauncher)   s    		c            sƒ  d „  }
 g  } | o
 d } n t t i i | i d ƒ ƒ } |  i	 i
 } t i d j o d „  } n† y) t i d i d d ƒ i d d ƒ } Wn t j
 o d	 } n Xd
 | j o | d 7} n t i d | t i ƒ ‰  ‡  d †  } t i ƒ  } zqt i d j o¦ xM| D]— } t i | ƒ x t i | ƒ D]p }	 | |	 ƒ o |
 |	 ƒ oO t i i |	 ƒ d t i i |	 ƒ f \ } } | i | ƒ d | f | | <q6q6WqWn« x§ | D]Ÿ } t i | ƒ x‰ t i | ƒ D]x }	 | |	 ƒ o |
 |	 ƒ oW ˆ  i d |	 ƒ t i i |	 ƒ f \ } } | i  ƒ  } | i | ƒ d | f | | <qÜqÜWq¹W|  i	 i! ƒ  Wd t i | ƒ X| Sd S(   sI   Add executables in all specified dirs to alias table
     
    Usage:

    %rehashdir c:/bin;c:/tools
      - Add all executables under c:/bin and c:/tools to alias table, in 
      order to make them directly executable from any directory.
        
      Without arguments, add all executables in current directory.
      
    c         C   s=   d g } x) | D]! } t i |  | ƒ o t Sq q Wt Sd  S(   Ns   *~(   s   junks   js   fnmatchs   fnames   Trues   False(   s   fnames   junks   j(    (    sQ   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_rehashdir.pys   isjunkP   s    	 s   .s   ;s   posixc         C   s&   t  i i |  ƒ o t  i |  t  i ƒ S(   N(   s   oss   paths   isfiles   fnames   accesss   X_OK(   s   fname(    (    sQ   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_rehashdir.pys   <lambda>^   s    s   pathexts   |s    s   exe|com|bat|pys   pys   |pys   (.*)\.(%s)$c            s    t  i i |  ƒ o ˆ  i |  ƒ S(   N(   s   oss   paths   isfiles   fnames   execres   match(   s   fname(   s   execre(    sQ   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_rehashdir.pys   <lambda>j   s    i    s   \1N("   s   isjunks   createds   args   maps   oss   paths   abspaths   splits   selfs   shells   alias_tables   names   isexecs   environs   replaces   winexts   KeyErrors   res   compiles
   IGNORECASEs   execres   getcwds   savedirs   pdirs   chdirs   listdirs   ffs   splitexts   srcs   tgts   appends   subs   lowers   alias_table_validate(   s   selfs   args   tgts   createds   winexts   pdirs   isexecs   execres   savedirs   ffs   isjunks   paths   srcs   alias_table(    (   s   execresQ   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_rehashdir.pys   rehashdir_fA   sV     	
)  .   * s	   rehashdir(   s   __doc__s   IPython.ipapis   IPythons   ipapis   gets   ips   oss   res   fnmatchs   syss
   selflaunchs
   PyLaunchers   rehashdir_fs   expose_magic(	   s   res   ips   rehashdir_fs   syss   fnmatchs
   selflaunchs   IPythons
   PyLaunchers   os(    (    sQ   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_rehashdir.pys   ?   s   	$		K