ó
 –Qc           @   sw  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l j Z d  d l m Z d  d l m Z d  d l	 j
 Z e j e ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! e" d d d d d g ƒ Z# d „  Z$ e" d d d d d d g ƒ Z% d „  Z& d S(   iÿÿÿÿN(   t	   is_darwin(   t   miscc         C   sÌ   t  j j t j ƒ } t j d ƒ } | rE t  j j | | g ƒ } n  t j d | ƒ z= y t j |  Œ  } Wn# t	 k
 r } t
 d | ƒ ‚ n XWd | d k	 r´ t j d | ƒ n t j d ƒ X| j ƒ  S(   s”   
    Executes an externally spawned Python interpreter and returns
    anything that was emitted in the standard output as a single
    string.
    t
   PYTHONPATHs   Execution failed: %sN(   t   ost   pathsept   joint   PyInstallert
   __pathex__t   compatt   getenvt   setenvt   exec_pythont   OSErrort
   SystemExitt   Nonet   unsetenvt   strip(   t   cmdt   ppt   old_ppt   txtt   e(    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   __exec_python_cmd   s    c         C   s   d |  g } t  | ƒ S(   s›   Executes a Python statement in an externally spawned interpreter, and
    returns anything that was emitted in the standard output as a single string.
    s   -c(   R   (   t	   statementR   (    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   exec_statement0   s    c         G   s¸   t  j j d t  j j |  ƒ ƒ }  t  j j t  j j t ƒ |  ƒ }  t  j j |  ƒ sc t d ƒ ‚ n  t  j j t  j j t	 j
 d ƒ ƒ } t	 j j | ƒ |  g } | j | ƒ t | ƒ S(   s  
    Executes a Python script in an externally spawned interpreter, and
    returns anything that was emitted in the standard output as a
    single string.

    To prevent missuse, the script passed to hookutils.exec-script
    must be located in the `hooks/utils` directory.
    t   utilssn   To prevent missuse, the script passed to hookutils.exec-script must be located in the `hooks/utils` directory.i    (   R   t   pathR   t   basenamet   dirnamet   __file__t   existst   SystemErrort   abspathR   t   __path__R   t   appendt   extendR   (   t   script_filenamet   argst   pyinstaller_root_dirR   (    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   exec_script8   s    	!!%	c         C   s&   t  |  ƒ j ƒ  } | s d St | ƒ S(   Nt    (   R   R   t   eval(   R   R   (    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   eval_statementQ   s    c         G   s)   t  |  | Œ j ƒ  } | s d St | ƒ S(   NR(   (   R'   R   R)   (   t   scriptfilenameR%   R   (    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   eval_scriptY   s    c         C   s<   d i |  d 6} t  | ƒ } | s8 t j d |  ƒ g  S| S(   sÅ  
    Return list of modules required by binary (C/C++) Python extension.

    Python extension files ends with .so (Unix) or .pyd (Windows).
    It's almost impossible to analyze binary extension and its dependencies.

    Module cannot be imported directly.

    Let's at least try import it in a subprocess and get the diffrence
    in module list from sys.modules.

    This function could be used for 'hiddenimports' in PyInstaller hooks files.
    s´  
import sys
# Importing distutils filters common modules, especiall in virtualenv.
import distutils
original_modlist = sys.modules.keys()
# When importing this module - sys.modules gets updated.
import %(modname)s
all_modlist = sys.modules.keys()
diff = set(all_modlist) - set(original_modlist)
# Module list contain original modname. We do not need it there.
diff.discard('%(modname)s')
# Print module list to stdout.
print list(diff)
t   modnames!   Cannot find imports for module %s(   R*   t   loggert   error(   R-   R   t   module_imports(    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   get_pyextension_importsa   s    c          C   sa   t  d ƒ }  |  s# t j d ƒ d Sx* |  D]" } t j j | ƒ r* t | ƒ Sq* Wt j d ƒ d S(   Nsh   from PyQt4.QtCore import QCoreApplication;app=QCoreApplication([]);print map(unicode,app.libraryPaths())s$   Cannot find PyQt4 plugin directoriesR(   s+   Cannot find existing PyQt4 plugin directory(   R*   R.   R/   R   R   t   isdirt   str(   t   qt4_plugin_dirst   d(    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   qt4_plugins_dir‡   s    	c          C   sa   t  d ƒ }  |  s# t j d ƒ d Sx* |  D]" } t j j | ƒ r* t | ƒ Sq* Wt j d ƒ d S(   NsÑ   from PyQt4.QtGui import QApplication;app=QApplication([]); app.setApplicationName('pyinstaller');from PyQt4.phonon import Phonon;v=Phonon.VideoPlayer(Phonon.VideoCategory);print map(unicode,app.libraryPaths())s+   Cannot find PyQt4 phonon plugin directoriesR(   s2   Cannot find existing PyQt4 phonon plugin directory(   R*   R.   R/   R   R   R2   R3   (   R4   R5   (    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   qt4_phonon_plugins_dir–   s    	c         C   sv   g  } t  ƒ  } t j t j j | |  ƒ ƒ } xB | D]: } | j t j j d |  t j j | ƒ ƒ | d f ƒ q4 W| S(   s;   Return list of dynamic libraries formated for mod.binaries.t   qt4_pluginst   BINARY(   R6   R   t   dlls_in_dirR   R   R   R"   R   (   t   plugin_typet   binariest   pdirt   filest   f(    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   qt4_plugins_binaries§   s    	!c       
   C   sß   d }  t  j j d ƒ d } t j j | d d ƒ t j j | d d d d d	 d
 d ƒ d d d g } d } t j | ƒ } | | 7} x? | D]7 } t j j | d ƒ } t j j | ƒ rŠ | }  PqŠ qŠ W|  sÛ t j	 d ƒ n  |  S(   s+   Return path to Qt resource dir qt_menu.nib.R(   s   /Libraryi    t   libt	   Resourcest   libexecs   qt4-macs   QtGui.frameworkt   Versionst   4s-   /Library/Frameworks/QtGui.framework/Resourcess8   /Library/Frameworks/QtGui.framework/Versions/4/Resourcess>   /Library/Frameworks/QtGui.Framework/Versions/Current/ResourcessA   /usr/local/Cellar/qt/4.*/lib/QtGui.framework/Versions/4/Resourcess   qt_menu.nibs"   Cannont find qt_menu.nib directory(
   t   syst
   executablet   splitR   R   R   t   globR   R.   R/   (   t   menu_dirt   macports_prefixt   dirst   globpatht   qt_homebrew_dirsR5   (    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   qt4_menu_nib_dir³   s&    	
c         C   sl   t  j j |  ƒ } t j d d | ƒ t j j t j	 |  ƒ ƒ t j j |  ƒ t
 d ƒ } t j d ƒ | S(   sŸ   
    Get all the necessary Django modules specified in settings.py.

    In the settings.py the modules are specified in several variables
    as strings.
    t   DJANGO_SETTINGS_MODULEs   %s.settingss   django-import-finder.py(   R   R   R   R   R
   R   R   R"   R   t   get_path_to_toplevel_modulesR,   R   (   t   django_root_dirt   package_namet   ret(    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   django_dottedstring_imports×   s    c          C   sä   t  j d d }  t j j t j j |  ƒ ƒ } d } t t j | ƒ ƒ } d | k rk d | k rk | } nu xr | D]j } t j j	 | ƒ rr t j t j j
 | | ƒ ƒ } d | k rÜ d | k rÜ t j j
 | | ƒ } PqÜ qr qr W| S(   sŽ  
    Return path to directory (top-level Python package) that contains main django
    files. Return None if no directory was detected.

    Main Django project directory contain files like '__init__.py', 'settings.py'
    and 'url.py'.

    In Django 1.4+ the script 'manage.py' is not in the directory with 'settings.py'
    but usually one level up. We need to detect this special case too.
    t   scriptsi    s   settings.pys   urls.pyN(   RF   t   _PYI_SETTINGSR   R   R   R    R   t   sett   listdirR2   R   (   t	   manage_pyt
   manage_dirt   settings_dirR>   R?   t   subfiles(    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   django_find_root_dirï   s    	c          C   s™   t  d ƒ }  g  } d } t r; d |  k r; |  j d ƒ n  x: |  D]2 } t | | j ƒ  ƒ } | sB | j | ƒ qB qB Wg  | D] } d | j ƒ  ^ q S(   sÏ   
    Return matplotlib backends availabe in current Python installation.

    All matplotlib backends are hardcoded. We have to try import them
    and return the list of successfully imported backends.
    s8   import matplotlib; print matplotlib.rcsetup.all_backendss_   
try:
    __import__('matplotlib.backends.backend_%s')
except ImportError, e:
    print str(e)
t   CocoaAggt   backend_(   R*   R    t   removeR   t   lowerR"   (   t   all_bkt   avail_bkt   import_statementt   bkt   stdoutt   x(    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   matplotlib_backends  s    c          C   s£   d }  t  j j j |  ƒ } t j j | d ƒ } t j | d ƒ } g  } xS | D]K } t j j t j j	 | ƒ ƒ d } | d k rŠ qP n  | j
 d | ƒ qP W| S(   sW   
    Return list of array modules for OpenGL module.

    e.g. 'OpenGL.arrays.vbo'
    s'   import OpenGL; print OpenGL.__path__[0]t   arrayss   /*.pyi    t   __init__s   OpenGL.arrays.(   R   t   hookst	   hookutilsR   R   R   R   RI   t   splitextR   R"   (   R   t   opengl_mod_patht   arrays_mod_pathR>   t   modulesR?   t   mod(    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   opengl_arrays_modules2  s    "c         C   s%   |  j  | ƒ r |  t | ƒ S|  Sd S(   s¤   
    This funtion removes the given prefix from a string, if the string does
    indeed begin with the prefix; otherwise, it returns the string
    unmodified.
    N(   t
   startswitht   len(   t   stringt   prefix(    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   remove_prefixH  s    c         C   s,   | r$ |  j  | ƒ r$ |  t | ƒ  S|  Sd S(   s¢   
    This funtion removes the given suffix from a string, if the string
    does indeed end with the prefix; otherwise, it returns the string
    unmodified.
    N(   t   endswithRu   (   Rv   t   suffix(    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   remove_suffixT  s    c         C   s   t  j j |  ƒ d S(   s>   
    This funtion returns filename without its extension.
    i    (   R   R   Rn   (   t   filename(    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   remove_file_extensionb  s    c         C   s   d } t  | |  ƒ S(   sŽ   
    Given a pacage name, return the value of __file__ attribute.

    In PyInstaller process we cannot import directly analyzed modules.
    sè  
# Fun Python behavior: __import__('mod.submod') returns mod,
# where as __import__('mod.submod', fromlist = [a non-empty list])
# returns mod.submod. See the docs on `__import__
# <http://docs.python.org/library/functions.html#__import__>`_.
# Keyworded arguments in __import__ function are available
# in Python 2.5+. Compatibility with Python 2.4 is preserved.
_fromlist = ['']
_globals = {}
_locals = {}
package = __import__('%s', _globals, _locals, _fromlist)
print package.__file__
(   R   (   t   packaget   __file__statement(    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   get_module_file_attributei  s    c         C   sh   d } t  | |  ƒ } | s" t ‚ t |  ƒ } t j j | ƒ } t | |  j d t j ƒ ƒ } | | f S(   s6  
    Given a package, return the path to packages stored on this machine
    and also returns the path to this particular package. For example,
    if pkg.subpkg lives in /abs/path/to/python/libs, then this function
    returns (/abs/path/to/python/libs,
             /abs/path/to/python/libs/pkg/subpkg).
    s,   import %s as p; print hasattr(p, "__path__")t   .(	   R*   t   AssertionErrorR€   R   R   R   R{   t   replacet   sep(   R~   t   is_pkg_statementt
   is_packaget	   file_attrt   pkg_dirt   pkg_base(    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   get_package_paths€  s    
s   .pys   .pycs   .pyds   .pyos   .soc   
      C   sé   t  |  ƒ \ } } t ƒ  } xÁ t j | ƒ D]° \ } } } t | | ƒ j t j d ƒ } d | k r× | j | ƒ xg | D]X } t j j	 | ƒ d }	 t
 | ƒ d k rx |	 t k rx | j | d t
 | ƒ ƒ qx qx Wq+ | 2q+ Wt | ƒ S(   s  
    The following two functions were originally written by Ryan Welsh
    (welchr AT umich.edu).

    This produces a list of strings which specify all the modules in
    package.  Its results can be directly assigned to ``hiddenimports``
    in a hook script; see, for example, hook-sphinx.py. The
    package parameter must be a string which names the package.

    This function does not work on zipped Python eggs.

    This function is used only for hook scripts, but not by the body of
    PyInstaller.
    R   s   __init__.pyi   Rk   (   RŠ   RX   R   t   walkRx   Rƒ   R„   t   addR   Rn   R}   t   PY_EXECUTABLE_EXTENSIONSt   list(
   R~   R‰   Rˆ   t   modst   dirpatht   dirnamest	   filenamest   mod_pathR?   t	   extension(    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   collect_submodulesŸ  s    	%t   dylibc         C   s¿   t  |  ƒ \ } } g  } x  t j | ƒ D] \ } } } x} | D]u } t j j | ƒ d } | t k r> t j j | | ƒ }	 t | t j j | ƒ t j	 ƒ }
 | j
 |	 |
 f ƒ q> q> Wq( W| S(   s²  
    This routine produces a list of (source, dest) non-Python (i.e. data)
    files which reside in package. Its results can be directly assigned to
    ``datas`` in a hook script; see, for example, hook-sphinx.py. The
    package parameter must be a string which names the package.

    This function does not work on zipped Python eggs.

    This function is used only for hook scripts, but not by the body of
    PyInstaller.
    i   (   RŠ   R   R‹   R   Rn   t   PY_IGNORE_EXTENSIONSR   Rx   R   R„   R"   (   R~   R‰   Rˆ   t   datasR   R‘   R>   R?   R”   t   sourcet   dest(    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   collect_data_filesÎ  s    ('   RI   R   RF   R   t   PyInstaller.compatR   R    t   PyInstaller.utilsR   t   PyInstaller.logt   logt   loggingt	   getLoggert   __name__R.   R   R   R'   R*   R,   R1   R6   R7   R@   RO   RU   R^   Ri   Rs   Rx   R{   R}   R€   RŠ   RX   R   R•   R—   R›   (    (    (    s^   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\hooks\hookutils.pyt   <module>   s>   						&				$		"	!							,