o
    ºe~iÊ  ã                   @  sF   d dl mZ d dlZd dlmZ d dlmZmZ dddœddd„ZdS )é    )ÚannotationsN)ÚPath)ÚListÚUnioné   T)ÚdaysÚdry_runÚartifacts_dirr   r   Úintr   ÚboolÚreturnúUnion[int, List[Path]]c           	   
   C  sr  t | ƒ} |  ¡ s|rg S dS t ¡ |d  }g }|  ¡ D ] }| ¡ s#qz| ¡ }|j|k r2| |¡ W q ty<   Y qw |rOt	|ƒD ]	}t
d|› ƒ qC|S d}|D ]c}zQ| d¡D ]}z| ¡ sf| ¡ rl|jdd W q[ tyv   Y q[w t	| d¡ddD ]}z
| ¡ r‹| ¡  W q€ ty•   Y q€w | ¡  |d7 }t
d	|› ƒ W qS ty¶   t
d
|› ƒ Y qSw |S )u  
    Borra carpetas de corrida dentro de artifacts_dir mÃ¡s viejas que N dÃ­as.
    Cada corrida es un folder tipo: timesheet-create-YYYYMMDD-HHMMSS.

    Retorna:
      - dry_run=True: lista de Path que se borrarÃ­an
      - dry_run=False: int con cantidad de carpetas borradas
    r   i€Q z[UIZ][dry-run] would delete: Ú*T)Ú
missing_ok)Úreverseé   z[UIZ] deleted: z[UIZ] failed to delete: )r   ÚexistsÚtimeÚiterdirÚis_dirÚstatÚst_mtimeÚappendÚ	ExceptionÚsortedÚprintÚrglobÚis_fileÚ
is_symlinkÚunlinkÚrmdir)	r	   r   r   ÚcutoffÚ
candidatesÚpÚstÚdeletedÚchild© r'   úi/var/www/html/flask_server/apps/aroflo_connector_app/ui_automation_zones/maintenance/cleanup_artifacts.pyÚcleanup_artifacts	   s^   	

€ÿ€ÿ€ÿþr)   )r	   r   r   r
   r   r   r   r   )	Ú
__future__r   r   Úpathlibr   Útypingr   r   r)   r'   r'   r'   r(   Ú<module>   s
   