
    Vh                       d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
mZ ddlmZ ddlmZ dd	lmZ  ej$                  d
      ZdZdZdZddZdddZedk(  rb ej4                  ej6                  d        e       Zej;                  ddd       ej=                         Z e  eejB                              y)a6  
Fetch and bundles the hcloud package inside the collection.

Fetch the desired version `HCLOUD_VERSION` from https://github.com/hetznercloud/hcloud-python
`HCLOUD_SOURCE_URL` using git, apply some code modifications to comply with ansible,
move the modified files at the vendor location `HCLOUD_VENDOR_PATH`.
    )annotationsN)ArgumentParser)Path)movermtree)
check_call)TemporaryDirectory)dedentvendorz-https://github.com/hetznercloud/hcloud-pythonzv2.3.0z"plugins/module_utils/vendor/hcloudc                   | j                  d      D ]  }|j                         }|}t        j                  dt	        d      j                         |      }t        j                  dt	        d      j                         |      }t        j                  dd|      }||k7  rt        j                  d|       |j                  |        y )	Nz*.pyzimport requestsz
                try:
                    import requests
                except ImportError:
                    requests = None
                z$from dateutil.parser import isoparsez
                try:
                    from dateutil.parser import isoparse
                except ImportError:
                    isoparse = None
                z: requests\.Response z Applied code modifications on %s)	rglob	read_textresubr
   striploggerinfo
write_text)source_pathfilecontentcontent_origs       a/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/hetzner/hcloud/scripts/vendor.pyapply_code_modificationsr      s    !!&) *!.." && eg
 &&3 eg
 &&#
 l"KK:DA U*!    Fc           
        t               5 }t        |      }t        j                  d|       t	        ddddt
        t        |g       t        j                  d|       t        |dz         t        j                  d       t        t               t        |dz  t               t        j                  d	       d d d        | rt	        dd
ddt        g       y# 1 sw Y    xY w)NzCreated temporary directory %sgitclonez	--depth=1z--branchzCloned the source files in %shcloudz.Applied code modifications on the source filesz4Bundled the modified sources files in the collectiondiffz--exit-codez--r   )r	   r   r   r   r   HCLOUD_VERSIONHCLOUD_SOURCE_URLr   r   HCLOUD_VENDOR_PATHr   )checktmp_dirtmp_dir_paths      r   mainr(   K   s    		 LG}4lCE7K^M^`lmn3\B !89DE!"\H$&89JKL E6=$8JKL#L Ls   B,CC__main__z%(levelname)-8s: %(message)s)levelformatz--check
store_true)actiondefault)r%   )r   r   )F)r%   boolreturnint)"__doc__
__future__r   loggingr   argparser   pathlibr   shutilr   r   
subprocessr   tempfiler	   textwrapr
   	getLoggerr   r#   r"   r$   r   r(   __name__basicConfigINFOparseradd_argument
parse_argsargs
SystemExitr%    r   r   <module>rE      s    #  	 #   ! ' 			8	$C 9 +!\* zGgll3QRF
	,FD
T

+
,, r   