mò
‘oÞFc           @   sV  d  k  Z  d  k Z d  k Z d Z d Z d f  d „  ƒ  YZ d „  Z d f  d „  ƒ  YZ d  d  d „ Z	 e
 d	 j oà d  k Z e i e i d
 d ƒ \ Z Z y e d Z Wn* e j
 o e e i d ƒ e ‚ n. Xe d
 Z e p e e i d ƒ e ‚ n d  Z e o0 e d d d j o e d d
 Z d e GHn e	 e e e ƒ n d  S(   Ns   .jss   @requires (.*)
t
   SourceFilec           B   s5   t  Z d  Z d „  Z d „  Z e d e d d ƒ Z RS(   s3   
    Represents a Javascript source code file.
    c         C   s   | |  _  | |  _ g  |  _ d S(   s	   
        N(   t   filepatht   selft   sourcet
   requiredBy(   R   R   R   (    (    t   ../tools/mergejs.pyt   __init__<   s     		c         C   s   t  i t |  i ƒ S(   sl   
        Extracts the dependencies specified in the source code and returns
        a list of them.
        N(   t   ret   findallt
   RE_REQUIRER   R   (   R   (    (    R   t   _getRequirementsE   s     t   fgett   doct    (   t   __name__t
   __module__t   __doc__R   R
   t   propertyt   requires(    (    (    R   R    7   s    			c         C   s   d |  GHd S(   s#   
    Displays a usage message.
    s3   %s [-c <config file>] <output.js> <directory> [...]N(   t   filename(   R   (    (    R   t   usageQ   s     t   Configc           B   s   t  Z d  Z d „  Z RS(   sd  
    Represents a parsed configuration file.

    A configuration file should be of the following form:

        [first]
        3rd/prototype.js
        core/application.js
        core/params.js

        [last]
        core/api.js

        [exclude]
        3rd/logger.js

    All headings are required.

    The files listed in the `first` section will be forced to load
    *before* all other files (in the order listed). The files in `last`
    section will be forced to load *after* all the other files (in the
    order listed).

    The files list in the `exclude` section will not be imported.
    
    c         C   sÎ   g  } t | ƒ D]$ } | i ƒ  o | | i ƒ  q q ~ } | | i d ƒ d | i d ƒ !|  _ | | i d ƒ d | i d ƒ !|  _	 | | i d ƒ d | i d ƒ !|  _
 | | i d ƒ d |  _ d S(   sM   
        Parses the content of the named file and stores the values.
        s   [first]i   s   [last]s	   [include]s	   [exclude]N(   t   _[1]t   openR   t   linet   stript   linest   indexR   t
   forceFirstt	   forceLastt   includet   exclude(   R   R   R   R   R   (    (    R   R   t   s     >&&&(   R   R   R   R   (    (    (    R   R   X   s    c         C   sŽ  d  } | o t | ƒ } n g  } xú t i |  ƒ D]é \ } } } x× | D]Ï } | i t ƒ o¹ | i d ƒ o¨ t i i | | ƒ t |  ƒ d } | i d d ƒ } | o? | i o5 | | i j p | | i j o | i | ƒ qq| p | | i j o | i | ƒ qqI qI Wq3 Wd d d d d	 d d d
 } h  } g  } xT | D]L } d | GHt i i |  | ƒ } t | d ƒ i ƒ  } t | | ƒ | | <qUWHd k l }
 t  } d } x¡| p™g  } g  } g  } d | GH| d 7} xN | i% ƒ  D]@ \ } } | i | ƒ x$ | i' D] } | i | | f ƒ qWqûWx |
 | | ƒ D]~ } xu | D]m } | i | ƒ | i* | ƒ pJ d | GHt i i |  | ƒ } t | d ƒ i ƒ  } t | | ƒ | | <q\q\WqOWt+ } yv xo | D]g } t- g  } | | i' D] } | | i0 | ƒ qü~ | i0 | ƒ g ƒ | i0 | ƒ j o
 t  } qáqáWWn t  } n XHqÂW| o\ d GH| i g  } | D]1 } | | i j o | | i2 j o | | q€q€~ | i2 } n Hg  }	 xo | D]g } | | } d G| i GH|	 i | | i ƒ | i5 } |	 i | ƒ | i d ƒ p |	 i d ƒ qÔqÔWd t | ƒ GH| o, d | GHt | d ƒ i7 d i |	 ƒ ƒ n d i |	 ƒ S(   Nt   .i   s   \t   /s   /* t   =iF   s   
    %s
s      s    */

s   Importing: %st   U(   s   toposorts   Resolution pass %s... s   Re-ordering files...s   Exporting: s   
s   
Total files merged: %d s   
Generating: %st   wR   (8   t   Nonet   cfgt
   configFileR   t   allFilest   ost   walkt   sourceDirectoryt   roott   dirst   filesR   t   endswitht   SUFFIX_JAVASCRIPTt
   startswitht   patht   joint   lenR   t   replaceR   R   t   appendR   t   HEADERt   ordert   fullpathR   t   readt   contentR    t   toposortt   Falset   completet   resolution_passt   nodest   routest   itemst   infoR   t   neededFilePatht   dependencyLevelt   has_keyt   Truet   fpt   maxR   t   rfpR   t   itemR   t   resultt   fR   t   outputFilenamet   write(   R+   RN   R'   R.   R(   RK   R&   RE   RH   RL   R<   R   RD   R   R;   R   R@   R-   R>   R7   RC   RJ   RM   R,   R   R?   RA   R9   R8   (    (    R   t   run‚   s       !# " 	 	
 
   	 W
W 
		#t   __main__i   s   -c:i    s   -cs   Parsing configuration file: %s(   R   R)   t   sysR0   R	   R    R   R   R%   RP   R   t   getoptt   argvt   optionst   argsRN   t
   IndexErrort
   SystemExitR+   R'   R   (   RV   RP   R+   R   R    R'   RN   RR   R   R0   R	   RS   R   R)   RU   (    (    R   t   ?0   s2   				*j	

