
    ~+hX                        d dl mZ 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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 d d	lmZ d d
lmZmZ dZ ej4                  d      j7                  ej8                          G d de      Z G d de      Z  G d de       Z! G d de       Z" G d de       Z# G d de       Z$ G d de      Z% G d de      Z&d dZ'd Z(e)dk(  r e(        yy)!    )print_functionN)PythonLoader
YAMLLoader)get_all_bundle_files)
BuildError)TimestampUpdater)
MemoryHunk)get_manifest)FilesystemCache)setStringIO)CommandErrorCommandLineEnvironmentmainwebassets.scriptc                       e Zd Zy)r   N)__name__
__module____qualname__     C/var/www/html/venv/lib/python3.12/site-packages/webassets/script.pyr   r      s    r   r   c                   "    e Zd ZdZd Zd Zd Zy)CommandzBase-class for a command used by :class:`CommandLineEnvironment`.

    Each command being a class opens up certain possibilities with respect to
    subclassing and customizing the default CLI.
    c                     || _         y N)cmd)selfcmd_envs     r   __init__zCommand.__init__$   s	    r   c                 .    t        | j                  |      S r   )getattrr   )r   names     r   __getattr__zCommand.__getattr__'   s    txx&&r   c                     t               r   )NotImplementedError)r   argskwargss      r   __call__zCommand.__call__+   s    !##r   N)r   r   r   __doc__r    r$   r)   r   r   r   r   r      s    '$r   r   c                       e Zd Z	 	 ddZy)BuildCommandNc           
         |r|rt        d      |r|rt        d      |rd| j                  _        |)	 t        || j                        }|| j                  _        |rt        |      }|r|n|r|j                         ng }|D ]  }|| j                  vst        d|z         |r=| j                  j                  j                         D 	
cg c]  \  }	}
|	|v r|	|
f }}	}
n| j                  D 
cg c]  }
d|
f }}
|rt
        j                  j                  |D 
cg c]>  \  }}
|
j                  r-t
        j                  j                  |
j!                               @ c}
}      }t
        j                  j#                  |      }g }|D ]  \  }}|j$                  r|rt        d      d}|r||   }n^|r\t
        j                  j                  |j!                               t'              d	z   d }t
        j                  j)                  ||      }|j+                  |||f        g }|D ]m  \  }}}|r1| j,                  j/                  d
|d|xs |j                  d       n(| j,                  j/                  d|j                  z         	 |s8|j1                  | j                        5  |j3                  d|       ddd       nt5               }|j1                  | j                        5  |j3                  d||       ddd       |rSt
        j                  j#                  |      }t
        j                  j7                  |      st        j8                  |       t;        |j=                               j?                  |       |j+                  |       p t'        |      r | jD                  d           t'        |      t'        |      k7  ryy# t        $ r; t        dt
        j                  j                  |      z  | j                        }Y w xY wc c}
}	w c c}
w c c}
}w # 1 sw Y   xY w# 1 sw Y   7xY w# t@        $ r)}| j,                  jC                  d|z         Y d}~Gd}~ww xY w)a   Build assets.

        ``bundles``
            A list of bundle names. If given, only this list of bundles
            should be built.

        ``output``
            List of (bundle, filename) 2-tuples. If given, only these
            bundles will be built, using the custom output filenames.
            Cannot be used with ``bundles``.

        ``directory``
            Custom output directory to use for the bundles. The original
            basenames defined in the bundle ``output`` attribute will be
            used. If the ``output`` of the bundles are pointing to different
            directories, they will be offset by their common prefix.
            Cannot be used with ``output``.

        ``no_cache``
            If set, a cache (if one is configured) will not be used.

        ``manifest``
            If set, the given manifest instance will be used, instead of
            any that might have been configured in the Environment. The value
            passed will be resolved through ``get_manifest()``. If this fails,
            a file-based manifest will be used using the given value as the
            filename.

        ``production``
            If set to ``True``, then :attr:`Environment.debug`` will forcibly
            be disabled (set to ``False``) during the build.
        z[When specifying explicit output filenames you must do so for all bundles you want to build.zcA custom output directory cannot be combined with explicit output filenames for individual bundles.FN)envzfile:%sz'I do not know a bundle name named "%s".zJA custom output directory cannot currently be used with container bundles.   zBuilding bundle: z (to )zBuilding bundle: %sT)forcedisable_cache)r1   outputr2   zFailed, error was: %s
post_build   )#r   environmentdebugr
   
ValueErrorospathabspathmanifestdictkeys_named_bundlesitemscommonprefixr3   normpathresolve_outputdirnameis_containerlenjoinappendloginfobindbuildr   existsmakedirsr	   getvaluesaver   errorevent_handlers)r   bundlesr3   	directoryno_cacher<   
productionbundle_namesr#   nb_prefixto_buildbundleoverwrite_filenameoffsetbuilt
output_dires                       r   r)   zBuildCommand.__call__1   sC   H v;< <   9 : : %*D" *'d6F6FG )1D% &\F #*wR  	FD4+++"=DF F	F )-)9)9)H)H)N)N)P 3A !\ 1 !u 3G 3 +/*:*:;Qay;G; WW))$2Q !!!"2"2"45 23F WW__V,F# 	ALD& ""y"34 4
 "&%+D\"))))+--0[]^=%'WW\\)V%D"OOV%7?@#	A( 08  	<,F& ,==? @ 3fmmCD<)T%5%56 I4xHI I &ZFT%5%56 44*2 % 44 !%'WW__5G%H
!ww~~j9KK
3v01667IJV$= 	<B u:-D-/u:X& '{  *'  99((	**,3 <
2LI I4 4  <6:;;<sn   O P2P$AP)
Q/P/.Q1P;BQA PP/P8	4Q;Q	 Q	Q:Q55Q:)NNNNNNr   r   r   r)   r   r   r   r,   r,   /   s    KO(,Sr   r,   c                        e Zd ZddZd Zd Zy)WatchCommandNc                    i }	 | j                   D ],  }t        d|j                  z         |j                  d       . | j                  j                  dt        | j                         z         	 | j                  |      }g }|D ]i  }t        d|j                  z  d       t        j                  j                          	 |j                  d       |j                  |       t        d	       k t        |      r | j                  d           |r |       nt        j                  d      }|ry# t        $ r#}t        d
       t        d|z         Y d}~d}~ww xY w# t         $ r Y yw xY w)a  Watch assets for changes.

        ``loop``
            A callback, taking no arguments, to be called once every loop
            iteration. Can be useful to integrate the command with other code.
            If not specified, the loop will call ``time.sleep()``.
        zBringing up to date: %sF)r1   z"Watching %d bundles for changes...TzBuilding bundle: %s ... )enddone z
Failed: %sNr4   g?)r6   printr3   rL   rI   rJ   rF   check_for_changessysstdoutflushrH   r   rR   timesleepKeyboardInterrupt)r   loopmtimesr]   changed_bundlesr`   rb   do_ends           r   r)   zWatchCommand.__call__   sX    !	 ** */&--?@5)* HHMM>d../0 1 "&"8"8"@- 
&F3fmmCMJJ$$&&40V,
 f
& u:5D''57#'TZZ_+  & 0b	lQ.//0 ! 		sC   B=E" #D3%AE" 2E" 3	E<EE" EE" "	E.-E.c                    |j                         }t               }| j                         D ]  \  }}t        j                  |      }|j
                  }t        j                  dk(  r||j                  z  }|j                  ||      |k7  r6t        |      r	  |       }|du rt        | j                        }||z  }|||<   |||<    |j                  |       |S # t        $ r! dd l}|j                          t               }Y fw xY w)Nwin32r   T)copyr   yield_files_to_watchr9   statst_mtimerm   platformst_ctimegetcallableEnvironmentError	traceback	print_excr6   update)	r   rt   _new_mtimesru   filenamebundles_to_updater{   mtimer   s	            r   rl   zWatchCommand.check_for_changes   s	    kkm% ,0+D+D+F 	*'H'778$DMME||w&&zz(E*e3-.2,=,?) %,(+D,<,<(=%#44(-H%$)K!1	*4 	k"! , 2 )!++-,/E)2s   C'DDc              #   n   K   | j                   D ]"  }t        |      D ]  }|t        |g      f  $ y wr   )r6   r   r   )r   r]   r   s      r   rz   z!WatchCommand.yield_files_to_watch  s@     && 	.F08 .VH--.	.s   35r   )r   r   r   r)   rl   rz   r   r   r   re   re      s    ,\#J.r   re   c                       e Zd Zd Zy)CleanCommandc                    | j                   j                  d       | j                  D ]  }|j                  s|j	                  | j                        }t
        j                  j                  |      sKt        j                  |       | j                   j                  d|j                  z          t        | j                  j                  t              r4t        j                  | j                  j                  j                         yy)z!Delete generated assets.
        zCleaning generated assets...zDeleted asset: %sN)rI   rJ   r6   r3   rC   r9   r:   rM   unlink
isinstancecacher   shutilrmtreerT   )r   r]   	file_paths      r   r)   zCleanCommand.__call__$  s     	45&& 	CF==--d.>.>?Iww~~i(		)$1FMMAB	C d&&,,o>MM$**00::; ?r   Nrc   r   r   r   r   r   "  s    <r   r   c                       e Zd Zd Zy)CheckCommandc                    d}| j                   j                  }|s%| j                  j                  d       t	               }| j                   D ]b  }| j                  j                  d|j                         |j                  || j                         sF| j                  j                  d       d}d |rt        j                  d       yy)zCheck to see if assets need to be rebuilt.

        A non-zero exit status will be returned if any of the input files are
        newer (based on mtime) than their output file. This is intended to be
        used in pre-commit hooks.
        Fz-no updater configured, using TimestampUpdaterzChecking asset: %sz  needs updateTN)
r6   updaterrI   r7   r   rJ   r3   needs_rebuildrm   exit)r   needsupdater   r]   s       r   r)   zCheckCommand.__call__5  s     ""**HHNNJK&(G&& 	#FHHMM.>$$VT-=-=>./"		#
 HHRL r   Nrc   r   r   r   r   r   3  s    r   r   c                   2    e Zd ZdZddZd Zd Zeee	e
dZy)r   a  Implements the core functionality for a command line frontend to
    ``webassets``, abstracted in a way to allow frameworks to integrate the
    functionality into their own tools, for example, as a Django management
    command, or a command for ``Flask-Script``.
    Nc                    || _         || _        t        d       | _        t	        |      r|| j                  d<   | j
                  j                         }|j                  |xs i        i | _        |j                         D ]E  \  }}|s	t        |t        t        f      s|di g} |d   | g|d   i |d   | j                  |<   G y )Nc                       yNTr   r   r   r   <lambda>z1CommandLineEnvironment.__init__.<locals>.<lambda>T  s    r   )r4   r4   r   r   r/   r5   )r6   rI   r=   rR   r   DefaultCommandsry   r   commandsr@   r   listtuple)r   r.   rI   r4   r   command_defr#   	constructs           r   r    zCommandLineEnvironment.__init__Q  s    "l;J0:D- **//18>r**002 	5OD)i$7&B/	".)A,#5 |#5'0|#5DMM$	5r   c                 R    || j                   v r| j                   |   S t        |      r   )r   AttributeError)r   items     r   r$   z"CommandLineEnvironment.__getattr__d  s(    4== ==&&T""r   c                 p    	 | j                   |   } |di |S # t        $ r}t        d|z        d}~ww xY w)zInvoke ``command``, or throw a CommandError.

        This is essentially a simple validation mechanism. Feel free
        to call the individual command methods manually.
        zunknown command: %sNr   )r   KeyErrorr   )r   commandr'   functionrb   s        r   invokezCommandLineEnvironment.invokej  sH    	$}}W-H #d##  	:4q899	:s    	505)rL   watchcleancheck)NN)r   r   r   r*   r    r$   r   r,   re   r   r   r   r   r   r   r   r   J  s+    5&#$ 	Or   r   c                   p    e Zd ZdZ G d de      ZddZddZed        Zd Z	d	 Z
d
 Zd Zd Zd Zd Zy)GenericArgparseImplementationa  Generic command line utility to interact with an webassets environment.

    This is effectively a reference implementation of a command line utility
    based on the ``CommandLineEnvironment`` class. Implementers may find it
    feasible to simple base their own command line utility on this, rather than
    implementing something custom on top of ``CommandLineEnvironment``. In
    fact, if that is possible, you are encouraged to do so for greater
    consistency across implementations.
    c                   "    e Zd ZdZd Zd Zd Zy)*GenericArgparseImplementation.WatchCommandzAExtended watch command that also looks at the config file itself.c                 >    t         j                  | |       || _        y r   )re   r    ns)r   r   argparse_nss      r   r    z3GenericArgparseImplementation.WatchCommand.__init__  s    !!$0!DGr   c              #      K   t         j                  |       D ]  }|  t        | j                  dd       r%| j                  j                  | j
                  f y y w)Nconfig)re   rz   r"   r   r   reload_config)r   results     r   rz   z?GenericArgparseImplementation.WatchCommand.yield_files_to_watch  sU     &;;DA  tww$/ggnnd&8&888 0s   AAc                     	 t        | j                  j                        j                         | j                  _        y# t        $ r}t        |      d }~ww xY wr   )r   r   r   load_environmentr   r6   	Exceptionr   )r   rb   s     r   r   z8GenericArgparseImplementation.WatchCommand.reload_config  sK    *'1$''..'A'R'R'T$   *&q))*s   <? 	AAAN)r   r   r   r*   r    rz   r   r   r   r   re   r     s    O	"	9	r   re   Nc                     	 dd l }|| _         || _        || _        | j                  ||       y # t        $ r t        d      w xY w)Nr   zYThe webassets command line now requires the "argparse" library on Python versions <= 2.6.)argparseImportErrorRuntimeErrorr.   rI   _construct_parser)r   r.   rI   progno_global_optionsr   s         r   r    z&GenericArgparseImplementation.__init__  sZ    	% %DMt%67  	A@A A	As	   . Ac                    | j                   j                  d|      x| _        }|sp|j                  dddd       |j                  ddd	d
       | j                  :|j                         }|j                  dddd       |j                  dddd       |j                  d      }t        j                  j                         D ].  }|j                  |      }t        | d|z  d      }|s' ||       0 y )NzManage assets.)descriptionr   z-vverbose
store_truez
be verbose)destactionhelpz-qquietzbe quiet)r   r   r   z-cz--configr   z!read environment from a YAML file)r   r   z-mz--modulemodulez%read environment from a Python moduler   )r   zmake_%s_parserF)r   ArgumentParserparseradd_argumentr.   add_mutually_exclusive_groupadd_subparsersr   r   r>   
add_parserr"   )	r   r   r   r   loadenv
subparsersr   command_parsermakers	            r   r   z/GenericArgparseImplementation._construct_parser  s   #}};;(  <   	f ! 9\!   #\   !xx ==?$$T:H< % >$$T:H@ % B **	*:
-==BBD 	&G'227;ND"2W"<eDEn%		&r   c                     | j                  dddd       | j                  dddd	d
d       | j                  ddd       | j                  ddd       | j                  dd       | j                  ddd       y )NrS   *BUNDLEz^Optional bundle names to process. If none are specified, then all known bundles will be built.)nargsmetavarr   z--outputz-or5   rH   )r   FILEzRBuild the given bundle, and use a custom output file. Can be given multiple times.)r   r   r   r   z--directoryz-dzWrite built files to this directory, using the basename defined by the bundle. Will offset the original bundle output paths on their common prefix. Cannot be used with --output.)r   z
--no-cacher   z,Do not use a cache that might be configured.)r   r   z
--manifestz|Write a manifest to the given file. Also supports the id:arg format, if you want to use a different manifest implementation.z--productionz_Forcably turn off debug mode for the build. This only has an effect if debug is set to "merge".)r   )r   s    r   make_build_parserz/GenericArgparseImplementation.make_build_parser  s    S(D 	 	E 	Ah&6 	 	7
 	49 	 	: 	? 	 	A 	, 	 	-
 	<B 	 	Cr   c                 t   | j                   r| j                   }|S t        j                  d      }|j                  s|t        j                         }|j                  |       |j                  |j                  rt        j                  n+|j                  rt        j                  nt        j                         |S )Nr   )rI   logging	getLoggerhandlersStreamHandler
addHandlersetLevelr   DEBUGr   WARNINGINFO)r   r   rI   handlers       r   _setup_loggingz,GenericArgparseImplementation._setup_logging  s    88((C 
 ##$67C<<!//1w'
   "**')xxGOOW\\D
r   c                    | j                   }|x|j                  r|j                  rJ |j                  r#t        |j                        j	                         }|j                  r#t        |j                        j	                         }|S r   )r.   r   r   r   r   r   )r   r   rI   r.   s       r   _setup_assets_envz/GenericArgparseImplementation._setup_assets_env  sd    hh;		bii00yy"299->>@yy +<<>
r   c                 F    t        ||dt        j                  |fi fi      S )Nr   )r   )r   r   re   )r   
assets_envrI   r   s       r   _setup_cmd_envz,GenericArgparseImplementation._setup_cmd_env  s.    %j#3@@2%LA
  	r   c                     t        |      j                         }| j                  j                  D ]  }|j                  }||v s||=  |S r   )varsry   r   _actionsr   )r   r   r'   r   r   s        r   _prepare_command_argsz3GenericArgparseImplementation._prepare_command_args  sJ     Bx}}kk** 	F;;Dt|J	 r   c                     | j                  |      }| j                  ||      }|t        d      | j                  |||      }| j	                  |      }|j                  |j                  |      S )Nz3Error: No environment given or found. Maybe use -m?)r   r   r   r   r   r   r   )r   r   rI   r.   r   r'   s         r   run_with_nsz)GenericArgparseImplementation.run_with_ns  sv    !!"%$$R-;EG G!!#sB/ ))"-zz"**d++r   c                     	 | j                   j                  |      }| j	                  |      S # t        $ r}|j                  d   cY d }~S d }~ww xY w)Nr   )r   
parse_args
SystemExitr'   r   )r   argvr   rb   s       r   run_with_argvz+GenericArgparseImplementation.run_with_argv  sP    	''-B ##  	 66!9	s   . 	AAAAc                 h    	 | j                  |      S # t        $ r}t        |       Y d}~yd}~ww xY w)zwParse the given command line.

        The commandline is expected to NOT including what would be sys.argv[0].
        Nr/   )r   r   rk   )r   r   rb   s      r   r   z"GenericArgparseImplementation.main'  s2    
	%%d++ 	!H	s    	1,1)NNNF)NF)r   r   r   r*   re   r    r   staticmethodr   r   r   r   r   r   r   r   r   r   r   r   r     sV    | ,8&6 C C:"

,$	r   r   c                 6    t        |      j                  |       S )aI  Execute the generic version of the command line interface.

    You only need to work directly with ``GenericArgparseImplementation`` if
    you desire to customize things.

    If no environment is given, additional arguments will be supported to allow
    the user to specify/construct the environment on the command line.
    )r   r   )r   r.   s     r   r   r   3  s     )-22488r   c                  j    t        j                  t        t         j                  dd       xs d       y)zcRuns the command line interface via ``main``, then exits the process
    with a proper return code.r/   Nr   )rm   r   r   r   r   r   r   runr   ?  s$     HHT#((12,$1%r   __main__r   )*
__future__r   r   r9   rm   rp   r   webassets.loadersr   r   webassets.bundler   webassets.exceptionsr   webassets.updaterr   webassets.merger	   webassets.versionr
   webassets.cacher   webassets.utilsr   r   __all__r   r   r   r   r   objectr   r,   re   r   r   r   r   r   r   r   r   r   r   <module>r     s    %     6 1 + . & * + ) =
   $ % . .w|| <	9 	$f $$U7 UpX.7 X.v<7 <"7 .3V 3lpF pf	9& zE r   