class DriverManager(object):
    def __init__(self, root_dir=None, log_level=None, print_first_line=None, cache_valid_range=1):
        self.driver_cache = DriverCache(root_dir, cache_valid_range)
        if os.environ.get('WDM_PRINT_FIRST_LINE', str(print_first_line)) == 'True':
            log("\n", formatter='%(message)s')
        log("====== WebDriver manager ======", level=log_level)

    def install(self):
        raise NotImplementedError("Please Implement this method")

    def _get_driver_path(self, driver):
        browser_version = driver.browser_version

        driver_name = driver.get_name()
        os_type = driver.get_os_type()
        driver_version = driver.get_version()

        binary_path = self.driver_cache.find_driver(browser_version, driver_name, os_type,
                                                    driver_version)
        if binary_path:
            return binary_path

        file = download_file(driver.get_url())
        binary_path = self.driver_cache.save_file_to_cache(file, browser_version,
                                                           driver_name, os_type, driver_version)
        return binary_path
Example #2
0
class DriverManager(object):
    def __init__(self, root_dir=None, log_level=None):
        self.driver_cache = DriverCache(root_dir)
        global_log_level = os.getenv('WDM_LOG_LEVEL')
        if not global_log_level and log_level:
            os.environ['WDM_LOG_LEVEL'] = str(log_level)

    def install(self):
        raise NotImplementedError("Please Implement this method")

    def _get_driver_path(self, driver):
        browser_version = driver.browser_version

        driver_name = driver.get_name()
        os_type = driver.get_os_type()
        driver_version = driver.get_version()

        binary_path = self.driver_cache.find_driver(browser_version,
                                                    driver_name, os_type,
                                                    driver_version)
        if binary_path:
            return binary_path

        file = download_file(driver.get_url())
        binary_path = self.driver_cache.save_file_to_cache(
            file, browser_version, driver_name, os_type, driver_version)
        return binary_path
class DriverManager(object):
    def __init__(self,
                 root_dir=None,
                 logger: Logger = None,
                 logginglevel=logging.INFO,
                 loggingfile: str = None,
                 cache_valid_range=1):
        self.driver_cache = DriverCache(root_dir, cache_valid_range)
        log("====== WebDriver manager ======",
            logger=logger,
            filename=loggingfile,
            level=logginglevel)

    def install(self):
        raise NotImplementedError("Please Implement this method")

    def _get_driver_path(self, driver):
        browser_version = driver.browser_version

        driver_name = driver.get_name()
        os_type = driver.get_os_type()
        driver_version = driver.get_version()

        binary_path = self.driver_cache.find_driver(browser_version,
                                                    driver_name, os_type,
                                                    driver_version)
        if binary_path:
            return binary_path

        file = download_file(driver.get_url())
        binary_path = self.driver_cache.save_file_to_cache(
            file, browser_version, driver_name, os_type, driver_version)
        return binary_path
Example #4
0
 def __init__(self, root_dir=None, log_level=None, print_first_line=None, cache_valid_range=1):
     self.driver_cache = DriverCache(root_dir, cache_valid_range)
     global_log_level = os.getenv('WDM_LOG_LEVEL')
     if not global_log_level and log_level:
         os.environ['WDM_LOG_LEVEL'] = str(log_level)
     global_print_first_line = os.getenv('WDM_PRINT_FIRST_LINE')
     if not global_print_first_line and print_first_line:
         os.environ['WDM_PRINT_FIRST_LINE'] = str(print_first_line)
Example #5
0
 def __init__(self,
              root_dir=None,
              log_level=None,
              print_first_line=None,
              cache_valid_range=1):
     self.driver_cache = DriverCache(root_dir, cache_valid_range)
     if print_first_line:
         print("\n")
     log("====== WebDriver manager ======")
Example #6
0
 def __init__(self,
              root_dir=None,
              log_level=None,
              print_first_line=None,
              cache_valid_range=1):
     self.driver_cache = DriverCache(root_dir, cache_valid_range)
     if os.environ.get('WDM_PRINT_FIRST_LINE',
                       str(print_first_line)) == 'True':
         log("\n", formatter='%(message)s')
     log("====== WebDriver manager ======")
class DriverManager(object):
    def __init__(self, root_dir=None):
        self.driver_cache = DriverCache(root_dir)

    def install(self):
        raise NotImplementedError("Please Implement this method")

    def __get_latest_driver_version(self, driver):
        latest_cached = self.driver_cache.get_latest_cached_driver_version(
            driver.get_name())
        if latest_cached is not None:
            return latest_cached

        return driver.get_latest_release_version()

    def __get_version_to_download(self, driver):
        driver_version = driver.get_version()

        if driver_version == "latest":
            return self.__get_latest_driver_version(driver), True
        return driver_version, False

    def __download_and_save_driver_to_cache(self,
                                            driver,
                                            driver_version,
                                            DEBUG_LOGGING=True):
        response = download_driver(driver.get_url(driver_version),
                                   DEBUG_LOGGING=DEBUG_LOGGING)
        return self.driver_cache.save_driver_to_cache(
            response,
            driver.get_name(),
            driver_version,
            driver.get_os_type(),
            DEBUG_LOGGING=DEBUG_LOGGING)

    def download_driver(self, driver, DEBUG_LOGGING=True):
        driver_version, is_latest = self.__get_version_to_download(driver)

        cached_path = self.driver_cache.find_file_if_exists(
            driver.get_name(),
            driver.get_os_type(),
            driver_version,
            is_latest,
            DEBUG_LOGGING=DEBUG_LOGGING)
        if cached_path is not None:
            return cached_path

        path = self.__download_and_save_driver_to_cache(
            driver, driver_version, DEBUG_LOGGING=DEBUG_LOGGING)

        if is_latest:
            self.driver_cache.save_latest_driver_version_number_to_cache(
                driver.get_name(), driver_version)

        return path
 def __init__(self,
              root_dir=None,
              logger: Logger = None,
              logginglevel=logging.INFO,
              loggingfile: str = None,
              cache_valid_range=1):
     self.driver_cache = DriverCache(root_dir, cache_valid_range)
     log("====== WebDriver manager ======",
         logger=logger,
         filename=loggingfile,
         level=logginglevel)
Example #9
0
class DriverManager(object):
    def __init__(self, root_dir=None, log_level=None):
        self.driver_cache = DriverCache(root_dir)
        global_log_level = os.getenv('WDM_LOG_LEVEL')
        if not global_log_level:
            os.environ['WDM_LOG_LEVEL'] = str(log_level)

    def install(self):
        raise NotImplementedError("Please Implement this method")

    def __get_latest_driver_version(self, driver):
        latest_cached = self.driver_cache.get_latest_cached_driver_version(driver.get_name())
        if latest_cached is not None:
            return latest_cached

        return driver.get_latest_release_version()

    def __get_version_to_download(self, driver):
        driver_version = driver.get_version()

        if driver_version == "latest":
            return self.__get_latest_driver_version(driver), True
        return driver_version, False

    def __download_and_save_driver_to_cache(self, driver, driver_version):
        response = download_driver(driver.get_url(driver_version))
        return self.driver_cache.save_driver_to_cache(response, driver.get_name(), driver_version,
                                                      driver.get_os_type())

    def download_driver(self, driver):
        driver_version, is_latest = self.__get_version_to_download(driver)

        cached_path = self.driver_cache.find_file_if_exists(driver.get_name(), driver.get_os_type(),
                                                            driver_version, is_latest)
        if cached_path is not None:
            return cached_path

        path = self.__download_and_save_driver_to_cache(driver, driver_version)

        if is_latest:
            self.driver_cache.save_latest_driver_version_number_to_cache(driver.get_name(), driver_version)

        return path
 def __init__(self, root_dir=None, log_level=None):
     self.driver_cache = DriverCache(root_dir)
     if log_level:
         os.environ['WDM_LOG_LEVEL'] = str(log_level)
import datetime
import os

from webdriver_manager.driver_cache import DriverCache
from webdriver_manager.utils import download_driver

project_root = os.path.dirname(os.path.dirname(__file__))
cache_root_dir = ".wdm"
name = "chromedriver"
version = "77"
os_type = "linux"

driver_cache = DriverCache(os.path.join(project_root, cache_root_dir))


def create_file(name, version, os_type):
    path = os.path.join(project_root, cache_root_dir, "drivers", name, version,
                        os_type)

    os.makedirs(path, exist_ok=True)
    file_path = os.path.join(path, "chromedriver")

    open(file_path, "w+")
    return file_path


def test_driver_cash_can_create_folder_on_init():
    driver_cache.create_cache_dir_for_driver(
        os.path.join(project_root, cache_root_dir, name, version, os_type))
    assert os.path.exists(driver_cache._root_dir)
Example #12
0
 def __init__(self, root_dir=None):
     self.driver_cache = DriverCache(root_dir)
Example #13
0
 def __init__(self, root_dir=None, log_level=None):
     self.driver_cache = DriverCache(root_dir)
     global_log_level = os.getenv('WDM_LOG_LEVEL')
     if not global_log_level and log_level:
         os.environ['WDM_LOG_LEVEL'] = str(log_level)