a
    5ñ»j×  ã                   @   s„   d dl Z d dl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 d dl	m
Z
 d dl	mZ d dlmZ e e¡ZG dd„ dƒZdS )é    N)ÚPath)ÚList)ÚOptional)ÚWebDriverExceptionc                   @   s`   e Zd ZdZeedœdd„Zeedœdd„ƒZ	eee
 edœdd	„ƒZeee d
œdd„ƒZdS )ÚSeleniumManagerzƒWrapper for getting information from the Selenium Manager binaries.

    This implementation is still in beta, and may change.
    )ÚargsÚreturnc                 C   s\   t |  ¡ ƒg| }t ¡ tjkr*| d¡ | d¡ | d¡ | d¡ | d¡ |  |¡S )zÆDetermines the locations of the requested assets.

        :Args:
         - args: the commands to send to the selenium manager binary.
        :Returns: dictionary of assets and their path
        z--debugz--language-bindingÚpythonz--outputÚjson)ÚstrÚ_get_binaryÚloggerÚgetEffectiveLevelÚloggingÚDEBUGÚappendÚ_run)Úselfr   © r   úPE:\soccer\ml_env\Lib\site-packages\selenium/webdriver/common/selenium_manager.pyÚbinary_paths'   s    




zSeleniumManager.binary_paths)r   c                  C   s  t tƒj d¡} t d¡}|dur,|  |¡} d}t d¡ }durXt	 
d|¡ t |ƒ}nŒ|  ¡ rf| }n~ddddddd	œ}tjd
v rŠt ¡ nd}tjdv r¦t	 dtj¡ | tj|f¡}|du rÔtdtj› d|› �ƒ‚t tƒj |¡}|du sö| ¡ �std|› �ƒ‚t	 
d|¡ |S )zÄDetermines the path of the correct Selenium Manager binary.

        :Returns: The Selenium Manager executable location

        :Raises: WebDriverException if the platform is unsupported
        zselenium-managerÚEXENZSE_MANAGER_PATHz2Selenium Manager set by env SE_MANAGER_PATH to: %szmacos/selenium-managerzwindows/selenium-manager.exezlinux/selenium-manager))ÚdarwinÚany)Úwin32r   )Úcygwinr   )ÚlinuxÚx86_64)Úfreebsdr   )Úopenbsdr   )r   r   r   r   )r   r   zFSelenium Manager binary may not be compatible with %s; verify settingsz/Unsupported platform/architecture combination: ú/z2Unable to obtain working Selenium Manager binary; z$Selenium Manager binary found at: %s)r   Ú__file__ÚparentÚjoinpathÚ	sysconfigÚget_config_varÚwith_suffixÚosÚgetenvr   ÚdebugÚexistsÚsysÚplatformÚmachineÚwarningÚgetr   Úis_file)Zcompiled_pathÚexeÚpathZenv_pathÚallowedÚarchÚlocationr   r   r   r   9   s8    	


ú	
zSeleniumManager._get_binaryc              
   C   sþ   d  | ¡}t d|¡ zptjdkr6tj| dtjd�}ntj| dd�}|j 	d¡ 
d¡}|j 	d¡ 
d¡}|d	krzt |¡ng i d
œ}W n4 tyº } ztd|› �ƒ|‚W Y d}~n
d}~0 0 t |d ¡ |d }|jrútd|› d|j› d|› d|› �ƒ‚|S )z¾Executes the Selenium Manager Binary.

        :Args:
         - args: the components of the command being executed.
        :Returns: The log string containing the driver location.
        ú zExecuting process: %sr   T)Úcapture_outputÚcreationflags)r7   zutf-8Ú
Ú )ÚlogsÚresultzUnsuccessful command executed: Nr;   r<   z; code: )Újoinr   r)   r+   r,   Ú
subprocessÚrunÚCREATE_NO_WINDOWÚstdoutÚdecodeÚrstripÚstderrr
   ÚloadsÚ	Exceptionr   r   Ú_process_logsÚ
returncode)r   ÚcommandZcompleted_procrA   rD   ÚoutputÚerrr<   r   r   r   r   i   s$    

 &ÿzSeleniumManager._run)Ú	log_itemsc                 C   sD   | D ]:}|d dkr$t  |d ¡ q|d dv rt  |d ¡ qd S )NÚlevelÚWARNÚmessage)r   ÚINFO)r   r.   r)   )rL   Úitemr   r   r   rG   †   s
    zSeleniumManager._process_logsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Údictr   Ústaticmethodr   r   r   r   rG   r   r   r   r   r   !   s   /r   )r
   r   r'   r,   r>   r+   r$   Úpathlibr   Útypingr   r   Zselenium.commonr   Ú	getLoggerrR   r   r   r   r   r   r   Ú<module>   s   
