<commit_before>from collections import namedtuple
from optparse import OptionParser
from urlparse import urlparse

import requests
from logger import logger
from requests.exceptions import ConnectionError

from perfrunner.helpers.remote import RemoteHelper
from perfrunner.settings import ClusterSpec

LOCATIONS = (
    'http://latestbuilds.hq.couchbase.com/',
    'http://latestbuilds.hq.couchbase.com/couchbase-server/sherlock/{build}/',
    'http://172.23.120.24/builds/latestbuilds/couchbase-server/watson/{build}/',
    'http://172.23.120.24/builds/latestbuilds/couchbase-server/spock/{build}/',
)

Build = namedtuple(
    'Build',
    ['arch', 'pkg', 'edition', 'version', 'release', 'build', 'url']
)


class CouchbaseInstaller(object):

    def __init__(self, cluster_spec, options):
        self.options = options
        self.remote = RemoteHelper(cluster_spec, None, options.verbose)
        self.cluster_spec = cluster_spec

        arch = self.remote.detect_arch()
        pkg = self.remote.detect_pkg()

        release = None
        build = None
        if options.version:
            release, build = options.version.split('-')

        self.build = Build(arch, pkg, options.cluster_edition, options.version,
                           release, build, options.url)
        logger.info('Target build info: {}'.format(self.build))

    def get_expected_filenames(self):
        if self.build.pkg == 'rpm':
            os_release = self.remote.detect_os_release()
            patterns = (
                'couchbase-server-{{edition}}-{{version}}-centos{}.{{arch}}.{{pkg}}'.format(os_release),
                'couchbase-server-{edition}_centos6_{arch}_{version}-rel.{pkg}',
            )
        elif self.build.pkg == 'deb':
            patterns = (
                'couchbase-server-{edition}_{arch}_{version}-rel.{pkg}',
                'couchbase-server-{edition}_{version}-ubuntu12.04_{arch}.{pkg}',
            )
        elif self.build.pkg == 'exe':
            patterns = (
                'couchbase-server-{edition}_{arch}_{version}-rel.setup.{pkg}',
                'couchbase-server-{edition}_{version}-windows_{arch}.{pkg}',
            )
        else:
            patterns = ()  # Sentinel

        for pattern in patterns:
            yield pattern.format(**self.build.__dict__)

    @staticmethod
    def is_exist(url):
        try:
            status_code = requests.head(url).status_code
        except ConnectionError:
            return False
        if status_code == 200:
            return True
        return False

    def find_package(self):<commit_msg>Support installation of 3.1.x builds on Windows<commit_after>from collections import namedtuple
from optparse import OptionParser
from urlparse import urlparse

import requests
from logger import logger
from requests.exceptions import ConnectionError

from perfrunner.helpers.remote import RemoteHelper
from perfrunner.settings import ClusterSpec

LOCATIONS = (
    'http://latestbuilds.hq.couchbase.com/',
    'http://latestbuilds.hq.couchbase.com/couchbase-server/sherlock/{build}/',
    'http://172.23.120.24/builds/latestbuilds/couchbase-server/watson/{build}/',
    'http://172.23.120.24/builds/latestbuilds/couchbase-server/spock/{build}/',
)

Build = namedtuple(
    'Build',
    ['arch', 'pkg', 'edition', 'version', 'release', 'build', 'url']
)


class CouchbaseInstaller(object):

    def __init__(self, cluster_spec, options):
        self.options = options
        self.remote = RemoteHelper(cluster_spec, None, options.verbose)
        self.cluster_spec = cluster_spec

        arch = self.remote.detect_arch()
        pkg = self.remote.detect_pkg()

        release = None
        build = None
        if options.version:
            release, build = options.version.split('-')

        self.build = Build(arch, pkg, options.cluster_edition, options.version,
                           release, build, options.url)
        logger.info('Target build info: {}'.format(self.build))

    def get_expected_filenames(self):
        if self.build.pkg == 'rpm':
            os_release = self.remote.detect_os_release()
            patterns = (
                'couchbase-server-{{edition}}-{{version}}-centos{}.{{arch}}.{{pkg}}'.format(os_release),
                'couchbase-server-{edition}_centos6_{arch}_{version}-rel.{pkg}',
            )
        elif self.build.pkg == 'deb':
            patterns = (
                'couchbase-server-{edition}_{arch}_{version}-rel.{pkg}',
                'couchbase-server-{edition}_{version}-ubuntu12.04_{arch}.{pkg}',
            )
        elif self.build.pkg == 'exe':
            patterns = (
                'couchbase-server-{edition}_{arch}_{version}-rel.setup.{pkg}',
                'couchbase-server-{edition}_{version}-windows_{arch}.{pkg}',
                'couchbase_server-{edition}-windows-{arch}-{version}.{pkg}',
            )
        else:
            patterns = ()  # Sentinel

        for pattern in patterns:
            yield pattern.format(**self.build.__dict__)

    @staticmethod
    def is_exist(url):
        try:
            status_code = requests.head(url).status_code
        except ConnectionError:
            return False
        if status_code == 200:
            return True
        return False

    def find_package(self):
{'fraction_non_alphanumeric': 0.13242784380305603, 'fraction_numerical': 0.010941331824184115, 'mean_word_length': 2.4184397163120566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '4909604', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1525, 'n_words': 274}