<commit_before>from uuid import uuid4

from fabric.api import execute, hide, get, run, parallel, settings
from logger import logger

from perfrunner.helpers import Helper


def all_hosts(task):
    def wrapper(*args, **kargs):
        self = args[0]
        with hide('output', 'running'):
            with settings(user=self.ssh_username, password=self.ssh_password):
                return execute(parallel(task), *args, hosts=self.hosts, **kargs)
    return wrapper


def single_host(task):
    def wrapper(*args, **kargs):
        self = args[0]
        with hide('output', 'running'):
            with settings(host_string=self.hosts[0],
                          user=self.ssh_username, password=self.ssh_password):
                return task(*args, **kargs)
    return wrapper


class RemoteHelper(Helper):

    ARCH = {'i686': 'x86', 'i386': 'x86', 'x86_64': 'x86_64'}

    def wget(self, url, outdir='/tmp'):
        logger.info('Fetching {0}'.format(url))
        run('wget -nc "{0}" -P {1}'.format(url, outdir))

    @single_host
    def detect_pkg(self):
        logger.info('Detecting package manager')
        dist = run('python -c "import platform; print platform.dist()[0]"')
        if dist in ('Ubuntu', 'Debian'):
            return 'deb'
        else:
            return 'rpm'

    @single_host
    def detect_arch(self):
        logger.info('Detecting platform architecture')
        arch = run('arch')
        return self.ARCH[arch]

    @all_hosts
    def reset_swap(self):
        logger.info('Resetting swap')
        run('swapoff --all && swapon --all')

    @all_hosts
    def drop_caches(self):
        logger.info('Dropping memory cache')
        run('sync && echo 3 > /proc/sys/vm/drop_caches')

    @all_hosts
    def collect_info(self):
        logger.info('Running cbcollect_info')
        fname = uuid4().hex
        run('/opt/couchbase/bin/cbcollect_info /tmp/{0}'.format(fname))
        get('/tmp/{0}.zip'.format(fname))
        run('rm -f /tmp/{0}.zip'.format(fname))<commit_msg>fix name of diags archive<commit_after>from uuid import uuid4

from fabric.api import execute, hide, get, run, parallel, settings
from logger import logger

from perfrunner.helpers import Helper


def all_hosts(task):
    def wrapper(*args, **kargs):
        self = args[0]
        with hide('output', 'running'):
            with settings(user=self.ssh_username, password=self.ssh_password):
                return execute(parallel(task), *args, hosts=self.hosts, **kargs)
    return wrapper


def single_host(task):
    def wrapper(*args, **kargs):
        self = args[0]
        with hide('output', 'running'):
            with settings(host_string=self.hosts[0],
                          user=self.ssh_username, password=self.ssh_password):
                return task(*args, **kargs)
    return wrapper


class RemoteHelper(Helper):

    ARCH = {'i686': 'x86', 'i386': 'x86', 'x86_64': 'x86_64'}

    def wget(self, url, outdir='/tmp'):
        logger.info('Fetching {0}'.format(url))
        run('wget -nc "{0}" -P {1}'.format(url, outdir))

    @single_host
    def detect_pkg(self):
        logger.info('Detecting package manager')
        dist = run('python -c "import platform; print platform.dist()[0]"')
        if dist in ('Ubuntu', 'Debian'):
            return 'deb'
        else:
            return 'rpm'

    @single_host
    def detect_arch(self):
        logger.info('Detecting platform architecture')
        arch = run('arch')
        return self.ARCH[arch]

    @all_hosts
    def reset_swap(self):
        logger.info('Resetting swap')
        run('swapoff --all && swapon --all')

    @all_hosts
    def drop_caches(self):
        logger.info('Dropping memory cache')
        run('sync && echo 3 > /proc/sys/vm/drop_caches')

    @all_hosts
    def collect_info(self):
        logger.info('Running cbcollect_info')
        fname = '/tmp/{0}.zip'.format(uuid4().hex)
        run('/opt/couchbase/bin/cbcollect_info {0}'.format(fname))
        get('{0}'.format(fname))
        run('rm -f {0}'.format(fname))
{'fraction_non_alphanumeric': 0.1458230350963915, 'fraction_numerical': 0.015570934256055362, 'mean_word_length': 2.5973333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2201764', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1255, 'n_words': 295}