a
    RIh                     @   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
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 )SeleniumManagerzWrapper 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 )zDetermines 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   d/var/www/html/venv_bot_3.9/lib/python3.9/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 rt nd}tjdv rt	dtj |tj|f}|du rtdtj d| t tj|}|du s| std| t	
d| |S )zDetermines 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   8   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rtd| d|j d| d| |S )zExecutes 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runZCREATE_NO_WINDOWstdoutdecoderstripstderrr
   loads	Exceptionr   r   _process_logs
returncode)r   commandZcompleted_procr@   rC   outputerrr<   r   r   r   r   h   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)   )rK   itemr   r   r   rF      s
    zSeleniumManager._process_logsN)__name__
__module____qualname____doc__r   dictr   staticmethodr   r   r   r   rF   r   r   r   r   r       s   /r   )r
   r   r'   r,   r>   r+   r$   pathlibr   typingr   r   Zselenium.commonr   	getLoggerrQ   r   r   r   r   r   r   <module>   s   
