def get_firefox_driver_latest(self, path="./bin"): """ Download Latest Firefox geckodriver Driver and add it to system path (only for this session). If system already contains proper version do nothing. Based on information from https://api.github.com/repos/mozilla/geckodriver/releases/latest """ try: initial = osl().get_environment_variable("PATH") path_abstract = os.path.abspath(path) if path_abstract not in initial: osl().set_environment_variable( "PATH", path_abstract + os.pathsep + initial) try: version = subprocess.check_output(["geckodriver", "--version"], shell=True, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: version = "Firefox geckodriver driver is MISSING " version_current = version.strip() version_latest = self.get_latest_firefox_driver_version.replace( "v", "").strip() url_firefox = self.get_url_for_latest_firefox_driver logger.debug("Current version \t" + version_current) logger.debug("Latest version :\t" + version_latest) if version_latest not in version_current: logger.info("Current version %s , latest is %s" % (version_current, version_latest)) logger.info("start download firefox geckodriver driver :" + url_firefox) if not os.path.exists(path_abstract): os.makedirs(path_abstract) driver = urllib.urlopen(url_firefox).read() logger.debug("Firefox geckodriver driver compressed size: " + sizeof_fmt(len(driver))) from zipfile import ZipFile from io import BytesIO with ZipFile(BytesIO(driver)) as zfile: zfile.extractall(path_abstract) logger.info("Chrome driver extracted to : " + path_abstract) else: logger.info( "Latest Version of Firefox geckodriver Present %s , latest %s" % (version_current, version_latest)) except KeyError as e: logger.error(e) except OSError as e: logger.error(e)
def get_chrome_driver_latest(self, path='./bin'): """ Download Latest Chrome Driver and add it to system path (only for this session). If system already contains proper version do nothing. Based on information from http://chromedriver.storage.googleapis.com/LATEST_RELEASE """ try: initial = osl().get_environment_variable("PATH") path_abstract = os.path.abspath(path) if (path_abstract not in initial): osl().set_environment_variable( "PATH", path_abstract + os.pathsep + initial) try: version = subprocess.check_output( ["chromedriver", "--version"], shell=True, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: version = "Chrome driver is MISSING " version_current = version.strip() version_latest = self.get_latest_chrome_driver_version url_chrome = self.get_url_for_latest_chrome_driver logger.debug("Current version \t" + version_current) logger.debug("Latest version :\t" + version_latest) if (version_latest not in version_current): logger.info("Current version %s , latest is %s" % (version_current, version_latest)) if not os.path.exists(path_abstract): os.makedirs(path_abstract) logger.info("start download chrome driver :" + url_chrome) driver = urllib.urlopen(url_chrome).read() logger.debug("Chrome driver compressed size: " + sizeof_fmt(len(driver))) from zipfile import ZipFile from io import BytesIO with ZipFile(BytesIO(driver)) as zfile: zfile.extractall(path_abstract) logger.info("Chrome driver extracted to : " + path_abstract) else: logger.info( "Latest Version of ChromeDriver Present %s , latest %s" % (version_current, version_latest)) except KeyError as e: logger.error(e) except OSError as e: logger.error(e)
def append_to_file_at_beginning(path, content, encoding="UTF-8"): path = os.path.abspath(path) parent = os.path.dirname(path) if not os.path.exists(parent): os.makedirs(parent) if not os.path.isfile(path): open(path, 'w').close() with open(path, 'r') as original: data = original.read() final_content = content + "\n" + data with open(path, 'w') as modified: modified.write(final_content.encode(encoding)) # noinspection PyProtectedMember robot_instances.osl()._link("Appended to file begin of file '%s'.", path)
def get_firefox_driver_latest(self, path='./bin'): """ Download Latest Firefox geckodriver Driver and add it to system path (only for this session). If system already contains proper version do nothing. Based on information from https://api.github.com/repos/mozilla/geckodriver/releases/latest """ try: initial = osl().get_environment_variable("PATH") path_abstract = os.path.abspath(path) if (path_abstract not in initial): osl().set_environment_variable("PATH", path_abstract + os.pathsep + initial) try: version = subprocess.check_output(["geckodriver", "--version"], shell=True, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: version = "Firefox geckodriver driver is MISSING " version_current = version.strip() version_latest = self.get_latest_firefox_driver_version.replace("v", "").strip() url_firefox = self.get_url_for_latest_firefox_driver logger.debug("Current version \t" + version_current) logger.debug("Latest version :\t" + version_latest) if (version_latest not in version_current): logger.info("Current version %s , latest is %s" % (version_current, version_latest)) logger.info("start download firefox geckodriver driver :" + url_firefox) if not os.path.exists(path_abstract): os.makedirs(path_abstract) driver = urllib.urlopen(url_firefox).read() logger.debug("Firefox geckodriver driver compressed size: " + sizeof_fmt(len(driver))) from zipfile import ZipFile from io import BytesIO with ZipFile(BytesIO(driver)) as zfile: zfile.extractall(path_abstract) logger.info("Chrome driver extracted to : " + path_abstract) else: logger.info("Latest Version of Firefox geckodriver Present %s , latest %s" % (version_current, version_latest)) except KeyError as e: logger.error(e) except OSError as e: logger.error(e)