class Chromedriver(object): def __init__(self): self.ut = Utility() self.ot = OS_type() self.log = Logger() # Get the required chromedriver informations from the downloader_config.ini # Use the config_reader function from the Utility class to read the required configuration def chromedriver_objects(self): config_dict = {} config_parser = self.ut.config_reader() driver_type = config_parser.get('ChromeDriver', 'name') api_url = config_parser.get('ChromeDriver', 'url') latest_release = config_parser.get('ChromeDriver', 'latest_browser_driver') arch = config_parser.get('ChromeDriver', 'arch_type') config_dict = { 'driver_type': driver_type, 'api_url': api_url, 'latest_release': latest_release, 'arch': arch } return config_dict # build the required download url based on the information gathered using the # chromedriver_objects function def url_builder(self, os_extension): data = self.chromedriver_objects() LATEST_RELEASE = requests.get(data['latest_release']) url_builder = data['api_url'] + LATEST_RELEASE.text + '/' + data[ 'driver_type'] + os_extension + data['arch'] + '.zip' return url_builder # Download the required chromedriver binary based on the operating system type def evaluate_on_environment(self, os_name, arch_type): dir_path = self.ut.get_driver_path("/dependencies/dir_chromedriver") if os_name == 'macos' and arch_type == '64': self.ut.log_message("INFO", "Environment: " + os_name) self.ut.log_message("INFO", "Architecture Type: " + arch_type) url_builder_mac = self.url_builder('_mac') self.ut.log_message( "INFO", "Downloading the required binary for chromedriver") self.ut.driver_downloader(url_builder_mac, dir_path) self.ut.log_message("INFO", "Download completed") self.ut.unzip_file('dir_chromedriver/') self.ut.log_message("INFO", "Unarchiving contents completed") if os_name == 'linux' and arch_type == '64': self.ut.log_message("INFO", "Environment: " + os_name) self.ut.log_message("INFO", "Architecture Type: " + arch_type) url_builder_linux = self.url_builder('_linux') self.ut.log_message( "INFO", "Downloading the required binary for chromedriver") self.ut.driver_downloader(url_builder_linux, dir_path) self.ut.log_message("INFO", "Download completed") self.ut.unzip_file('dir_chromedriver/') self.ut.log_message("INFO", "Unarchiving contents completed") # Create a required directory separately for Chrome and called the evaluate_on_environment # function to download the required binary def download_driver(self): dir_path = self.ut.get_driver_path("/dependencies/dir_chromedriver") if os.path.exists(dir_path): self.ut.log_message( "INFO", "chrome driver is already present. To update chromedriver please run `flexibox update --driver=chromedriver`" ) else: os.makedirs(dir_path) os_name = self.ot.os_name() arch_type = str(self.ot.os_architecture()) self.evaluate_on_environment(os_name, arch_type) # Update the required chromedriver based on the operating system type def update_driver(self): self.ut.check_directory_content( "/dependencies/dir_chromedriver/chromedriver") self.ut.log_message("INFO", "Deleting directory contents") self.ut.delete_dir_contents('dir_chromedriver/') os_name = self.ot.os_name() arch_type = str(self.ot.os_architecture()) self.evaluate_on_environment(os_name, arch_type) self.ut.log_message("INFO", "chromedriver updated")
class Phantomjs_driver(): def __init__(self): self.ut = Utility() self.ot = OS_type() self.log = Logger() # Get the required phsntomjs driver informations from the downloader_config.ini # Use the config_reader function from the Utility class to read the required configuration def phantomjsdriver_object(self): config_parser = self.ut.config_reader() api_url = config_parser.get('PhantomJSDriver', 'latest_browser_driver') return api_url # Get the required API data from the function phantomjsdriver_object def parse_phantomjsdriver_api(self): api_url = self.phantomjsdriver_object() api_data = self.ut.api_parser(api_url) return api_data # Get the required download url based on the information gathered using the # geckodriver_objects function def parse_apidata(self): api_url = {} raw_json = self.parse_phantomjsdriver_api() api_url = { "zip_ball": raw_json['zipball_url'], "tar_ball": raw_json['tarball_url'] } return api_url # Download the required phantomjsdriver binary based on the operating system type def evaluate_on_environment(self, os_name): download_url = self.parse_apidata() dir_path = self.ut.get_driver_path('/dependencies/dir_phantomjsdriver') if os_name == 'macos': self.log.log_info("Environment: " + os_name) self.log.log_info( "Downloading the required binary for phantomjsdriver") self.ut.driver_downloader(download_url['zip_ball'], dir_path) self.log.log_info("Download completed") self.ut.unzip_file('dir_phantomjsdriver/') self.log.log_info("Unarchiving contents completed") self.ut.rename_dir('dir_phantomjsdriver/') if os_name == 'linux': self.log.log_info("Environment: " + os_name) self.log.log_info( "Downloading the required binary for phantomjsdriver") self.ut.driver_downloader(download_url['tar_ball'], dir_path) self.log.log_info("Download completed") self.ut.untar_file('dir_phantomjsdriver/') self.log.log_message("Unarchiving contents completed") self.ut.rename_dir('dir_phantomjsdriver/') # Create a required directory separately for phantomjs and called the evaluate_on_environment # function to download the required binary def download_driver(self): dir_path = self.ut.get_driver_path('/dependencies/dir_phantomjsdriver') if os.path.exists(dir_path): self.log.log_info( "phantomjs driver is already present. To update phantomjsdriver please run `flexibox update --driver=phantomjsdriver`" ) else: os.makedirs(dir_path) os_name = self.ot.os_name() self.evaluate_on_environment(os_name) # Update the required phantomjsdriver based on the operating system type def update_driver(self): self.log.log_info("Deleting directory contents") self.ut.check_directory_content('/dependencies/dir_phantomjsdriver') self.ut.delete_dir_contents('dir_phantomjsdriver/') os_name = self.ot.os_name() self.evaluate_on_environment(os_name) self.log.log_info("phantomjs driver updated")
class Operadriver(object): def __init__(self): self.ut = Utility() self.ot = OS_type() self.log = Logger() # Get the required chromedriver informations from the downloader_config.ini # Use the config_reader function from the Utility class to read the required configuration def operadriver_object(self): config_parser = self.ut.config_reader() api_url = config_parser.get('OperaDriver', 'latest_browser_driver') return api_url # build the required download url based on the information gathered using the # operadriver_objects function def parse_operadriver_api(self): api_url = self.operadriver_object() browser_api_url = self.ut.get_api_data(api_url) return browser_api_url # Download the required chromedriver binary based on the operating system type def evaluate_on_environment(self, os_name, arch_type): dir_path = self.ut.get_driver_path('/dependencies/dir_operadriver') if os_name == 'macos' and arch_type == '64': self.log.log_info("Environment: " + os_name) self.log.log_info("Architecture Type: " + arch_type) url_builder_mac = self.parse_operadriver_api() self.log.log_info( "Downloading the required binary for operadriver") self.ut.driver_downloader(url_builder_mac['mac'], dir_path) self.log.log_info("Download completed") self.ut.unzip_file('dir_operadriver/') self.log.log_info("Unarchiving contents completed") if os_name == 'linux' and arch_type == '64': self.log.log_info("Environment: " + os_name) self.log.log_info("Architecture Type: " + arch_type) url_builder_linux = self.parse_operadriver_api() self.log.log_info( "Downloading the required binary for operadriver") self.ut.driver_downloader(url_builder_linux['linux'], dir_path) self.log.log_info("Download completed") self.ut.unzip_file('dir_operadriver/') self.log.log_info("Unarchiving contents completed") # Create a required directory separately for Opera and called the evaluate_on_environment # function to download the required binary def download_driver(self): dir_path = self.ut.get_driver_path('/dependencies/dir_operadriver') if os.path.exists(dir_path): self.log.log_info( "Opera driver is already present. To update operadriver please run `flexibox update " "--driver=operadriver`") else: os.makedirs(dir_path) os_name = self.ot.os_name() arch_type = str(self.ot.os_architecture()) self.evaluate_on_environment(os_name, arch_type) # Delete the previous downloaded driver and download a fresh pair of driver def update_driver(self): self.log.log_info("Deleting directory contents") self.ut.check_directory_content("/dependencies/dir_operadriver") self.ut.delete_dir_contents('dir_operadriver/') os_name = self.ot.os_name() arch_type = str(self.ot.os_architecture()) self.evaluate_on_environment(os_name, arch_type) self.log.log_info("Operadriver updated")