ó
£áSc           @` s  d  Z  d d l m Z m Z m Z g  Z d d l Z e j d ƒ d d l Z d d l	 Z	 d d l
 Z
 d d l Z d „  Z d „  Z d „  Z d „  Z d d l Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z e	 j j d „ Z d „  Z e	 j j d „ Z e d k re e j ƒ n  d S(   sº  
This module converts code written for numpy.oldnumeric to work
with numpy

FIXME:  Flesh this out.

Makes the following changes:
 * Converts typecharacters '1swu' to 'bhHI' respectively
   when used as typecodes
 * Changes import statements
 * Change typecode= to dtype=
 * Eliminates savespace=xxx keyword arguments
 *  Removes it when keyword is not given as well
 * replaces matrixmultiply with dot
 * converts functions that don't give axis= keyword that have changed
 * converts functions that don't give typecode= keyword that have changed
 * converts use of capitalized type-names
 * converts old function names in oldnumeric.linear_algebra,
   oldnumeric.random_array, and oldnumeric.fft

i    (   t   divisiont   absolute_importt   print_functionNs0   numpy.oldnumeric.alter_code2 is not working yet.c         C` s^   |  j  d d ƒ }  |  j  d d ƒ }  |  j  d d ƒ }  |  j  d d ƒ }  |  j  d d	 ƒ }  |  S(
   Ns   's's   'h's   'b's   'B's   '1's   'w's   'H's   'u's   'I'(   t   replace(   t   astr(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt   replacetypechars%   s    c         C` sú   d | } d | } d | } d } |  j  | d | ƒ }  |  j  | d | | f ƒ }  d } t | ƒ } t d | ƒ }	 xu t rï |  j | | ƒ }
 |
 d k  r£ Pn  |
 | } |  | d k rÃ q{ n  d |  |
  | |  | f }  | |	 | 7} q{ W|  | f S(   Ns	   import %ss   import %s as s   from %s import i    s   import %s as %st   *s   %sfrom %s import %s(   R   t   lent   Truet   find(   t   fstrt   namet   newnamet	   importstrt   importasstrt   fromstrt   fromallt   indt   Nlent   Nlen2t   found(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt   changeimports-   s&    


	
c         C` s   |  j  d d ƒ }  |  S(   Nt   matrixmultiplyt   dot(   R   (   R   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt   replaceattrD   s    c         C` s=   t  j d d |  ƒ }  |  j d d ƒ }  |  j d d ƒ }  |  S(   Ns   typecode\s*=s   dtype=t	   ArrayTypet   ndarrayt   NewAxist   newaxis(   t   ret   subR   (   R   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt   replaceotherH   s    c         C` sN  t  |  d d ƒ \ }  } t  |  d d ƒ \ }  } t  |  d d ƒ \ }  } t  |  d d ƒ \ }  } t  |  d d ƒ \ }  } t  |  d	 d
 ƒ \ }  } t  |  d d ƒ \ }  } t  |  d d ƒ \ }  } t  |  d d ƒ \ }  } | pç t pç | } t |  ƒ }  t |  ƒ }  t j j ƒ  j d ƒ } t j	 j
 t j d ƒ d } d | | |  f }  |  S(   Ns   numpy.oldnumerict   numpys   numpy.core.multiarrays   numpy.core.umatht   LinearAlgebras   numpy.linalg.oldt   RNGs   numpy.random.oldrngs   RNG.Statisticss   numpy.random.oldrngstatst   RandomArrays   numpy.random.oldrandomarrayt   FFTs   numpy.fft.oldt   MAs   numpy.core.mas	   %b %d, %Yi    iÿÿÿÿs/   ## Automatically adapted for numpy %s by %s

%s(   R   t   fromall2R   R   t   datetimet   datet   todayt   strftimet   ost   patht   splitt   syst   argv(   t   filestrt   fromall1t   fromall3R   R)   R   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyR   O   s$    	c         C` s*   t  |  d ƒ } | j | ƒ | j ƒ  d  S(   Nt   w(   t   filet   writet   close(   R   R0   t   fid(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt   makenewfiled   s    c         C` sO   t  |  ƒ } | j ƒ  } | j ƒ  t j j |  ƒ \ } } t | d | ƒ | S(   Ns   .orig(   R4   t   readR6   R+   R,   t   splitextR8   (   R   R7   R0   t   baset   ext(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt
   getandcopyi   s    
c         C` s)   t  |  ƒ } t | ƒ } t |  | ƒ d S(   sŸ   Convert the filename given from using Numeric to using NumPy

    Copies the file to filename.orig and then over-writes the file
    with the updated code
    N(   R=   R   R8   (   t   filenameR0   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt   convertfileq   s    c         C` s   |  d } t  | ƒ d  S(   Ni   (   R?   (   t   argsR>   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt   fromargs{   s    
c         C` s=   t  j  t j j |  d ƒ ƒ } x | D] } t | ƒ q% Wd S(   sò   Convert all .py files to use NumPy (from Numeric) in the directory given

    For each file, a backup of <usesnumeric>.py is made as
    <usesnumeric>.py.orig.  A new file named <usesnumeric>.py
    is then written with the updated code.
    s   *.pyN(   t   globR+   R,   t   joinR?   (   t   direct   filest   afile(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt
   convertall   s    c         C` s   t  | ƒ d  S(   N(   RG   (   t   argt   dirnamet   fnames(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt   _funcŠ   s    c         C` s   t  j j |  t d ƒ d S(   s-   Convert all .py files in the tree given

    N(   R+   R,   t   walkRK   t   None(   RD   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt   converttree�   s    t   __main__(   t   __doc__t
   __future__R    R   R   t   __all__t   warningst   warnR.   R+   R   RB   R   R   R   R   R'   R   R8   R=   R?   RA   R,   t   curdirRG   RK   RN   t   __name__R/   (    (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/numpy/oldnumeric/alter_code2.pyt   <module>   s.   								
		