
XGc           @   s  d  Z  d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k	 Z	 d d k
 Z
 d d k Z d d k Td d k l Z l Z d d k Z d d k Z d Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z h  Z d   Z d   Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# e$ d j o e#   n d S(   s  
Pyste version %s

Usage:
    pyste [options] interface-files

where options are:
    --module=<name>         The name of the module that will be generated;
                            defaults to the first interface filename, without
                            the extension.
    -I <path>               Add an include path    
    -D <symbol>             Define symbol    
    --multiple              Create various cpps, instead of only one 
                            (useful during development)                        
    --out=<name>            Specify output filename (default: <module>.cpp)
                            in --multiple mode, this will be a directory
    --no-using              Do not declare "using namespace boost";
                            use explicit declarations instead
    --pyste-ns=<name>       Set the namespace where new types will be declared;
                            default is the empty namespace
    --debug                 Writes the xml for each file parsed in the current
                            directory
    --cache-dir=<dir>       Directory for cache files (speeds up future runs)
    --only-create-cache     Recreates all caches (doesn't generate code).
    --generate-main         Generates the _main.cpp file (in multiple mode)
    --file-list             A file with one pyste file per line. Use as a 
                            substitute for passing the files in the command
                            line.
    --gccxml-path=<path>    Path to gccxml executable (default: gccxml)
    --no-default-include    Do not use INCLUDE environment variable for include
                            files to pass along gccxml.
    -h, --help              Print this help and exit
    -v, --version           Print version information                         
iN(   t   *(   t	   CppParsert   CppParserErrors   0.9.30c            s2   |  g     f d   } t  i i |  | d    S(   sA   Return a list containg the include dir and all its subdirectoriesc            s2   t  i i |  d d j o   i |  n d  S(   Ni   t   CVS(   t   ost   patht   splitt   append(   t   argt   dirt   names(   t   dirs(    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyt   visit>   s    N(   R   R   t   walkt   None(   t   includeR   (    (   R   s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyt   RecursiveIncludes;   s    	c          C   s6   d t  i j o t  i d }  |  i t  i  Sg  Sd  S(   Nt   INCLUDE(   R   t   environR   t   pathsep(   R   (    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyt   GetDefaultIncludesF   s    c         C   sO   t  i d j o; d } x2 |  D]& } | i d d  |  | <| d 7} q Wn d  S(   Nt   win32i    s   \t   /i   (   t   syst   platformt   replace(   t   includest   indexR   (    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyt   ProcessIncludesN   s     c         C   s]   t  |   } g  } z9 x2 | D]* } | i   } | o | i |  q q WWd  | i   X| S(   N(   t   filet   stripR   t   close(   t   filenamet   ft   filest   line(    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyt   ReadFileListV   s     c          C   s  d   }  yP t  i  t i d d d d d d d d	 d
 d d d d d d d g  \ } } Wn) t  i j
 o } Hd G| GH|    n Xt   } g  } g  } d  } d  } t }	 d  }
 t } t } d } x| D]\ } } | d j o | i |  q | d j o | i |  q | d j o | i t	 |   q | d j o
 | } q | d j o
 | } q | d j o d t
 i _ t t
 _ q | d j o | d t
 i _ q | d j o t t
 _ q | d j o
 t }	 q | d j o
 | }
 q | d  j o
 t } q | d! j o | t |  7} q | d1 j o |    q | d2 j o d& t GHt i d'  q | d( j o
 t } q | d) j o
 | } q | d* j o
 g  } q d+ G| GH|    q W| | d, d, +| p |    n | p* t i i t i i | d,   d, } n | p | } |	 p | d- 7} q:n xP | D]H } t i i t i i |   } | t i j o t i i |  qAqAW| o% |
 o d. GH|    t i d/  n | o% |	 o d0 GH|    t i d/  n t |  | | | | | |	 |
 | | | f
 S(3   Nc           S   s   t  t GHt i d  d  S(   Ni   (   t   __doc__t   __version__R   t   exit(    (    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyt   Usagee   s    	i   s   R:I:D:vhs   module=t   multiples   out=s   no-usings	   pyste-ns=t   debugs
   cache-dir=s   only-create-cachet   versions   generate-mains
   file-list=t   helps   gccxml-path=s   no-default-includes   ERROR:t   gccxmls   -Is   -Ds   -Rs   --modules   --outs
   --no-usings   boost::python::s
   --pyste-nss   ::s   --debugs
   --multiples   --cache-dirs   --only-create-caches   --file-lists   -hs   --helps   -vs	   --versions   Pyste version %si   s   --generate-mains   --gccxml-paths   --no-default-includes   Unknown option:i    s   .cppsC   Error: Use --cache-dir to indicate where to create the cache files!i   s3   Error: --generate-main only valid in multiple mode.(   s   -hs   --help(   s   -vs	   --version(   t   getoptR   t   argvt   GetoptErrorR   R   t   FalseR   t   extendR   t   settingst
   namespacest   pythont   USING_BOOST_NSt   pystet   Truet   DEBUGR$   R&   R'   R   R   t   splitextt   basenamet   dirnamet   abspathR   (   R(   t   optionsR"   t   et   default_includesR   t   definest   modulet   outR)   t	   cache_dirt   create_cachet   generate_maint   gccxml_patht   optt   valueR   t   d(    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyt   ParseArgumentsc   s    	
		 




	


	* 
c          G   sB   d i  g  } |  D] } | d | q ~  } t i | d  d  S(   Ns   
s   #include <%s>t
   pchinclude(   t   joint   infost   CodeInfo(   t   headerst   _[1]t   xt   code(    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyt
   PCHInclude   s    .c          C   s  h  }  t  |  d <t i |  d <t i |  d <d   |  d <t |  d <t i |  d <t i |  d <t i |  d	 <t i |  d
 <t i	 |  d <t i
 |  d <t i |  d <t i |  d <t i |  d <t i |  d <t i |  d <t i |  d <t i |  d <t i |  d <t |  d <t |  d <t |  d <t |  d <t |  d <t |  d <t |  d <t |  d <t |  d <t |  d <t i |  d <d    |  d! <d"   |  d# <t i |  d$ <|  S(%   s:   create the context where a interface file will be executedt   Importt   Functiont   Classc         S   s   t  i d  |  d  S(   s   #include <%s>
R   (   RN   RO   (   t   header(    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyt   <lambda>   s    t   IncludeRT   t   Templatet   Enumt   AllFromHeadert   Vart   renamet
   set_policyt   excludet   set_wrappert   use_shared_ptrt   use_auto_ptrt   holdert
   add_methodt   finalt   export_valuest   return_internal_referencet   with_custodian_and_wardt   return_value_policyt   reference_existing_objectt   copy_const_referencet   copy_non_const_referencet   return_opaque_pointert   manage_new_objectt   return_by_valuet   return_selft   Wrapperc         S   s   t  i |  d   S(   s   declaration-outside(   RN   RO   (   RS   (    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyRY      s    t   declaration_codec         S   s   t  i |  d   S(   RB   (   RN   RO   (   RS   (    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyRY      s    t   module_codet
   class_code(    RU   RN   t   FunctionInfot	   ClassInfoRT   t   ClassTemplateInfot   EnumInfot
   HeaderInfot   VarInfoR_   R`   Ra   Rb   Rc   Rd   Re   Rf   Rg   Rh   Ri   Rj   Rk   Rl   Rm   Rn   Ro   Rp   Rq   Rr   t   exporterutilst   FunctionWrapperRv   (   t   context(    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyt   CreateContext   sF    











c          C   s   t    \
 }  } } } } } } } } }	 x | D] }
 t |
  q. Wt |  | | t i |	  } zM | p8 | p t | | | | |  St | | t |   Sn t |  SWd  | i	   Xd  S(   N(
   RK   t   ExecuteInterfaceR   t   declarationsR+   t   GenerateCodet   GenerateMaint   OrderInterfacest   CreateCachest   Close(   R   RA   RB   RC   t
   interfacesR)   RD   RE   RF   RG   t	   interfacet   parser(    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyt   Begin   s    ' c         C   sm   t  t i  } xW | D]O \ } } | | | f } |  i | |  } |  i | | | |  } d G| GHq Wd S(   Nt   Cachedi    (   t	   JoinTailst	   exporterst   ParseWithGCCXMLt   CreateCache(   R   t   tailsR   RX   t   tailR   t	   cachefile(    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyR   
  s     c         C   s   t  i } t i i |   pI | o> t i i |  o+ t i i |  } t i i | |   }  qe n t i i |   p t d |   n t i	 |  d  d t |  <|  t  _ t
   } t i i |   | d <t |  |  | t  _ d  S(   Ns   Cannot find interface file %s.i    i   t   INTERFACE_FILE(   R   t   current_interfaceR   R   t   existsR<   RM   t   IOErrort   _imported_countt   getR   R=   t   execfile(   R   t   old_interfaceRJ   R   (    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyR     s    			c         C   s    t  t _ t |   t t _ d  S(   N(   R8   R   t	   importingR   R1   (   R   (    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyRU   .  s    	
c         C   s   h  } x |  D] } | i  } | i   } | i   p d } | | f | j o2 | | | f } | d | 7} | | | | f <q | | | | f <q W| S(   s   Returns a dict of {(interface, header): tail}, where tail is the
    joining of all tails of all exports for the header.  
    t    s   
(   t   interface_filet   Headert   Tail(   t   exportsR   t   exportR   RX   R   t	   all_tails(    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyR   4  s     	c         C   sd   g  } |  D] } | t  | | f q ~ } | i   | i   g  } | D] \ } } | | qJ ~ S(   N(   R   t   sortt   reverse(   R   RQ   RR   t   interfaces_ordert   _[2]t   _(    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyR   H  s    +

c         C   s#   t  i  |  |  } | i |  d S(   Ni    (   t   MultipleCodeUnitR   (   RB   RC   R   t   codeunit(    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyR   P  s    c         C   s  | o t  i  | |  } n t i | |  } t i } d  t _ t g  } | D] } | | i   d  f qO ~  }	 h  }
 xF | D]> } | i |
 j o |
 | i i |  q | g |
 | i <q Wg  } t |  } x | D] } | i	 |
 |  q W~
 ~ t
 |  } x t t |   D] } | | } | i } | i   } | o/ | | | f } |  i | | |  \ } } n g  } d  } t | |	  | i |  | i |  | o | i | i | i    n | i | |	  d  | | <~ ~ t i   qW| i   | p d | GHn d S(   Ns   Module %s generatedi    (   R   t   SingleCodeUnitR   R   t   dictt   NameR   R   R   R2   R   t   xranget   lenR   t   Parset   ExpandTypedefst   SetDeclarationst   SetParsedHeadert
   SetCurrentR   t   gct   collectt   Save(   R   RB   RC   R   R)   R   R   RQ   RR   t   exported_namest   orderR   R   R   R   t   iRX   R   R   t   parsed_header(    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyR   V  sX    		3   
	

c         C   sV   xO | i    D]A } x8 |  D]0 } t | t i  o d | | i i   <q q Wq Wd S(   sf   Check if the names in exported_names are a typedef, and add the real class 
    name in the dict.
    N(   t   keyst
   isinstanceR   t   TypedefR   t   typet   FullName(   t   declsR   t   namet   decl(    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyR     s      c          C   s(   y d d k  }  |  i   Wn n Xd S(   s   Tries to use psyco if possibleiN(   t   psycot   profile(   R   (    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyt   UsePsyco  s
     c          C   s@   t  i   }  t   t   } d t  i   |  GHt i |  d  S(   Ns   %0.2f seconds(   t   timet   clockR   R   R   R'   (   t   startt   status(    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyt   main  s
    	t   __main__(%   R%   R   R   R.   R   R   R   RN   R}   R3   R   t   policiesR   R   R   R   R&   R   R   R   R$   RK   RT   R   R   R   R   R   RU   R   R   R   R   R   R   R   t   __name__(    (    (    s+   /usr/lib/pymodules/python2.6/Pyste/pyste.pyt   <module>'   sJ   
					c		+								8				