Ñò
4×ÛQc           @   s  d  d k  Z  d  d k Z d  d k Z d Z d Z d e f d „  ƒ  YZ d d d „  ƒ  YZ d „  Z d	 d d
 „  ƒ  YZ	 d „  Z
 d d „ Z d d e d „ Z e d j oã d  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(   iÿÿÿÿNs   .jss   @requires?:?\s+(\S*)\s*
t   MissingImportc           B   s   e  Z d  Z RS(   s>   Exception raised when a listed import is not found in the lib.(   t   __name__t
   __module__t   __doc__(    (    (    s   ../tools\mergejs.pyR    0   s   t
   SourceFilec           B   s5   e  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  |  _ g  |  _ t i t |  i ƒ } xB | D]: } t | | ƒ o |  i i | ƒ q@ |  i i | ƒ q@ Wg  |  _	 d S(   s	   
        N(
   t   filepatht   sourcet   excludedFilest   requiredFilest   ret   findallt
   RE_REQUIREt	   undesiredt   appendt
   requiredBy(   t   selfR   R   t
   cfgExcludet   auxReqt   filename(    (    s   ../tools\mergejs.pyt   __init__8   s    				 c         C   s   |  i  S(   sl   
        Extracts the dependencies specified in the source code and returns
        a list of them.
        (   R   (   R   (    (    s   ../tools\mergejs.pyt   _getRequirementsJ   s    t   fgett   doct    (   R   R   R   R   R   t   propertyt   requires(    (    (    s   ../tools\mergejs.pyR   3   s   		c         C   s   d |  GHd S(   s#   
    Displays a usage message.
    s3   %s [-c <config file>] <output.js> <directory> [...]N(    (   R   (    (    s   ../tools\mergejs.pyt   usageU   s    t   Configc           B   s   e  Z d  Z d „  Z RS(   sá  
    Represents a parsed configuration file.

    A configuration file should be of the following form:

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

        [last]
        core/api.js # Another comment

        [exclude]
        3rd/logger.js
        exclude/this/dir

    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.

    Any text appearing after a # symbol indicates a comment.
    
    c         C   sô   g  } t  | ƒ D]J } | i ƒ  o7 | i ƒ  i d ƒ o  | t i d d | ƒ 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.
        t   #s   #.*?$R   s   [first]i   s   [last]s	   [include]s	   [exclude]N(
   t   opent   stript
   startswithR	   t   subt   indext
   forceFirstt	   forceLastt   includet   exclude(   R   R   t   _[1]t   linet   lines(    (    s   ../tools\mergejs.pyR   |   s    M&&&(   R   R   R   R   (    (    (    s   ../tools\mergejs.pyR   \   s   c         C   se   |  | j } | pN xK | D]? } | i  d ƒ p | d 7} n |  i | ƒ o t } Pq q Wn | S(   Nt   /(   t   endswithR   t   True(   R   t   excludesR%   t   excludepath(    (    s   ../tools\mergejs.pyR   Š   s     c         C   s   t  |  d  | t ƒ S(   N(   t   runt   NoneR+   (   t   sourceDirectoryt
   configFile(    (    s   ../tools\mergejs.pyt   getNames˜   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 t |
 | i ƒ o | i |
 ƒ qqI qI Wq3 Wd d d d d	 d d d
 } h  } x` | D]X }
 d |
 GHt i i |  |
 ƒ i ƒ  } t | d ƒ i ƒ  } t |
 | | i ƒ | |
 <qSWHd d k l } t } d } xï | pç t } d | GH| d 7} xÇ | i ƒ  D]¹ \ }
 } xª | i D]Ÿ } | i | ƒ p‰ t } t i i |  | ƒ i ƒ  } t i i | ƒ o; d | GHt | d ƒ i ƒ  } t | | | i ƒ | | <q±t d | |
 f ƒ ‚ qqWqüWqÏWh  } x' | i ƒ  D] \ }
 } | i | |
 <qÑWd GH| | ƒ } | o\ d GH| i g  } | D]1 } | | i j o | | i j o | | qq~ | i } n Hg  } | o xx | D]p } t i i t i i |  | ƒ ƒ i
 d d ƒ } d G| GH| | } x | i D] } d | GHqÇW| i | ƒ qwWd t	 | ƒ GH| SxŒ | D]„ } | | } d G| i GHx | i D] } d | GHq,W| i | | i ƒ | i  } | i | ƒ | i d ƒ p | i d ƒ qqWd t	 | ƒ GH| o, d | GHt | d ƒ i! d i | ƒ ƒ n d i | ƒ S(   Nt   .i   s   \R)   s   /* t   =iF   s   
    %s
s      s    */

s   Importing: %st   Uiÿÿÿÿ(   t   toposorts   Resolution pass %s... s'   File '%s' not found (required by '%s').s
   Sorting...s   Re-ordering files...s   Append: s!     Required file "%s" is excluded.s   
Total files: %d s   Exporting: s   
s   
Total files merged: %d s   
Generating: %st   wR   ("   R/   R   t   ost   walkR*   t   SUFFIX_JAVASCRIPTR   t   patht   joint   lent   replaceR$   R"   R   R   R%   R   R   t   readR   R6   t   FalseR+   t   itemsR   t   has_keyt   existsR    R#   t   normpathR   R   R   t   write(   R0   t   outputFilenameR1   t   returnAsListOfNamest   cfgt   allFilest   roott   dirst   filesR   R   t   HEADERt   fullpatht   contentR6   t   completet   resolution_passt   infoR;   t   dependenciest   orderR&   t   itemt   resultt   fpt   fNamet   ft   fExcludeR   (    (    s   ../tools\mergejs.pyR.   œ   sª      !# " 	 	
 
 	' W -	

  

 		#t   __main__i   s   -c:i    s   -cs   Parsing configuration file: %s(    (    (   R	   R8   t   sysR:   R   t	   ExceptionR    R   R   R   R   R/   R2   R@   R.   R   t   getoptt   argvt   optionst   argsRF   t
   IndexErrort
   SystemExitR0   R1   R   (    (    (    s   ../tools\mergejs.pyt   <module>(   s:   "	.	m

