ó
Šś"Pc           @   s  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 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 S(   i˙˙˙˙N(   t	   is_darwint   set(   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(    (    sL   /home/salopaasi/Documents/Moo/pyinstaller-2.0/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   (    (    sL   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/hooks/hookutils.pyt   exec_statement(   s    c         G   sb   |  t  j j |   k r' t d   n  t  j j t  j j t  |   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` directory.
    sh   To prevent missuse, the script passed to hookutils.exec-script must be located in the `hooks` directory.(	   R   t   patht   basenamet   SystemErrorR   t   dirnamet   __file__t   extendR   (   t   scriptfilenamet   argsR   (    (    sL   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/hooks/hookutils.pyt   exec_script0   s
    
$c         C   s&   t  |   j   } | s d St |  S(   Nt    (   R   R   t   eval(   R   R   (    (    sL   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/hooks/hookutils.pyt   eval_statementD   s    c         G   s)   t  |  |  j   } | s d St |  S(   NR#   (   R"   R   R$   (   R    R!   R   (    (    sL   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/hooks/hookutils.pyt   eval_scriptL   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(    (    sL   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/hooks/hookutils.pyt   get_pyextension_importsT   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(    (    sL   /home/salopaasi/Documents/Moo/pyinstaller-2.0/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   R,   R-   (   R.   R/   (    (    sL   /home/salopaasi/Documents/Moo/pyinstaller-2.0/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(   R0   R   t   dlls_in_dirR   R   R   t   appendR   (   t   plugin_typet   binariest   pdirt   filest   f(    (    sL   /home/salopaasi/Documents/Moo/pyinstaller-2.0/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 d l } d } | 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/Resourcesi˙˙˙˙NsA   /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   globt   existsR(   R)   (   t   menu_dirt   macports_prefixt   dirsRD   t   globpatht   qt_homebrew_dirsR/   (    (    sL   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/hooks/hookutils.pyt   qt4_menu_nib_dir§   s(    	
c         C   s0   t  j j |   } t j d d |  t d  S(   Nt   DJANGO_SETTINGS_MODULEs   %s.settingss   django-import-finder.py(   R   R   R   R	   R   R&   (   t   django_root_dirt   package_name(    (    sL   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/hooks/hookutils.pyt   django_dottedstring_importsĚ   s    c      	   C   sí   t  t j |    } d | k r@ d | k r@ d | k r@ |  g Sg  } x | D] } t j j |  |  } t j j |  rM y t j |  } Wn t t f k
 rŠ qM n Xd | k rá d | k rá d | k rá | j |  qá qM qM W| Sd  S(   Ns	   manage.pys   settings.pys   urls.py(	   R   R   t   listdirR   R   R,   t   IOErrorR   R5   (   t   dirt   entitiest   django_root_directoriest   entityt   path_to_analyzet   dir_entities(    (    sL   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/hooks/hookutils.pyt   find_django_rootŇ   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   lowerR5   (   t   all_bkt   avail_bkt   import_statementt   bkt   stdoutt   x(    (    sL   /home/salopaasi/Documents/Moo/pyinstaller-2.0/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   RD   t   splitextR   R5   (   R   t   opengl_mod_patht   arrays_mod_pathR9   t   modulesR:   t   mod(    (    sL   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/hooks/hookutils.pyt   opengl_arrays_modules  s    "(   RD   R   RA   R   t   PyInstaller.compatR	   R    R   t   PyInstaller.utilsR   t   PyInstaller.logt   logt   loggingt	   getLoggert   __name__R(   R   R   R"   R%   R&   R+   R0   R1   R;   RK   RO   RX   Rc   Rm   (    (    (    sL   /home/salopaasi/Documents/Moo/pyinstaller-2.0/PyInstaller/hooks/hookutils.pyt   <module>   s,   						'				%			!