
    vj                     `    d Z ddlZddlZddlZddlmZ  G d d      Zd Zedk(  r e        yy)z
From a list of trame modules name, gather and generate the required static
content that needs to be served for a trame application to work.
    N)Pathc                   2    e Zd Zd Zd Zd Zd Zd ZddZy)	StaticContentGeneratorc                 <    d| _         d | _        i | _        d| _        y )Nwww_generatorvue3)namewwwserveclient_type)selfs    </DATA/.local/lib/python3.12/site-packages/trame/tools/www.py__init__zStaticContentGenerator.__init__   s    #	
!    c                     dd l }t        j                  d      } | j                  |j	                  |j
                        D cg c]  }|j                   c}  y c c}w )Nr   ztrame.modules)pkgutil	importlibimport_moduleenable_modulesiter_modules__path__r	   )r   r   rootms       r   
enable_allz!StaticContentGenerator.enable_all   sL    &&7g.B.B4==.QR.Qaff.QRSRs   Ac                      y)zFake serverN )r   argskwargss      r   add_protocol_to_configurez0StaticContentGenerator.add_protocol_to_configure   s    r   c                 <   t        |t              r|n|j                  }d}d|v r	  |j                  d      |        d}nd}|rJd|v r*| j
                  j                  |j                  d             d|v r|j                  d      | _        y y y # t        $ r Y Xw xY w)NFsetupTr   r
   )
isinstancedict__dict__get	TypeErrorr   updater
   )r   moduler   definitionsload_remainings        r   enable_modulez$StaticContentGenerator.enable_module   s     *64 8ffook!((.!% "N+%

!!+//'":;#&??51 $	   s   B 	BBc                 *   |D ]?  }d }	 t        j                  d|       }|t        d|        /| j	                  |       A y # t        $ rC 	 t        d|       t        j                  |      }n# t        $ r t        d|        Y nw xY wY pw xY w)Nztrame.modules.zmodule_name:z - Error: Skipping module zSkipping module: )r   r   ModuleNotFoundErrorprintr+   )r   namesmodule_namer(   s       r   r   z%StaticContentGenerator.enable_modules2   s     KFF"00>+1OP ~)+78v& ! ' FF.+6&44[AF* F6{mDEF	Fs5   A	B!A21B2B	BBBBNc                    |t        j                         }| j                  r"t        j                  | j                  |d       | j
                  j                         D ]+  \  }}t        |      |z  }t        j                  ||d       - y )NT)dirs_exist_ok)r   cwdr
   shutilcopytreer   items)r   output_directorysub_pathsrc_dirdst_dirs        r   writezStaticContentGenerator.writeD   sr    ##xxz88OO " "&!1!1!3Hg+,x7GOOGWDA "4r   )N)	__name__
__module____qualname__r   r   r   r+   r   r;   r   r   r   r   r      s"    "T2*'$Br   r   c                  f   t        j                  d      } | j                  dd       | j                  ddd	       | j                         \  }}t	               }|j
                  |_        t        |      r |j                  |  n|j                          |j                  |j                         y )
Nz2Static Web Client generator for trame applications)descriptionz--outputz(Directory to fill with trame client code)helpz--client-typer   z"Type of client to use [vue2, vue3])defaultrA   )argparseArgumentParseradd_argumentparse_known_argsr   r   lenr   r   r;   output)parserr   module_names	generators       r   mainrL   T   s    $$HF 7  
 1    002D,&(I ,,I
< 	  ,/OODKK r   __main__)	__doc__rC   r   r4   pathlibr   r   rL   r<   r   r   r   <module>rP      s@   
    EB EBP!4 zF r   