Пример #1
0
class Geckodriver(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 geckodriver_object(self):
        config_parser = self.ut.config_reader()
        api_url = config_parser.get('GeckoDriver', 'latest_browser_driver')
        return api_url

    # build the required download url based on the information gathered using the
    # geckodriver_objects function

    def parse_geckodriver_api(self):
        api_url = self.geckodriver_object()
        browser_api_url = self.ut.get_api_data(api_url)
        return browser_api_url

    # Download the required geckodriver 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_geckodriver')
        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_geckodriver_api()
            self.log.log_info("Downloading the required binary for geckodriver")
            self.ut.driver_downloader(url_builder_mac['mac'], dir_path)
            self.log.log_info("Download completed")
            self.ut.untar_file('dir_geckodriver/')
            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_geckodriver_api()
            self.log.log_info("Downloading the required binary for geckodriver")
            self.ut.driver_downloader(url_builder_linux['linux'], dir_path)
            self.log.log_info("Download completed")
            self.ut.untar_file('dir_geckodriver/')
            self.log.log_info("Unarchiving contents completed")
        if os_name == 'linux' and arch_type == '32':
            self.log.log_info("Environment: " + os_name)
            self.log.log_info("Architecture Type: " + arch_type)
            url_builder_linux = self.parse_geckodriver_api()
            self.log.log_info("Downloading the required binary for geckodriver")
            self.ut.driver_downloader(url_builder_linux['linux'], dir_path)
            self.log.log_info("Download completed")
            self.ut.untar_file('dir_geckodriver/')
            self.log.log_info("Unarchiving contents completed")

    # Create a required directory separately for gecko 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_geckodriver')
        if os.path.exists(dir_path):
            self.log.log_info(
                "gecko driver is already present. To update gecko driver please run `flexibox update "
                "--driver=geckodriver`"
            )
        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 geckodriver based on the operating system type

    def update_driver(self):
        self.log.log_info("Deleting directory contents")
        self.ut.check_directory_content("/dependencies/dir_geckodriver/geckodriver")
        self.ut.delete_dir_contents('dir_geckodriver/')
        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("geckodriver updated")
Пример #2
0
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")