
TgdNc           @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l	 m
 Z
 d  d l m Z d  d l m Z d  d l m Z yL d  d l Z d  d l m Z d  d	 l m Z d  d
 l m Z m Z m Z Wn e k
 re Z n Xe Z g  Z g  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 e f d     YZ. d e
 f d     YZ/ d e f d     YZ0 d e f d     YZ1 d  e2 f d!     YZ3 d" e1 f d#     YZ4 d S($   iN(   t   dep_util(   t	   build_ext(   t   install_lib(   t   install_data(   t	   Extension(   t   find_executable(   t	   Overrides(   t
   DefsParser(   t   register_typest   SourceWritert
   FileOutputs  
***************************************************************************
Codegen could not be found on your system and is required by the
dsextras.Template and dsextras.TemplateExtension classes.
***************************************************************************
c         C   s   t  j d |  d  } t j j d  r2 d } n' t j j d  rM d } n t d   x< t |  j   D]( } | j |  } | rl | j	 d  Sql Wd S(   s@   Return the value of a m4_define variable as set in configure.in.s   m4_define\(s   \,\s*(.+)\)s   configure.acs   configure.ins$   ERROR: Could not find configure filei   N(   t   ret   compilet   ost   patht   existst
   SystemExitt   opent	   readlinest   matcht   groupt   None(   t   varnamet   patternt   fnamet   linet	   match_obj(    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   get_m4_define*   s    		c         C   s   t  |   d S(   s=   Return output (stdout or stderr) of executing cmd in a shell.i   (   t   getstatusoutput(   t   cmd(    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt	   getoutput=   s    c         C   s   t  j d k rj t j |  d  } | j   } | j   p< d } x | d d	 k r_ | d  } qB W| | f Sd d l m } | |   Sd S(
   s4   Return (status, output) of executing cmd in a shell.t   win32t   ri    is   
s   (   R   N(   s   
s   (   t   syst   platformR   t   popent   readt   closet   commandsR   (   R   t   pipet   textt   stsR   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyR   A   s    
c           C   s   t  d  r t Sd S(   s   Checks for the existence of gcct   gccN(   R   t   True(    (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   have_gccP   s    c           C   s   t  d  r t Sd S(   s&   Checks for the existence of pkg-configs
   pkg-configN(   R   R+   (    (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   have_pkgconfigU   s    c         C   s   |  j  t j  d k rP |  j t j  } t j | d  t j  }  | d } n |  } d }  t j j |   }  g  } xH t j |   D]7 } t	 j	 | |  r | j
 t j j |  |   q q W| S(   s   List all files in a dir, with filename match support:
    for example: glade/*.glade will return all files in the glade directory
    that matches *.glade. It also looks up the full pathit   .(   t   findR   t   sept   splitt   stringt   joinR   t   abspatht   listdirt   fnmatcht   append(   t   dirt   partsR   t   retvalt   file(    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt
   list_filesZ   s    #c         C   sn   t  j d |   } | s t St |   } t t | j d   } t t | j d   } | | k rj t St S(   ss   Check the existence and version number of a package:
    returns False if not installed or too old, True otherwise.s   pkg-config --exists %sR.   (   R   t   systemt   Falset   pkgc_get_versiont   mapt   intR1   R+   (   t   namet   req_versiont   is_installedt   orig_versiont   versiont   pkc_version(    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   pkgc_version_checko   s    c         C   s   t  d |   S(   s7   return the version as return by pkg-config --modversions   pkg-config --modversion %s(   R   (   RB   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyR?      s    c         C   s&   t  d |   } | j d d  j   S(   sC   returns a list of libraries as returned by pkg-config --libs-only-ls   pkg-config --libs-only-l %ss   -lt    (   R   t   replaceR1   (   RB   t   output(    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   pkgc_get_libraries   s    c         C   s&   t  d |   } | j d d  j   S(   sF   returns a list of library dirs as returned by pkg-config --libs-only-Ls   pkg-config --libs-only-L %ss   -LRI   (   R   RJ   R1   (   RB   RK   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   pkgc_get_library_dirs   s    c         C   s&   t  d |   } | j d d  j   S(   sH   returns a list of include dirs as returned by pkg-config --cflags-only-Is   pkg-config --cflags-only-I %ss   -IRI   (   R   RJ   R1   (   RB   RK   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   pkgc_get_include_dirs   s    c         C   s   t  d |   } | S(   sA   returns the defs dir as returned by pkg-config --variable=defsdirs    pkg-config --variable=defsdir %s(   R   (   RB   RK   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   pkgc_get_defs_dir   s    t   BuildExtc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s   g  |  _  t j d k r |  j j d k r t   sB t d   n  i d d 6d d 6d d 6} t d	  } d
 | | | d f GH|  j  j | | d  n  d  S(   NR   t   mingw32s   ERROR: Could not find gcc.s   -fnative-structt   2s   -mms-bitfieldst   3t   4s   gcc -dumpversions)   using MinGW GCC version %s with %s optioni    (	   t   extra_compile_argsR!   R"   t   compilert   compiler_typeR,   R   R   R7   (   t   selft   msnative_structt   gcc_version(    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   init_extra_compile_args   s    	!	

c         C   sk   t  j d k rg |  j j d k rg t   s9 t d   n  |  j j j d  rg |  j j j d  qg n  d  S(   NR   RQ   s   ERROR: Could not find gcc.s   -static(	   R!   R"   RV   RW   R,   R   t	   linker_sot   countt   remove(   RX   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   modify_compiler   s
    !	c         C   s%   |  j    |  j   t j |   d  S(   N(   R[   R_   R   t   build_extensions(   RX   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyR`      s    

c         C   s   | j  |  j  7_  t | d  r. | j   n  t j d k r |  j j d k r | j } g  | j D] } | d k rb | ^ qb | _ n	 | j } t j	 |  |  | d  k	 r | | j k r | | _ n  d  S(   Nt   generateR   t   msvct   ct   m(   Rc   Rd   (   RU   t   hasattrRa   R!   R"   RV   RW   t	   librariesR   t   build_extensionR   (   RX   t   extt	   save_libst   lib(    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyRg      s    !		(   t   __name__t
   __module__R[   R_   R`   Rg   (    (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyRP      s   		
	t
   InstallLibc           B   s/   e  Z g  Z g  Z d    Z d   Z d   Z RS(   c         C   s   | |  _  d  S(   N(   t   install_dir(   RX   Rn   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   set_install_dir   s    c         C   s   t  j |   |  j S(   N(   R   t   get_outputst   local_outputs(   RX   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyRp      s    c         C   s   t  j |   |  j S(   N(   R   t
   get_inputst   local_inputs(   RX   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyRr      s    (   Rk   Rl   Rq   Rs   Ro   Rp   Rr   (    (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyRm      s
   		t   InstallDatac           B   sP   e  Z g  Z g  Z i  Z d    Z d   Z d   Z d   Z d   Z	 d   Z
 RS(   c         C   s(  t  j d k r: t  j j |  j j t  j  d   |  _ n( t  j j |  j j t  j  d   |  _ d |  _ d |  _ d |  _	 d |  _
 d |  _ |  j d |  j  |  j d	 |  j  |  j d
 |  j  |  j d |  j	  |  j d |  j
  |  j d |  j  |  j d t j  |  j d d  d  S(   Nt   ntiis   ${prefix}/bins   ${prefix}/includes   ${prefix}/libs   ${prefix}/sharet   prefixt   exec_prefixt
   includedirt   libdirt   datarootdirt   datadirt   PYTHONt   THREADING_CFLAGSRI   (   R   RB   R0   R3   Rn   R1   Rv   Rw   Rx   Ry   Rz   R{   t   add_template_optionR!   t
   executable(   RX   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   prepare   s     +(					c         C   s   | |  _  d  S(   N(   Rn   (   RX   Rn   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyRo     s    c         C   s   | |  j  d | <d  S(   Ns   @%s@(   t   template_options(   RX   RB   t   value(    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyR~     s    c         C   s   t  j j |  d d  } t |  j   } x/ |  j j   D] \ } } | j | |  } q< Wt  j j | |  } |  j	 |  t | d  j
 |  |  j j |  |  j j |  | S(   s<   Install template filename into target directory install_dir.iit   wb(   R   R   R1   R   R$   R   t   itemsRJ   R3   t   mkpatht   writeRs   R7   Rq   (   RX   t   filenameRn   t   output_filet   templatet   keyR   RK   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   install_template  s    c         C   s   t  j |   |  j S(   N(   R   Rp   Rq   (   RX   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyRp     s    c         C   s   t  j |   |  j S(   N(   R   Rr   Rs   (   RX   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyRr     s    (   Rk   Rl   Rq   Rs   R   R   Ro   R~   R   Rp   Rr   (    (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyRt      s   					t   PkgConfigExtensionc           B   sJ   e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(   s   pygobject-2.0c         K   s  | d } d | k r6 | d c |  j  |  t 7<n |  j  |  t | d <t | d <d | k r | d c |  j |  7<n |  j |  | d <d | k r | d c |  j |  7<n |  j |  | d <d | k r | j d  |  _ n  |  j rN| d c |  j  |  j  7<| d c |  j |  j  7<| d c |  j |  j  7<n  | d |  _ | d |  _ | d |  _	 | d =| d =t
 j |  |  d  S(	   Nt   pkc_namet   include_dirst   define_macrosRf   t   library_dirst   pygobject_pkcRB   RG   (   t   get_include_dirst
   GLOBAL_INCt   GLOBAL_MACROSt   get_librariest   get_library_dirst   popR   RB   R   RG   R   t   __init__(   RX   t   kwargsRB   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyR   #  s,    
 
	c         C   sL   t  |  t k r | f } n  g  } x! | D] } | j t |   q+ W| S(   N(   t   typet   tuplet   extendRN   (   RX   t   namesR:   RB   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyR   E  s    c         C   sL   t  |  t k r | f } n  g  } x! | D] } | j t |   q+ W| S(   N(   R   R   R   RL   (   RX   R   R:   RB   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyR   P  s    c         C   sL   t  |  t k r | f } n  g  } x! | D] } | j t |   q+ W| S(   N(   R   R   R   RM   (   RX   R   R:   RB   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyR   [  s    c         C   s  |  j  d k	 r |  j  St |  j  t k rC |  j |  j f g } n t |  j |  j  } x | D] \ } } t j d |  } | r d | |  j	 f GHt
 |  _  t
 St |  } t t | j d   t t | j d   k r t |  _  t Sd | GHd | | f GHt
 |  _  t
 Sq_ Wd S(   s.   If the pkg-config version found is good enoughs   pkg-config --exists %ss>   * %s.pc could not be found, bindings for %s will not be built.R.   s   Warning: Too old version of %ss%            Need %s, but %s is installedN(   t   can_build_okR   R   R   R   RG   t   zipR   R=   RB   R>   R?   R@   RA   R1   R+   (   RX   t   reqst   packageRF   R:   RE   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt	   can_buildf  s*    				c         C   s   d  S(   N(    (   RX   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyRa     s    N(   Rk   Rl   R   R   R   R   R   R   R   R   Ra   (    (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyR     s   	"				 t   Templatec           B   s>   e  Z d    Z g  d e d  Z d   Z d   Z d   Z RS(   c         O   s/   t  s" t d |  j t f   n  t j |   S(   Ns   '%s' is not defined
%s(   t   template_classes_enabledt	   NameErrorRk   t   codegen_error_messaget   objectt   __new__(   t   clst   argst   kwds(    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyR     s    c   	      C   s   | |  _  | |  _ | |  _ | |  _ | |  _ g  |  _ t | t  re | d |  _ |  j j	 |  n	 | |  _ g  |  _
 xT | D]L } t | t  r |  j
 j	 | d  |  j j	 |  q~ |  j
 j	 |  q~ Wd  S(   Ni    (   t   overrideRK   Rv   t
   load_typest   py_ssize_t_cleant
   built_defst
   isinstanceR   t   defsR7   t   register(	   RX   R   RK   R   Rv   R   R   R   R    (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyR     s     								c         C   s>   |  j  } | j |  j  | j |  j  t j | |  j  S(   N(   R   R7   R   R   R    t   newer_groupRK   (   RX   t   files(    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   check_dates  s    
c         C   sS   xL |  j  D]A \ } } t j | |  r
 d | g | } t j j |  q
 q
 Wd  S(   Nt   dummy(   R   R    R   t   codegent
   createdefst   main(   RX   t   targett   sourcesR   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   generate_defs  s    c         C   s  |  j    |  j   r d  Sx: |  j D]/ } t | t t   } | j   t |  q$ W|  j ry i  } t	 |  j |  n  t |  j
 t t   } | j   t |  t |  j d  } t | t |  j  |  j t | |  j   } | j |  j  | j   d  S(   Nt   w(   R   R   R   R   t   dictR   t   startParsingR   R   t   execfileR   R   RK   R	   R   R   Rv   R
   R   R   R%   (   RX   t   itemt   dpt   globalst   fdt   sw(    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyRa     s$    

	

N(	   Rk   Rl   R   R   R>   R   R   R   Ra   (    (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyR     s
   				t   TemplateExtensionc           B   s#   e  Z d    Z d   Z d   Z RS(   c         O   s5   t  s" t d |  j t f   n  t j |  | |  S(   Ns   '%s' is not defined
%s(   R   R   Rk   R   R   R   (   R   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyR     s    c      	   K   s
  | d } | d } t  | t  r8 | d d  d } n | d  d } | d } | j d  } | j d t  } g  |  _ |  j j t | | | d	 | | d
 | |   | d
 =| d =| d =| r | d =n  | j d  r | d | d <| d =n  t	 j
 |  |  d  S(   NRB   R   i    is   .cR   R   R   t   pyR   RK   (   R   R   t   getR   R>   t	   templatesR7   R   t   has_keyR   R   (   RX   R   RB   R   RK   R   R   R   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyR     s&    


	



c         C   s   t  d   |  j  d  S(   Nc         S   s
   |  j    S(   N(   Ra   (   t   x(    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   <lambda>  s    (   R@   R   (   RX   (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyRa     s    (   Rk   Rl   R   R   Ra   (    (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyR     s   		(5   R   R!   R6   R   R2   t	   distutilsR    t   distutils.command.build_extR   t   distutils.command.install_libR   t   distutils.command.install_dataR   t   distutils.extensionR   t   distutils.spawnR   t   codegen.createdefsR   t   codegen.overrideR   t   codegen.defsparserR   t   codegen.codegenR   R	   R
   t   ImportErrorR>   R   R+   R   R   R   R   R   R   R,   R-   R<   RH   R?   RL   RM   RN   RO   RP   Rm   Rt   R   R   R   R   (    (    (    s4   /usr/lib/python2.7/dist-packages/gtk-2.0/dsextras.pyt   <module>   sN    
												?8lN