def get_cached_binary(self, driver, path=None): if not path is None: self.root_dir = path cached_driver = driver.config.driver_path is_offline = driver.config.offline if cached_driver and is_offline == 'True': console("Using driver from cache {}".format(cached_driver)) return Binary(cached_driver) name = driver.name version = driver.get_version() os_type = driver.os_type console("") console("Checking for {} {}:{} in cache".format( os_type, name, version), bold=True) if "win" in os_type: name += ".exe" if path is None: for dirName, subdirList, fileList in \ os.walk(self.get_cache_path()): for fname in fileList: target_file = os.path.join(version, os_type, name) driver_file = os.path.join(dirName, fname) if driver_file.endswith(target_file): console("Driver found in {}/{}".format(dirName, fname)) return Binary(os.path.join(dirName, fname)) else: if os.path.isfile(os.path.join(path, name)): console("Driver found in {}".format(os.path.join(path, name))) return Binary(os.path.join(path, name)) console("There is no cached driver. Downloading new one...") return None
def download_driver(self, driver): cached_binary = self.get_cached_binary(driver) if cached_binary: return cached_binary zip_file = self._download_file(driver) files = archive.unpack(zip_file) return Binary(os.path.join(os.path.dirname(zip_file.name), files[0]))
def download_binary(self, driver, path=None): if path is not None: path = os.path.abspath(path) cached_binary = self.get_cached_binary(driver, path) if cached_binary: return cached_binary return Binary(self._download_file(driver).name)
def download_binary(self, driver): cached_binary = self.get_cached_binary(driver.name, driver.get_version(), driver.os_type) if cached_binary: return cached_binary return Binary(self._download_file(driver).name)
def install(self): cached_binary = self._file_manager.get_cached_binary(self.driver) if cached_binary: return cached_binary.path zip_file = self._file_manager._download_file(self.driver) path = self.__extract_phantomjs_bin(zip_file) bin_file = Binary(path) os.chmod(bin_file.path, 0o755) return bin_file.path
def download_driver(self, driver, path=None): # type: (Driver) -> Binary if path is not None: path = os.path.abspath(path) cached_binary = self.get_cached_binary(driver, path) if cached_binary: return cached_binary zip_file = self._download_file(driver, path) files = archive.unpack(zip_file) return Binary(os.path.join(os.path.dirname(zip_file.name), files[0]))
def install(self, path=None): if not path is None: path = os.path.abspath(path) cached_binary = self._file_manager.get_cached_binary(self.driver, path) if cached_binary: return cached_binary.path zip_file = self._file_manager._download_file(self.driver, path) path = self.__extract_phantomjs_bin(zip_file) bin_file = Binary(path) os.chmod(bin_file.path, 0o755) return bin_file.path
def get_cached_binary(self, driver): cached_driver = driver.config.driver_path is_offline = driver.config.offline if cached_driver and is_offline == 'True': logging.warning("Using driver from cache {}".format(cached_driver)) return Binary(cached_driver) name = driver.name version = driver.get_version() os_type = driver.os_type logging.warning("Checking for {} {}:{} in cache".format( os_type, name, version)) if "win" in os_type: name += ".exe" for dirName, subdirList, fileList in os.walk(self.get_cache_path()): for fname in fileList: if os.path.join(dirName, fname).endswith(os.path.join(version, name)): logging.warning("Driver found in cache {}/{}".format( dirName, fname)) return Binary(os.path.join(dirName, fname)) logging.warning("There is no cached driver. Downloading new one...") return None
def get_cached_binary(self, name, version, os_type): logging.warning("Checking for {} {}:{} in cache".format( os_type, name, version)) if "win" in os_type: name += ".exe" for dirName, subdirList, fileList in os.walk(self.get_cache_path()): for fname in fileList: if os.path.join(dirName, fname).endswith(os.path.join(version, name)): logging.warning("Driver found in cache {}/{}".format( dirName, fname)) return Binary(os.path.join(dirName, fname)) logging.warning("There is no cached driver. Downloading new one...") return None
def download_binary(self, driver): cached_binary = self.get_cached_binary(driver) if cached_binary: return cached_binary return Binary(self._download_file(driver).name)