<commit_before>from fabric.api import run, sudo, env
from fabric.context_managers import prefix, settings, cd, hide
from fabric.operations import prompt
import fabric.colors as c
import decorator

VENV = 'moksha'

SRC_DIR_KEY = 'moksha_source_location'
if not SRC_DIR_KEY in env:
    prompt('Enter ' + SRC_DIR_KEY + ' (can be specified in ~/.fabricrc):',
           key=SRC_DIR_KEY)

SRC_DIR = env[SRC_DIR_KEY]

APPS_DIR = 'moksha/apps'
pid_files = ['paster.pid', 'orbited.pid', 'moksha-hub.pid']

def _file_exists(fname):
    with settings(hide('warnings', 'running', 'stdout', 'stderr'),
                  warn_only=True):
        return 'No such file' not in run('ls {fname}'.format(fname=fname))

def _with_virtualenv(func, *args, **kwargs):
    with prefix('workon {venv}'.format(venv=VENV)):
        return func(*args, **kwargs)

def _in_srcdir(func, *args, **kwargs):
    with cd(SRC_DIR):
        return func(*args, **kwargs)

def _reporter(func, *args, **kwargs):
    print "[moksha fabric]  Running", func.__name__, "with",
    print "args:", c.cyan(str(args)) + " and kw:" + c.cyan(str(kwargs))
    try:
        output = func(*args, **kwargs)
    except Exception:
        print "[moksha fabric] [ " + c.red('FAIL') + " ]", func.__name__
        raise
    print "[moksha fabric] [  " + c.green('OK') + "  ]", func.__name__
    return output

def _warn_only(func, *args, **kwargs):
    with settings(hide('warnings', 'running', 'stdout', 'stderr'),
                  warn_only=True):
        return func(*args, **kwargs)

_with_virtualenv = decorator.decorator(_with_virtualenv)
_in_srcdir = decorator.decorator(_in_srcdir)
_reporter = decorator.decorator(_reporter)
_warn_only = decorator.decorator(_warn_only)

def _use_yum():
    with settings(hide('warnings', 'running', 'stdout', 'stderr'),
                  warn_only=True):
        return bool(run('cat /etc/redhat-release'))

@_reporter
def bootstrap():
    """ Should only be run once.  First-time moksha setup. """
    if _use_yum():
        reqs = [
            'python-setuptools', 'python-qpid', 'qpid-cpp-server',
            'orbited', 'multitail',
        ]

        sudo('yum install -q -y ' + ' '.join(reqs) )
    else:
        # No orbited or qpid on ubuntu as far as I can tell
        # TODO -- how should we work this?
        sudo('apt-get install -y python-setuptools')

    sudo('easy_install -q pip')
    sudo('pip -q install virtualenv')
    sudo('pip -q install virtualenvwrapper')
    
    shellrc_lookup = {
        # TODO -- add other shells (zsh) here if need be
        '/bin/bash -l -c' : '~/.bashrc',
    }
    shellrc = shellrc_lookup[env['shell']]
    shellrc_snippet = """ "
# virtualenv stuff (put here by the moksha fabric bootstrap process)
export WORKON_HOME=$HOME/.virtualenvs;
source /usr/bin/virtualenvwrapper.sh;
" """
    cmd="grep {test} {shellrc} || echo {payload} >> {shellrc}".format(
        test="virtualenvwrapper.sh", payload=shellrc_snippet, shellrc=shellrc)
    run(cmd)
    run('mkdir -p $WORKON_HOME')
    rebuild()

@_reporter
def rebuild():<commit_msg>Yum install pip and virtualenv<commit_after>from fabric.api import run, sudo, env
from fabric.context_managers import prefix, settings, cd, hide
from fabric.operations import prompt
import fabric.colors as c
import decorator

VENV = 'moksha'

SRC_DIR_KEY = 'moksha_source_location'
if not SRC_DIR_KEY in env:
    prompt('Enter ' + SRC_DIR_KEY + ' (can be specified in ~/.fabricrc):',
           key=SRC_DIR_KEY)

SRC_DIR = env[SRC_DIR_KEY]

APPS_DIR = 'moksha/apps'
pid_files = ['paster.pid', 'orbited.pid', 'moksha-hub.pid']

def _file_exists(fname):
    with settings(hide('warnings', 'running', 'stdout', 'stderr'),
                  warn_only=True):
        return 'No such file' not in run('ls {fname}'.format(fname=fname))

def _with_virtualenv(func, *args, **kwargs):
    with prefix('workon {venv}'.format(venv=VENV)):
        return func(*args, **kwargs)

def _in_srcdir(func, *args, **kwargs):
    with cd(SRC_DIR):
        return func(*args, **kwargs)

def _reporter(func, *args, **kwargs):
    print "[moksha fabric]  Running", func.__name__, "with",
    print "args:", c.cyan(str(args)) + " and kw:" + c.cyan(str(kwargs))
    try:
        output = func(*args, **kwargs)
    except Exception:
        print "[moksha fabric] [ " + c.red('FAIL') + " ]", func.__name__
        raise
    print "[moksha fabric] [  " + c.green('OK') + "  ]", func.__name__
    return output

def _warn_only(func, *args, **kwargs):
    with settings(hide('warnings', 'running', 'stdout', 'stderr'),
                  warn_only=True):
        return func(*args, **kwargs)

_with_virtualenv = decorator.decorator(_with_virtualenv)
_in_srcdir = decorator.decorator(_in_srcdir)
_reporter = decorator.decorator(_reporter)
_warn_only = decorator.decorator(_warn_only)

def _use_yum():
    with settings(hide('warnings', 'running', 'stdout', 'stderr'),
                  warn_only=True):
        return bool(run('cat /etc/redhat-release'))

@_reporter
def bootstrap():
    """ Should only be run once.  First-time moksha setup. """
    if _use_yum():
        reqs = [
            'python-setuptools', 'python-qpid', 'qpid-cpp-server',
            'orbited', 'multitail', 'python-pip', 'python-virtualenv',
        ]

        sudo('yum install -q -y ' + ' '.join(reqs) )
    else:
        # No orbited or qpid on ubuntu as far as I can tell
        # TODO -- how should we work this?
        sudo('apt-get install -y python-setuptools')

    print 'installing the wrapper'
    sudo('pip -q install virtualenvwrapper')
    
    shellrc_lookup = {
        # TODO -- add other shells (zsh) here if need be
        '/bin/bash -l -c' : '~/.bashrc',
    }
    shellrc = shellrc_lookup[env['shell']]
    shellrc_snippet = """ "
# virtualenv stuff (put here by the moksha fabric bootstrap process)
export WORKON_HOME=$HOME/.virtualenvs;
source /usr/bin/virtualenvwrapper.sh;
" """
    cmd="grep {test} {shellrc} || echo {payload} >> {shellrc}".format(
        test="virtualenvwrapper.sh", payload=shellrc_snippet, shellrc=shellrc)
    run(cmd)
    run('mkdir -p $WORKON_HOME')
    rebuild()

@_reporter
def rebuild():
{'fraction_non_alphanumeric': 0.1486289144896966, 'fraction_numerical': 0.0, 'mean_word_length': 3.2451790633608817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3796389', 'n_tokens_mistral': 2114, 'n_tokens_neox': 2070, 'n_words': 514}