<commit_before># -*- coding: utf-8 -*-
'''
(c) Copyright 2014 Telefonica, I+D. Printed in Spain (Europe). All Rights
Reserved.

The copyright to the software program(s) is property of Telefonica I+D.
The program(s) may be used and or copied only with the express written
consent of Telefonica I+D or in accordance with the terms and conditions
stipulated in the agreement/contract under which the program(s) have
been supplied.
'''
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import logging.config
import ConfigParser


class SeleniumWrapper(object):
    # Singleton instance
    _instance = None

    def __new__(cls, *args, **kwargs):
        if not cls._instance:
            # Configure logger
            logging.config.fileConfig('conf/logging.conf')
            cls.logger = logging.getLogger(__name__)

            # Read properties file
            cls.config = ConfigParser.ConfigParser()
            cls.config.read('conf/properties.cfg')

            # Create new instance
            cls._instance = super(SeleniumWrapper, cls).__new__(cls, *args, **kwargs)
        return cls._instance

    def connect(self):
        """
        Set up the browser driver
        """
        if self.config.get('Server', 'enabled') == 'true':
            self._setup_remotedriver()
        else:
            self._setup_localdriver()

        return self.driver

    def _setup_remotedriver(self):
        """
        Setup webdriver in a remote server
        """
        self.logger.info("Creating remote driver (browser = {0})".format(self.config.get('Browser', 'browser')))

        server_host = self.config.get('Server', 'host')
        server_port = self.config.get('Server', 'port')
        server_url = 'http://{0}:{1}/wd/hub'.format(server_host, server_port)

        capabilities_list = {
                        'firefox': DesiredCapabilities.FIREFOX,
                        'chrome': DesiredCapabilities.CHROME,
                        'iexplore': DesiredCapabilities.INTERNETEXPLORER,
                        'phantomjs': DesiredCapabilities.PHANTOMJS,
                       }
        capabilities = capabilities_list.get(self.config.get('Browser', 'browser'))<commit_msg>Add version and platorm remote driver capabilities<commit_after># -*- coding: utf-8 -*-
'''
(c) Copyright 2014 Telefonica, I+D. Printed in Spain (Europe). All Rights
Reserved.

The copyright to the software program(s) is property of Telefonica I+D.
The program(s) may be used and or copied only with the express written
consent of Telefonica I+D or in accordance with the terms and conditions
stipulated in the agreement/contract under which the program(s) have
been supplied.
'''
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import logging.config
import ConfigParser


class SeleniumWrapper(object):
    # Singleton instance
    _instance = None

    def __new__(cls, *args, **kwargs):
        if not cls._instance:
            # Configure logger
            logging.config.fileConfig('conf/logging.conf')
            cls.logger = logging.getLogger(__name__)

            # Read properties file
            cls.config = ConfigParser.ConfigParser()
            cls.config.read('conf/properties.cfg')

            # Create new instance
            cls._instance = super(SeleniumWrapper, cls).__new__(cls, *args, **kwargs)
        return cls._instance

    def connect(self):
        """
        Set up the browser driver
        """
        if self.config.get('Server', 'enabled') == 'true':
            self._setup_remotedriver()
        else:
            self._setup_localdriver()

        return self.driver

    def _setup_remotedriver(self):
        """
        Setup webdriver in a remote server
        """
        browser = self.config.get('Browser', 'browser')
        self.logger.info("Creating remote driver (browser = {0})".format(browser))

        server_host = self.config.get('Server', 'host')
        server_port = self.config.get('Server', 'port')
        server_url = 'http://{0}:{1}/wd/hub'.format(server_host, server_port)

        # Get browser type capabilities
        capabilities_list = {
                             'firefox': DesiredCapabilities.FIREFOX,
                             'chrome': DesiredCapabilities.CHROME,
                             'iexplore': DesiredCapabilities.INTERNETEXPLORER,
                             'phantomjs': DesiredCapabilities.PHANTOMJS,
                            }
        browser_name = browser.split('-')[0]
        capabilities = capabilities_list.get(browser_name)

        # Add browser version
        try:
            capabilities.version = browser.split('-')[1]
        except:
            pass

        # Add platform capability
        try:
            platforms_list = {
                              'xp': 'XP',
                              'windows_7': 'VISTA',
                              'windows_8': 'WIN8',
                              'linux': 'LINUX',
                              'mac': 'MAC',
                             }
            capabilities.platform = platforms_list.get(browser.split('-')[3])
        except:
            pass

        # Create remote driver
{'fraction_non_alphanumeric': 0.10178165276724792, 'fraction_numerical': 0.004169825625473844, 'mean_word_length': 2.1022927689594355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2214355', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1367, 'n_words': 360}