<commit_before>""" Functions for fcomm-ctl """
import decorator
import os
import sys

# Local imports
import config
import colors as c
import utils


# load the fedoracommunity config
ctl_config = config.load_config()

# Add moksha's src dir to the path so we can import it
sys.path.insert(0, ctl_config['moksha-src-dir'])

# Import moksha from its source directory
import moksha.ctl.core.ctl as moksha_ctl

# Override moksha config with fedoracommunity config
moksha_ctl.ctl_config.update(ctl_config)

PRETTY_PREFIX = "[ " + c.magenta("fcomm-ctl") + " ] "


@decorator.decorator
def _with_virtualenv(func, *args, **kwargs):
    import virtualenvcontext
    with virtualenvcontext.VirtualenvContext(ctl_config['venv']):
        return func(*args, **kwargs)


@decorator.decorator
def _in_srcdir(func, *args, **kwargs):
    with utils.DirectoryContext(ctl_config['fcomm-src-dir']):
        return func(*args, **kwargs)

@decorator.decorator
def _with_moksha_faked(func, *args, **kwargs):
    ret = True

    # Do what moksha do, but don't change directory
    moksha_ctl.ctl_config['moksha-src-dir'] = ctl_config['fcomm-src-dir']

    # Call the function by name
    ret = getattr(moksha_ctl, func.__name__)(*args, **kwargs)

    moksha_ctl.ctl_config['moksha-src-dir'] = ctl_config['moksha-src-dir']

    # Go on with our fcomm business
    return func(*args, **kwargs) and ret

@decorator.decorator
def _with_moksha_first(func, *args, **kwargs):
    ret = True

    with utils.DirectoryContext(ctl_config['moksha-src-dir']):
        # Call the function by name
        ret = getattr(moksha_ctl, func.__name__)(*args, **kwargs)

    # Go on with our fcomm business
    return func(*args, **kwargs) and ret

@decorator.decorator
def _reporter(func, *args, **kwargs):
    PRETTY_PREFIX = "[ " + c.magenta("fcomm-ctl") + " ] "
    descriptor = ":".join([func.__name__] + [a for a in args if a])
    print PRETTY_PREFIX, "Running:", descriptor
    output = None
    try:
        output = func(*args, **kwargs)
        if not output:
            raise Exception
        print PRETTY_PREFIX, "[ " + c.green('OK') + " ]", descriptor
    except Exception:
        print PRETTY_PREFIX, "[ " + c.red('FAIL') + " ]", descriptor
    return output


@_reporter
@_with_moksha_first
def bootstrap():
    """ Should only be run once. First-time moksha setup. """
    ret = True
    if os.path.exists('/etc/redhat-release'):
        reqs = [
            'python-kitchen', 'python-fedora', 'python-bugzilla', 'koji',
            'xapian-bindings-python',
        ]
        ret = ret and not os.system(
            'sudo yum install -q -y ' + ' '.join(reqs))

    print PRETTY_PREFIX, "Scratch that."
    print "Really, run './fcomm-ctl.py rebuild' to continue."
    return ret


@_reporter
@_with_moksha_first
def rebuild():
    """ Completely destroy and rebuild the virtualenv. """
    return install_hacks() and link_external_libs() and develop() and download_db_snapshot()


@_reporter
def download_db_snapshot():
    """ Download a snapshot of our xapian database """
    os.system('wget -N http://johnp.fedorapeople.org/downloads/xapian/xapian.tar.xz')
    os.system('tar xvf xapian.tar.xz')
    return True


@_reporter
@_with_moksha_first
@_with_virtualenv<commit_msg>Pull in the latest xapian db snapshot<commit_after>""" Functions for fcomm-ctl """
import decorator
import os
import sys

# Local imports
import config
import colors as c
import utils


# load the fedoracommunity config
ctl_config = config.load_config()

# Add moksha's src dir to the path so we can import it
sys.path.insert(0, ctl_config['moksha-src-dir'])

# Import moksha from its source directory
import moksha.ctl.core.ctl as moksha_ctl

# Override moksha config with fedoracommunity config
moksha_ctl.ctl_config.update(ctl_config)

PRETTY_PREFIX = "[ " + c.magenta("fcomm-ctl") + " ] "


@decorator.decorator
def _with_virtualenv(func, *args, **kwargs):
    import virtualenvcontext
    with virtualenvcontext.VirtualenvContext(ctl_config['venv']):
        return func(*args, **kwargs)


@decorator.decorator
def _in_srcdir(func, *args, **kwargs):
    with utils.DirectoryContext(ctl_config['fcomm-src-dir']):
        return func(*args, **kwargs)

@decorator.decorator
def _with_moksha_faked(func, *args, **kwargs):
    ret = True

    # Do what moksha do, but don't change directory
    moksha_ctl.ctl_config['moksha-src-dir'] = ctl_config['fcomm-src-dir']

    # Call the function by name
    ret = getattr(moksha_ctl, func.__name__)(*args, **kwargs)

    moksha_ctl.ctl_config['moksha-src-dir'] = ctl_config['moksha-src-dir']

    # Go on with our fcomm business
    return func(*args, **kwargs) and ret

@decorator.decorator
def _with_moksha_first(func, *args, **kwargs):
    ret = True

    with utils.DirectoryContext(ctl_config['moksha-src-dir']):
        # Call the function by name
        ret = getattr(moksha_ctl, func.__name__)(*args, **kwargs)

    # Go on with our fcomm business
    return func(*args, **kwargs) and ret

@decorator.decorator
def _reporter(func, *args, **kwargs):
    PRETTY_PREFIX = "[ " + c.magenta("fcomm-ctl") + " ] "
    descriptor = ":".join([func.__name__] + [a for a in args if a])
    print PRETTY_PREFIX, "Running:", descriptor
    output = None
    try:
        output = func(*args, **kwargs)
        if not output:
            raise Exception
        print PRETTY_PREFIX, "[ " + c.green('OK') + " ]", descriptor
    except Exception:
        print PRETTY_PREFIX, "[ " + c.red('FAIL') + " ]", descriptor
    return output


@_reporter
@_with_moksha_first
def bootstrap():
    """ Should only be run once. First-time moksha setup. """
    ret = True
    if os.path.exists('/etc/redhat-release'):
        reqs = [
            'python-kitchen', 'python-fedora', 'python-bugzilla', 'koji',
            'xapian-bindings-python',
        ]
        ret = ret and not os.system(
            'sudo yum install -q -y ' + ' '.join(reqs))

    print PRETTY_PREFIX, "Scratch that."
    print "Really, run './fcomm-ctl.py rebuild' to continue."
    return ret


@_reporter
@_with_moksha_first
def rebuild():
    """ Completely destroy and rebuild the virtualenv. """
    return install_hacks() and link_external_libs() and develop() and download_db_snapshot()


@_reporter
def download_db_snapshot():
    """ Download a snapshot of our xapian database """
    os.system('wget -N http://johnp.fedorapeople.org/downloads/xapian/xapian-LATEST.tar.xz')
    os.system('tar xvf xapian-LATEST.tar.xz')
    return True


@_reporter
@_with_moksha_first
@_with_virtualenv
{'fraction_non_alphanumeric': 0.12847116264876413, 'fraction_numerical': 0.0003051571559353067, 'mean_word_length': 3.511355815554026, 'pattern_counts': {'":': 2, '<': 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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5771530', 'n_tokens_mistral': 2248, 'n_tokens_neox': 2210, 'n_words': 559}