ó
öé{Tc           @   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($   iÿÿÿÿN(   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(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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    iÿÿÿÿs   
s   (   R   N(   s   
s   (   t   syst   platformR   t   popent   readt   closet   commandsR   (   R   t   pipet   textt   stsR   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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(    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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+   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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 pathiÿÿÿÿt   .(   t   findR   t   sept   splitt   stringt   joinR   t   abspatht   listdirt   fnmatcht   append(   t   dirt   partsR   t   retvalt   file(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/gtk-2.0/dsextras.pyRg   Á   s    !		(   t   __name__t
   __module__R[   R_   R`   Rg   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/gtk-2.0/dsextras.pyRp   ß   s    c         C   s   t  j |  ƒ |  j S(   N(   R   t
   get_inputst   local_inputs(   RX   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/gtk-2.0/dsextras.pyRr   â   s    (   Rk   Rl   Rq   Rs   Ro   Rp   Rr   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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   ntiýÿÿÿiüÿÿÿs   ${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   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/gtk-2.0/dsextras.pyt   prepareë   s     +(					c         C   s   | |  _  d  S(   N(   Rn   (   RX   Rn   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/gtk-2.0/dsextras.pyRo     s    c         C   s   | |  j  d | <d  S(   Ns   @%s@(   t   template_options(   RX   RB   t   value(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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.iÿÿÿÿiýÿÿÿt   wb(   R   R   R1   R   R$   R�   t   itemsRJ   R3   t   mkpatht   writeRs   R7   Rq   (   RX   t   filenameRn   t   output_filet   templatet   keyR‚   RK   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/gtk-2.0/dsextras.pyt   install_template  s    c         C   s   t  j |  ƒ |  j S(   N(   R   Rp   Rq   (   RX   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/gtk-2.0/dsextras.pyRp     s    c         C   s   t  j |  ƒ |  j S(   N(   R   Rr   Rs   (   RX   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/gtk-2.0/dsextras.pyRr     s    (   Rk   Rl   Rq   Rs   R�   R€   Ro   R~   R‹   Rp   Rr   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/gtk-2.0/dsextras.pyt	   can_buildf  s*    				c         C   s   d  S(   N(    (   RX   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/gtk-2.0/dsextras.pyRa   †  s    N(   Rk   Rl   R‘   R   Rž   R˜   R’   R•   R–   R¢   Ra   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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ª   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/gtk-2.0/dsextras.pyRa   ¼  s$    

	

N(	   Rk   Rl   R¨   R   R>   R˜   Rµ   R¼   Ra   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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«   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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    iûÿÿÿs   .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®   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/gtk-2.0/dsextras.pyR˜   à  s&    


	



c         C   s   t  d „  |  j ƒ d  S(   Nc         S   s
   |  j  ƒ  S(   N(   Ra   (   t   x(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/gtk-2.0/dsextras.pyt   <lambda>ý  s    (   R@   RÉ   (   RX   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/gtk-2.0/dsextras.pyRa   ü  s    (   Rk   Rl   R¨   R˜   Ra   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-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Æ   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/gtk-2.0/dsextras.pyt   <module>   sN    
												?8lN