o
    vh                     @   sD   d dl Z d dlmZ ddlmZ ddlmZmZ G dd deZdS )    N)BaseCommand   )MissingSource)cachefile_registrygenerator_registryc                   @   s4   e Zd ZdZdZdd Zdd Zdd Zd	d
 ZdS )Commanda  Generate files for the specified image generators (or all of them if
none was provided). Simple, glob-like wildcards are allowed, with *
matching all characters within a segment, and ** matching across
segments. (Segments are separated with colons.) So, for example,
"a:*:c" will match "a:b:c", but not "a:b:x:c", whereas "a:**:c" will
match both. Subsegments are always matched, so "a" will match "a" as
well as "a:b" and "a:b:c".z[generator_ids]c                 C   s   |j dddd d S )Ngenerator_id*z*<app_name>:<model>:<field> for model specs)nargshelp)add_argument)selfparser r   i/var/www/html/hyperkenya/venv/lib/python3.10/site-packages/imagekit/management/commands/generateimages.pyadd_arguments   s   zCommand.add_argumentsc                    s   t  }d|v r|d n|}|r| |  fdd|D }|D ]V}| jd|  t|D ]F}|jru| jd|j  z|  W q/ t	y[ } z| jd W Y d }~q/d }~w t
yt } z| jd|  W Y d }~q/d }~ww q/q d S )Nr   c                 3   s*    | ] t  fd dD r V  qdS )c                 3   s    | ]}|  V  qd S )N)match).0pidr   r   	<genexpr>   s    z+Command.handle.<locals>.<genexpr>.<genexpr>N)any)r   patternsr   r   r      s   ( z!Command.handle.<locals>.<genexpr>zValidating generator: %s
z  %s
z	 No source associated with
z	Failed %s
)r   get_idscompile_patternsstdoutwriter   getnamegenerater   	Exception)r   argsoptions
generatorsgenerator_idsr   
image_fileerrr   r   r   handle   s,   
zCommand.handlec                    s    fdd|D S )Nc                    s   g | ]}  |qS r   )compile_pattern)r   r   r   r   r   
<listcomp>+   s    z,Command.compile_patterns.<locals>.<listcomp>r   )r   r&   r   r+   r   r   *   s   zCommand.compile_patternsc                 C   sZ   t d|}d}|D ]}|dkr|d7 }q
|dkr|d7 }q
|t |7 }q
t d| S )Nz	(\*{1,2}) r	   z[^:]*z**z.*z
^%s(:.*)?$)resplitescapecompile)r   r   partspatternpartr   r   r   r*   -   s   

zCommand.compile_patternN)	__name__
__module____qualname__r   r#   r   r)   r   r*   r   r   r   r   r   	   s    r   )	r.   django.core.management.baser   
exceptionsr   registryr   r   r   r   r   r   r   <module>   s
    