<commit_before>import os
from contextlib import contextmanager

from fabric.context_managers import cd, settings
from fabric.decorators import task
from fabric.operations import prompt
from fabric.state import env
from fabric.utils import indent

from refabric.api import run, info
from refabric.context_managers import sudo, shell_env
from refabric.contrib import blueprints, debian

from . import git
from . import user
from . import virtualenv

blueprint = blueprints.get(__name__)

project_home = lambda: os.path.join(app_root(), blueprint.get('project'))
app_root = lambda: blueprint.get('root_path') or '/srv/app'
source_path = lambda: os.path.join(project_home(), 'src')
virtualenv_path = lambda: os.path.join(project_home(), 'env')


@task
def manage(cmd=''):
    if not cmd:
        cmd = prompt('Enter django management command:')
    with sudo_project(), cd(git_path()), virtualenv.activate(virtualenv_path()), shell_env():
        run('python manage.py {cmd}'.format(cmd=cmd))


@task
def setup():
    install()
    upgrade()
    manage('syncdb')


def install():
    with sudo():
        # Create global paths
        root_path = app_root()
        debian.mkdir(root_path)

        # Create project user
        install_project_user()

        # Create static paths
        project_name = blueprint.get('project')
        static_base = os.path.join('/srv/www/', project_name)
        static_path = os.path.join(static_base, 'static')
        media_path = os.path.join(static_base, 'media')
        debian.mkdir(static_path, group='www-data')
        debian.chmod(static_path, mode=1775)
        debian.mkdir(media_path, group='www-data')
        debian.chmod(media_path, mode=1775)

        # Install system-dependencies
        install_system_dependencies()

        # Clone repository
        install_git()

        # Create virtualenv
        install_virtualenv()


@task
def upgrade():
    # Reset git repo
    update_git()

    # Install repo requirements.txt
    install_requirements()

    # Update uwsgi-configuration
    upload_deamon_conf()


@task
def upload_deamon_conf():
    from blues import uwsgi
    updates = []

    with sudo_project():
        default_templates = uwsgi.blueprint.get_default_template_root()
        destination = os.path.join(project_home(), 'uwsgi.d')

        with settings(template_dirs=[default_templates]):
            wsgi_deamon = blueprint.get('wsgi.deamon')
            if wsgi_deamon == 'uwsgi':
                context = get_uwsgi_wsgi_context()<commit_msg>Ensure uwsgi.d dir gets created<commit_after>import os
from contextlib import contextmanager

from fabric.context_managers import cd, settings
from fabric.decorators import task
from fabric.operations import prompt
from fabric.state import env
from fabric.utils import indent

from refabric.api import run, info
from refabric.context_managers import sudo, shell_env
from refabric.contrib import blueprints, debian

from . import git
from . import user
from . import virtualenv

blueprint = blueprints.get(__name__)

project_home = lambda: os.path.join(app_root(), blueprint.get('project'))
app_root = lambda: blueprint.get('root_path') or '/srv/app'
source_path = lambda: os.path.join(project_home(), 'src')
virtualenv_path = lambda: os.path.join(project_home(), 'env')


@task
def manage(cmd=''):
    if not cmd:
        cmd = prompt('Enter django management command:')
    with sudo_project(), cd(git_path()), virtualenv.activate(virtualenv_path()), shell_env():
        run('python manage.py {cmd}'.format(cmd=cmd))


@task
def setup():
    install()
    upgrade()
    manage('syncdb')


def install():
    with sudo():
        # Create global paths
        root_path = app_root()
        debian.mkdir(root_path)

        # Create project user
        install_project_user()

        # Create static paths
        project_name = blueprint.get('project')
        static_base = os.path.join('/srv/www/', project_name)
        static_path = os.path.join(static_base, 'static')
        media_path = os.path.join(static_base, 'media')
        debian.mkdir(static_path, group='www-data')
        debian.chmod(static_path, mode=1775)
        debian.mkdir(media_path, group='www-data')
        debian.chmod(media_path, mode=1775)

        # Install system-dependencies
        install_system_dependencies()

        # Clone repository
        install_git()

        # Create virtualenv
        install_virtualenv()


@task
def upgrade():
    # Reset git repo
    update_git()

    # Install repo requirements.txt
    install_requirements()

    # Update uwsgi-configuration
    upload_deamon_conf()


@task
def upload_deamon_conf():
    from blues import uwsgi
    updates = []

    with sudo_project():
        default_templates = uwsgi.blueprint.get_default_template_root()
        destination = os.path.join(project_home(), 'uwsgi.d')
        debian.mkdir(destination)

        with settings(template_dirs=[default_templates]):
            wsgi_deamon = blueprint.get('wsgi.deamon')
            if wsgi_deamon == 'uwsgi':
                context = get_uwsgi_wsgi_context()
{'fraction_non_alphanumeric': 0.10731132075471699, 'fraction_numerical': 0.0031446540880503146, 'mean_word_length': 3.305414551607445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '1724388', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1496, 'n_words': 360}