ó
©¶"Pc           @   s  d  d l  Z  d  d l Z d  d l Z d  d l m Z d  d l Z d  d l m Z m Z m Z m	 Z	 m
 Z
 m Z d  d l m Z d  d l m Z d  d l j Z d  d l m Z d  d l j Z e j d ƒ Z i  Z e re ry d  d l Z d  d l Z Wqe k
 re d ƒ ‚ qXn  d  d	 l m Z d  d
 l m Z d  d l m  Z  y d  d l m! Z! Wqe k
 r{Z" d Z! qXn  d d „ Z$ d „  Z% d „  Z& d d d „ Z' d „  Z( d d „ Z) d „  Z* d d „ Z+ d d „ Z, d „  Z- d „  Z. d „  Z/ d „  Z0 d „  Z1 d S(   iÿÿÿÿN(   t   glob(   t   is_wint   is_unixt   is_aixt	   is_cygwint	   is_darwint   is_py26(   t   dylib(   t   winutils(   t   sets   PyInstaller.build.bindependsz   Error: PyInstaller for Python 2.6+ on Windows needs pywin32.
Please install from http://sourceforge.net/projects/pywin32/(   t   RT_MANIFEST(   t   GetManifestResources(   t   Manifest(   t   winresourcec         C   sÙ   t  j t j ƒ  } | d k	 rW t | ƒ t d ƒ k rJ | j d | ƒ qW | | } n  x{ | D]s } t j j | |  ƒ } t j j	 | ƒ r | Sx? | D]7 } t j j | |  j
 ƒ  ƒ } t j j	 | ƒ r– | Sq– Wq^ Wd S(   sö   
    Return the full path name of MOD.

    MOD is the basename of a dll or pyd.
    XTRAPATH is a path or list of paths to search first.
    Return the full path name of MOD.
    Will search the full Windows search path, as well as sys.path
    t    i    N(   t   syst   pathR   t   get_system_patht   Nonet   typet   insertt   ost   joint   existst   lower(   t   modt   xtrapatht   epatht   pt   npth(    (    sF   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/bindepend.pyt   getfullnameof=   s    
c         C   s{   d d l  j j } t ƒ  } | j |  d t ƒ} | j d | j d g ƒ x* t | d g  ƒ D] } | j	 | j
 ƒ q] W| S(   sª   
    Find the binary dependencies of PTH.

    This implementation walks through the PE header
    and uses library pefile for that and supports
    32/64bit Windows
    iÿÿÿÿNt	   fast_loadt   directoriest   IMAGE_DIRECTORY_ENTRY_IMPORTt   DIRECTORY_ENTRY_IMPORT(   t   PyInstaller.lib.pefilet   libt   pefileR	   t   PEt   Truet   parse_data_directoriest   DIRECTORY_ENTRYt   getattrt   addt   dll(   t   pthR%   t   dllst   pet   entry(    (    sF   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/bindepend.pyt   _getImports_peY   s    		c         C   sp   xi |  D]a } | \ } } } t  j j | ƒ s t | ƒ d d } |  j | ƒ |  j | | | f ƒ q q W|  S(   sÚ   
    Ensure all binary modules in zipped eggs get extracted and
    included with the frozen executable.

    The supplied toc is directly modified to make changes effective.

    return  modified table of content
    i    (   R   R   t   isfilet   check_extract_from_eggt   removet   append(   t   toct   itemt   modnameR-   t   typ(    (    sF   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/bindepend.pyt   _extract_from_eggr   s    	c   
      C   s#  t  |  ƒ }  x|  D]\ } } } t j | j ƒ  d ƒ r@ q n  t j d | ƒ d t | j ƒ  <t rŸ x6 t | | ƒ D]" \ } } |  j | | d f ƒ qv Wn  xy t	 | | ƒ D]h \ } }	 t j | j ƒ  d ƒ s¯ t j |	 j ƒ  d ƒ rñ q¯ n  d t |	 j ƒ  <|  j | |	 d f ƒ q¯ Wq W|  S(   s  
    Expand LTOC to include all the closure of binary dependencies.

    LTOC is a logical table of contents, ie, a seq of tuples (name, path).
    Return LTOC expanded by all the binary dependencies of the entries
    in LTOC, except those listed in the module global EXCLUDES

    manifest should be a winmanifest.Manifest instance on Windows, so
    that all dependent assemblies can be added
    i    s   Analyzing %si   t   BINARY(
   R:   t   seent   gett   uppert   loggert   debugR   t   selectAssembliesR5   t   selectImports(
   t   lTOCR   t   manifestt   nmR-   R9   t   ftocnmt   fnR$   R   (    (    sF   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/bindepend.pyt   Dependencies‡   s    0c          C   s  t  j d ƒ }  |  d k	 r |  St j d k r> t j j d ƒ Sd } d d | f d | f d | f d d | f g } x™ | D]… \ } } d } xp | D]7 } | t j k rÊ t j j | t  j | ƒ ƒ } q” Pq” W| rí t j j | | ƒ } n  t j j | d ƒ Sq{ Wt	 d ƒ ‚ d S(   s  
    Determine the default cache location

    This returns the ``PYTHON_EGG_CACHE`` environment variable, if set.
    Otherwise, on Windows, it returns a 'Python-Eggs' subdirectory of the
    'Application Data' directory.  On all other systems, it's '~/.python-eggs'.
    t   PYTHON_EGG_CACHEt   nts   ~/.python-eggss   Application Datat   APPDATAt   USERPROFILEt	   HOMEDRIVEt   HOMEPATHt   HOMEt   WINDIRR   s   Python-Eggss3   Please set the PYTHON_EGG_CACHE enviroment variableN(   s   APPDATA(   (   s   APPDATAN(   RL   (   RM   s   HOMEPATH(   s   HOMEPATH(   s   HOME(   (   s   HOMEN(   RP   (
   t   compatt   getenvR   R   t   nameR   t
   expandusert   environR   t   RuntimeError(   t	   egg_cachet   app_datat	   app_homest   keyst   subdirt   dirnamet   key(    (    sF   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/bindepend.pyt   pkg_resouces_get_default_cache§   s.    				!c         C   s  g  } t  j j r3 |  j t  j j t  j j ƒ }  n  |  j t  j j ƒ } x½t | ƒ D]¯\ } } | j ƒ  j d ƒ rU t  j j j	 | | d  ƒ } t  j j
 | ƒ ry t j | ƒ } Wn, t j k
 ræ } t d | | f ƒ ‚ n X| d k rt  j j	 t ƒ  | d ƒ } n  | | d r=d j	 | | d ƒ g }	 n | j ƒ  }	 x± |	 D]© }
 t  j j	 | |
 ƒ }  t  j j
 |  ƒ sãt  j j |  ƒ } t  j j | ƒ s±t  j | ƒ n  t |  d ƒ } | j | j |
 ƒ ƒ | j ƒ  n  | j |  | |
 f ƒ qPW| SqU qU W|  d d f g S(   s˜  
    Check if path points to a file inside a python egg file, extract the
    file from the egg to a cache directory (following pkg_resources
    convention) and return [(extracted path, egg file path, relative path
    inside egg file)].
    Otherwise, just return [(original path, None, None)].
    If path points to an egg file directly, return a list with all files
    from the egg formatted like above.

    Example:
    >>> check_extract_from_egg(r'C:\Python26\Lib\site-packages\my.egg\mymodule\my.pyd')
    [(r'C:\Users\UserName\AppData\Roaming\Python-Eggs\my.egg-tmp\mymodule\my.pyd',
    r'C:\Python26\Lib\site-packages\my.egg', r'mymodule/my.pyd')]
    s   .eggi   s   Error: %s %ss   -tmpt   /t   wbN(   R   R   t   altsept   replacet   sept   splitt	   enumerateR   t   endswithR   R2   t   zipfilet   ZipFilet
   BadZipfilet
   SystemExitR   R^   t   namelistR\   t   isdirt   makedirst   opent   writet   readt   closeR5   (   R-   t   todirt   rvt
   componentst   iRS   t   eggptht   eggt   et   memberst   memberR\   t   f(    (    sF   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/bindepend.pyR3   Ò   s<    !c   
   	   C   s  |  j  ƒ  j d ƒ r g  S|  d } t j j | ƒ rr t | d ƒ } i i i | j ƒ  d 6d 6t 6} | j ƒ  nc t	 s| g  Sy t
 |  ƒ } WnF t	 j j k
 rÔ } | j d t	 j k rÎ t j d |  ƒ g  S‚  n Xg  } t | k rt | t ƒ rx| t D]} x| t | D]ö } yY t ƒ  } d j |  t t ƒ t | ƒ t | ƒ g ƒ | _ | j | t | | t ƒ Wn6 t k
 r®} t j d | | |  ƒ t j | ƒ qX| j rýt j d |  ƒ t j d	 j g  | j D] }	 |	 j ƒ  ^ qÞƒ ƒ n  | j | j ƒ qWqWn  | S(
   s6   
    Return the dependent assemblies of a binary.
    s	   .manifestt   rbi    i   s0   Cannot get manifest resource from non-PE file %st   :s-   Can not parse manifest resource %s, %sfrom %ss   Dependent assemblies of %s:s   , (   R   Rf   R   R   R2   Rn   Rp   R
   Rq   R   R   t
   pywintypest   errort   argst   ERROR_BAD_EXE_FORMATR?   t   infot   lenR   R   t   strt   filenamet   parse_stringt   Falset	   Exceptiont	   exceptiont   dependentAssembliesR@   t   getidt   extend(
   R-   t
   manifestnmt   fdt   rest   excRs   RS   t   languageRD   t   assembly(    (    sF   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/bindepend.pyt   getAssemblies  sJ    
!				&c         C   sz  g  } | r4 t  g  | j D] } | j ^ q ƒ } n  x?t |  ƒ D]1} t j | j ƒ  j ƒ  d ƒ rk qA n  | r¶ | j | k r¶ t j	 d | j ƒ | j j
 | ƒ | j | j ƒ n  t j | j ƒ sä t j d | j ƒ  ƒ qA n  | j r	t j d | j ƒ  ƒ qA n  | j ƒ  } | r\d t | j ƒ  j ƒ  <x>| D]} t j j | ƒ \ } }	 |	 j ƒ  d k rx| j |	 }
 n t j j | ƒ }
 |
 } | j d k r½t j j | j ƒ  | ƒ } n  g  |
 | | f D] } | j t j ƒ  ƒ ^ qÍ\ }
 } } t j | j ƒ  d ƒ s8t j d
 | ƒ d t |
 j ƒ  <d t | j ƒ  <| j
 | | f ƒ q8q8WqA t j d | j ƒ  ƒ qA W| S(   s|   
    Return a binary's dependent assemblies files that should be included.

    Return a list of pairs (name, fullpath)
    i    s5   Adding %s to dependent assemblies of final executables   Skipping assembly %ss   Skipping optional assembly %si   s	   .manifestR   t   *t   neutrals	   Adding %ss   Assembly %s not foundN(   NR   R”   R•   (   R	   RŠ   RS   R“   R<   R=   R‹   R>   R?   R‚   R5   R+   R   t   include_libraryR@   t   optionalt
   find_filesR   R   t   splitextR   t   basenameR‘   R   R   t   getlanguaget   encodeR   t   getfilesystemencodingR   (   R-   RD   Rs   t   dept	   _depNamesR’   t   filesRG   t   fnamet   fextRE   RF   R7   (    (    sF   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/bindepend.pyRA   9  sR    (	
	1c         C   sÉ  g  } | d k r* t j j |  ƒ g } n. t | t ƒ s? t ‚ t j j |  ƒ g | } t |  ƒ } x^| D]V} t j	 | j
 ƒ  d ƒ r qk n  t r¸ t r¸ | } t j j | ƒ } n t | | ƒ } | rÖ | } n | } t j | ƒ sX| j d ƒ d k  rX| j d ƒ d k  rXt j	 | j
 ƒ  d ƒ sk t j d | t j j |  ƒ ƒ qk qk qXn  | r®t j	 | j
 ƒ  d ƒ sÁt j d | t j j |  ƒ ƒ | j | | f ƒ qÁqk t j d | |  ƒ qk W| S(   ss   
    Return the dependencies of a binary that should be included.

    Return a list of pairs (name, fullpath)
    i    t	   libpythons   Python.frameworks   Skipping %s dependency of %ss   Adding %s dependency of %ss"   lib not found: %s dependency of %sN(   R   R   R   R\   t
   isinstancet   listt   AssertionErrort
   getImportsR<   R=   R>   R   R   Rš   R   R   R–   t   findR?   R@   R5   R   (   R-   R   Rs   R.   R$   R   t   candidatelib(    (    sF   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/bindepend.pyRB   q  s>    			c         C   s(  t  ƒ  } t r! t j d ƒ } n t j d ƒ } xñ t j d |  ƒ j ƒ  j ƒ  D]Ñ } | j | ƒ } | rO t r¡ | j	 d ƒ } t
 j j | ƒ | j	 d ƒ } n | j	 d ƒ | j	 d ƒ } } | d  d
 k rÖ qO n  t
 j j | ƒ r| | k r| j | ƒ qq t j d	 | | |  ƒ qO qO W| S(   sk   
    Find the binary dependencies of PTH.

    This implementation is for ldd platforms (mostly unix).
    s   \s+(.*?)(\(.*\))s   \s+(.*?)\s+=>\s+(.*?)\s+\(.*\)t   lddi   i   i
   s
   linux-gates
   linux-vdsos)   Can not find %s in path %s (needed by %s)(   s
   linux-gates
   linux-vdso(   R	   R   t   ret   compileRQ   t   exec_commandt   stript
   splitlinest   searcht   groupR   R   Rš   R   R+   R?   R   (   R-   t   rsltt
   lddPatternt   linet   mR$   RS   (    (    sF   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/bindepend.pyt   _getImports_ldd¦  s&    	%"	c         C   s¶  d d l  m } d d l m } d d l m } t ƒ  } t ƒ  } | |  ƒ } xM | j D]B } x9 | j ƒ  D]+ \ } }	 }
 |
 | k rk | j	 |
 ƒ qk qk WqX Wt ƒ  } x— | j D]Œ } xƒ | j
 D]x } | d j } | | k rÁ | d } | j d ƒ } t j j t j j t j j |  ƒ | ƒ ƒ } | j | g ƒ qÁ qÁ Wq± Wt j j t j j |  ƒ ƒ } xP| D]H}
 |
 j d ƒ r@|
 j d d	 ƒ }
 d } x‹ | D]ƒ } t j j | ƒ sÊt j j | | ƒ } n  t j j t j j | |
 ƒ ƒ ršt j j t j j | |
 ƒ ƒ } | j	 | ƒ PqšqšW| s®t j d
 |
 |  ƒ q®qf|
 j d ƒ rd|
 j d d ƒ }
 n  y# | |
 d | ƒ}
 | j	 |
 ƒ Wqft k
 r­t j d
 |
 |  ƒ qfXqfW| S(   sr   
    Find the binary dependencies of PTH.

    This implementation is for Mac OS X and uses library macholib.
    iÿÿÿÿ(   t   MachO(   t   LC_RPATH(   t	   dyld_findi    i   t    s   @rpatht   .s#   Can not find path %s (needed by %s)s   @loader_paths   @executable_patht   executable_pathN(   t   PyInstaller.lib.macholib.MachOR·   t   PyInstaller.lib.macholib.mach_oR¸   t   PyInstaller.lib.macholib.dyldR¹   R	   t   headerst   walkRelocatablesR+   t   commandst   cmdt   rstripR   R   t   normpathR   R\   t   updatet   abspatht
   startswithRb   R   t   isabsR   R?   R   t
   ValueError(   R-   R·   R¸   R¹   R²   R<   Rµ   t   headert   idxRS   R$   t	   run_pathst   commandt   cmd_typet   rpatht	   exec_patht	   final_libt   run_path(    (    sF   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/bindepend.pyt   _getImports_macholibÌ  sR    				
-!!c         C   s   t  s t r |  j ƒ  j d ƒ r% g  Sy t |  ƒ SWq™ t k
 r{ } t j t j	 ƒ rw t j
 d |  ƒ t j | ƒ n  g  SXn t r t |  ƒ St |  ƒ Sd S(   sM   
    Forwards to the correct getImports implementation for the platform.
    s	   .manifests,   Can not get binary dependencies for file: %sN(   R   R   R   Rf   R1   Rˆ   R?   t   isEnabledFort   loggingt   WARNt   warnR‰   R   RÔ   R¶   (   R-   R‰   (    (    sF   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/bindepend.pyR§   (  s    
c   	      C   s‚  t  s t d ƒ ‚ d } t j d d ƒ } xM | j t j ƒ D]9 } t t j	 j
 | |  d ƒ ƒ } | r= | d } Pq= q= W| d k rÒ d t j |  ƒ } t j | t j d d ƒ ƒ } | rÒ | j d ƒ } qÒ n  | d k rGd	 d
 g } t r | j d ƒ n  xD | D]9 } t t j	 j
 | |  d ƒ ƒ } | r| d } PqqWn  | d k rWd St j	 j | ƒ } t j	 j
 | t | ƒ ƒ S(   s’   
    Look for a library in the system.

    Emulate the algorithm used by dlopen.
    `name`must include the prefix, e.g. ``libpython2.4.so``
    s:   Current implementation for Unix only (Linux, Solaris, AIX)t   LD_LIBRARY_PATHR   R”   i    s   /[^\(\)\s]*%s\.[^\(\)\s]*s   /sbin/ldconfigs   -ps   /libs   /usr/libs   /opt/freeware/libN(   R   R¦   R   RQ   RR   Rd   R   t   pathsepR    R   R   R«   t   escapeR°   R­   R±   R   R5   R\   t	   getSoname(	   RS   R$   t   lpR   t   libst   exprRµ   t   pathst   dir(    (    sF   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/bindepend.pyt   findLibraryB  s4    

c         C   sG   d d d d |  g } t  j d t j | Œ  ƒ } | rC | j d ƒ Sd S(   s)   
    Return the soname of a library.
    t   objdumps   -ps   -js   .dynamics   \s+SONAME\s+([^\s]+)i   N(   R«   R°   RQ   R­   R±   (   R…   RÃ   Rµ   (    (    sF   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/bindepend.pyRÜ   p  s    (2   R   R   R«   R    Rg   t   PyInstallerR   R   R   R   R   R   t   PyInstaller.dependR   t   PyInstaller.utilsR   t   PyInstaller.compatRQ   R	   t   PyInstaller.logt   logRÖ   t	   getLoggerR?   R<   t   win32apiR~   t   ImportErrorRj   t   PyInstaller.utils.winmanifestR
   R   R   R   t   detailR   R   R1   R:   RH   R^   R3   R“   RA   RB   R¶   RÔ   R§   Râ   RÜ   (    (    (    sF   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/bindepend.pyt   <module>   sP   .		 	+5	285	&	\		.