
    i                         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
  ej                  e      Z G d d      Zy)    N)Path)WebDriverExceptionc                   r    e Zd ZdZdedefdZedefd       Z	edee
   defd       Zedee   fd       Zy	)
SeleniumManagerzWrapper for getting information from the Selenium Manager binaries.

    This implementation is still in beta, and may change.
    argsreturnc                 R   t        | j                               g|z   }t        j                         t        j
                  k(  r|j                  d       |j                  d       |j                  d       |j                  d       |j                  d       | j                  |      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   s     f/var/www/html/BatchJob/venv/lib/python3.12/site-packages/selenium/webdriver/common/selenium_manager.pybinary_pathszSeleniumManager.binary_paths&   s     D$$&'(4/##%6KK	"()HJFyy    c                     t        t              j                  j                  d      } t	        j
                  d      }|| j                  |      } d}t        j                  d      x}Dt        j                  d|        t        |      }|j                         st        d|       |}n| j                         r| }ndddd	d	d	d
}t        j                  dv rt        j                         nd}t        j                  dv r't        j!                  dt        j                   d       |j#                  t        j                  |f      }|t        dt        j                   d|       t        t              j                  j                  |      }||j                         st        d|       t        j                  d|        |S )aL  Determines the path of the Selenium Manager binary.

        Location of the binary is checked in this order:

        1. location set in an environment variable
        2. location where setuptools-rust places the compiled binary (built from the sdist package)
        3. location where we ship binaries in the wheel package for the platform this is running on
        4. give up

        Returns:
            The Selenium Manager executable location.

        Raises:
            WebDriverException: If the platform is unsupported or Selenium Manager executable can't be found.
        zselenium-managerEXENSE_MANAGER_PATHz0Selenium Manager set by env SE_MANAGER_PATH to: z*SE_MANAGER_PATH does not point to a file: z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"   z3Selenium Manager binary may not be compatible with z; verify settingsz/Unsupported platform/architecture combination: /z2Unable to obtain working Selenium Manager binary; z"Selenium Manager binary found at: )r   __file__parentjoinpath	sysconfigget_config_varwith_suffixosgetenvr   debugis_filer   sysplatformmachinewarningget)compiled_pathexepathenv_pathpath_candidateallowedarchlocations           r   r   zSeleniumManager._get_binary9   s   " X--667IJ&&u-?)55c:M 		"344HALLKH:VW!(^N!))+(+UV^U_)`aa!D""$ D $<"@#A%='?'?G *-9X)X8##%^cD||55!TUXUaUaTbbstu{{CLL$#78H(+Z[^[g[gZhhijnio)pqq>((11(;D<t||~$'YZ^Y_%`aa9$@Ar   c           
         dj                  |       }t        j                  d|       	 t        j                  dk(  r't        j                  | dt
        j                        }nt        j                  | d      }|j                  j                  d      j                  d      }|j                  j                  d      j                  d      }|d	k7  rt        j                  |      ng i d
}t         j#                  |d          |d   }|j$                  r!t        d| d|j$                   d| d|       |S # t        $ r}t        d|       |d}~ww xY w)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)r=   zutf-8
 )logsresultzUnsuccessful command executed: NrA   rB   z; code: )joinr   r,   r.   r/   
subprocessrunCREATE_NO_WINDOWstdoutdecoderstripstderrr   loads	Exceptionr   r   _process_logs
returncode)r   commandcompleted_procrG   rJ   outputerrrB   s           r   r   zSeleniumManager._runt   sG    ((4.,g6		[||w&!+TYcYtYt!u!+T!J#**11':AA$GF#**11':AA$GF+1R<TZZ'bTV=WF 	%%fVn5!$$$1'(>C\C\B]]_`f_ggijpiqr    	[$'Fwi%PQWZZ	[s   CD9 9	EEE	log_itemsc                     | D ]C  }|d   dk(  rt         j                  |d          $|d   dv s,t         j                  |d          E y )NlevelWARNmessage)r   INFO)r   r1   r,   )rS   items     r   rM   zSeleniumManager._process_logs   sJ     	.DG}&tI/g"33T)_-		.r   N)__name__
__module____qualname____doc__listdictr   staticmethodr   r   r   r   rM    r   r   r   r       s{    
 $ & 8 8 8t 49   < .d . .r   r   )r   r   r*   r/   rD   r.   r'   pathlibr   selenium.commonr   	getLoggerrZ   r   r   ra   r   r   <module>re      s@   $   	   
   .			8	$y. y.r   