
 Qc           @   s  d  Z  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 j Z e j e  Z i  Z e ru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! Wque k
 rqZ" d Z! qu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   Z2 d S(   s1   
Find external dependencies of binary libraries.
iN(   t   glob(   t   is_wint   is_unixt   is_aixt	   is_cygwint	   is_darwint   is_py26(   t   dylib(   t   winutilssz   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  d d l  m } t j j |   d d  } t j | g t j   } | d k	 r t	 |  t	 d  k r| | j
 d |  q | | } 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
    i(   t   get_python_libt   numpyt   coret    i    N(   t   distutils.sysconfigR   t   ost   patht   joint   sysR   t   get_system_patht   Nonet   typet   insertt   existst   lower(   t   modt   xtrapathR   t   numpy_core_patht   epatht   pt   npth(    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\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
    iNt	   fast_loadt   directoriest   IMAGE_DIRECTORY_ENTRY_IMPORTt   DIRECTORY_ENTRY_IMPORT(   t   PyInstaller.lib.pefilet   libt   pefilet   sett   PEt   Truet   parse_data_directoriest   DIRECTORY_ENTRYt   getattrt   addt   dll(   t   pthR)   t   dllst   pet   entry(    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\bindepend.pyt   _getImports_peZ   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   modnameR2   t   typ(    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\bindepend.pyt   _extract_from_eggs   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   selectAssembliesR:   t   selectImports(
   t   lTOCR   t   manifestt   nmR2   R>   t   ftocnmt   fnR(   R!   (    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\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(   s   USERPROFILE(   s	   HOMEDRIVEs   HOMEPATH(   s   HOMEPATH(   s   HOME(   (   s   HOMEN(   RU   (
   t   compatt   getenvR   R   t   nameR   t
   expandusert   environR   t   RuntimeError(   t	   egg_cachet   app_datat	   app_homest   keyst   subdirt   dirnamet   key(    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\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   R7   t   zipfilet   ZipFilet
   BadZipfilet
   SystemExitR   Rc   t   namelistRa   t   isdirt   makedirst   opent   writet   readt   closeR:   (   R2   t   todirt   rvt
   componentst   iRX   t   eggptht   eggt   et   memberst   memberRa   t   f(    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\bindepend.pyR8      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   Rk   R   R   R7   Rs   Ru   R	   Rv   R   R
   t
   pywintypest   errort   argst   ERROR_BAD_EXE_FORMATRD   t   infot   lenR   R   t   strt   filenamet   parse_stringt   Falset	   Exceptiont	   exceptiont   dependentAssembliesRE   t   getidt   extend(
   R2   t
   manifestnmt   fdt   rest   excRx   RX   t   languageRI   t   assembly(    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\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   RX   R   RA   RB   R   RC   RD   R   R:   R0   R   t   include_libraryRE   t   optionalt
   find_filesR   R   t   splitextR   t   basenameR   R   R   t   getlanguaget   encodeR   t   getfilesystemencodingR   (   R2   RI   Rx   t   dept	   _depNamesR   t   filesRL   t   fnamet   fextRJ   RK   R<   (    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\bindepend.pyRF   :  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   Ra   t
   isinstancet   listt   AssertionErrort
   getImportsRA   RB   RC   R   R   R   R"   R   R   t   findRD   RE   R:   R   (   R2   R   Rx   R3   R(   R!   t   candidatelib(    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\bindepend.pyRG   r  s>    			c         C   s"  t    } t r! t j d  } n t j d  } x t j d |   j   D] } | j |  } | rI t r | j d  } t	 j
 j |  | j d  } n | j d  | j d  } } | d  d
 k r qI n  t	 j
 j |  r| | k r| j |  qqt j d	 | | |   qI qI 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   compileRV   t   exec_commandt
   splitlinest   searcht   groupR   R   R   R   R0   RD   R   (   R2   t   rsltt
   lddPatternt   linet   mR(   RX   (    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\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   walkRelocatablesR0   t   commandst   cmdt   rstripR   R   t   normpathR   Ra   t   updatet   abspatht
   startswithRg   R   t   isabsR   RD   R   t
   ValueError(   R2   R   R   R   R   RA   R   t   headert   idxRX   R(   t	   run_pathst   commandt   cmd_typet   rpatht	   exec_patht	   final_libt   run_path(    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\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   Rk   R6   R   RD   t   isEnabledFort   loggingt   WARNt   warnR   R   R   R   (   R2   R   (    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\bindepend.pyR   )  s    
c   	      C   s  t  s t d   d } t r3 t j d d  } n- t rN t j d d  } n t j d d  } xM | j t j	  D]9 } t
 t j j | |  d   } | rs | d } Pqs qs W| d k rt j j d  rd	 t j |   } t j | t j d d
   } | r| j d  } qn  | d k rd d g } t rH| j d  n  xD | D]9 } t
 t j j | |  d   } | rO| d } PqOqOWn  | d k r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   LIBPATHR   t   DYLD_LIBRARY_PATHt   LD_LIBRARY_PATHR   i    s   /sbin/ldconfigs   /[^\(\)\s]*%s\.[^\(\)\s]*s   -ps   /libs   /usr/libs   /opt/freeware/libN(   R   R   R   R   RV   RW   R   Ri   R   t   pathsepR    R   R   R   R   t   escapeR   R   R   R:   Ra   t	   getSoname(	   RX   R(   t   lpR   t   libst   exprR   t   pathst   dir(    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\bindepend.pyt   findLibraryC  s<    

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   RV   R   R   (   R   R   R   (    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\bindepend.pyR   y  s    c          C   s  t  j d  }  t r# d |  f } nj t r9 d |  f } nT t rU d d d |  f } n8 t rk d |  f } n" t r d |  f } n t d	   t t  j	  } xc | D][ } xR | D]J } t
 j j |  | k r t r t
 j j |  r t |  } n  | Sq Wq Wt r2x | D] } t |  } | r| SqWnc t rt j rMt  j } n	 t  j } x< | D]1 } t
 j j | |  } t
 j j |  r]| Sq]Wn  d
 S(   s  
    Find dynamic Python library that will be bundled with frozen executable.

    Return  full path to Python dynamic library or None when not found.


    We need to know name of the Python dynamic library for the bootloader.
    Bootloader has to know what library to load and not trying to guess.

    Some linux distributions (e.g. debian-based) statically build the
    Python executable to the libpython, so bindepend doesn't include
    it in its output. In this situation let's try to find it.

    Darwin custom builds could possibly also have non-framework style libraries,
    so this method also checks for that variant as well.
    i   s   python%d%d.dlls   libpython%d%d.dllt   Pythons   .Pythons   libpython%d.%d.dylibs   libpython%d.%d.as   libpython%d.%d.so.1.0s#   Your platform is not yet supported.N(   R   t   version_infoR   R   R   R   R   Ro   R   t
   executableR   R   R   R   R"   R   RV   t   is_virtualenvt   real_prefixt   prefixR   R   R   (   t   pyvert   namesR3   R   RX   t   python_libnamet	   py_prefixt	   full_path(    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\bindepend.pyt   get_python_library_path  sB    		(3   t   __doc__R   R   R   R    Rl   t   PyInstaller.compatR   R   R   R   R   R   t   PyInstaller.dependR   t   PyInstaller.utilsR   RV   t   PyInstaller.logt   logR   t	   getLoggert   __file__RD   RA   R   t   win32apit   ImportErrorRo   t   PyInstaller.utils.winmanifestR	   R
   R   R   t   detailR   R"   R6   R?   RM   Rc   R8   R   RF   RG   R   R   R   R   R   R   (    (    (    sX   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\bindepend.pyt   <module>   sR   . 		 	+5	285	&	\		6	
