<commit_before>from contextlib import contextmanager as _contextmanager
from fabric.api import cd, env, local, run, sudo, task, put, hide
from fabric.context_managers import prefix, settings
from fabric.contrib.files import append
from fabric.operations import prompt
import os, re, tempfile, time, copy
import subprocess, json

#from helpers.models_to_forms import jsmodels

env.use_ssh_config = True # ~/.ssh/config
env.use_sudo = True

env.local_project_root = os.path.dirname(__file__)
env.local_python_packages_dir = os.path.join(env.local_project_root, 'dist')
# SETTINGS
env.project = 'facegame'
env.deploy_group = 'Users' # deploy users must belong to this group
env.www_root = '/srv/www'
env.user = os.environ['USER']
env.owner = 'www-data'
env.release = '%s_%s' % (env.project, time.strftime('%Y%m%d%H%M%S'))
env.pkg = '/tmp/{release}.tar.gz'.format(**env)
env.apache_restart_command = 'service apache2 restart'
env.basepath = '{www_root}/{project}'.format(**env)
env.project_root = '{www_root}/{project}/www'.format(**env)
env.reldir = '{basepath}/releases/{release}/'.format(**env)
env.usedir = copy.deepcopy(env.reldir)
env.python_packages_dir = '{www_root}/{project}/dist'.format(**env)
env.virtualenv = '{www_root}/{project}/venv'.format(**env)
env.supervisor_conf_dir = '/etc/supervisor'
env.branch = 'fum5'

#
#
# TASKS
#
#

# supervisor_conf()
# supervisor_restart()

@task
def deploy():
    ask_sudo_password()

    dirs()

    tar_from_git()
    upload_tar()

    prepare_python_packages()
    synchronize_python_packages()
    install_python_packages()
    
    # anything that depends on requirements under here
    # jsurls need to be re-generated with production settings
    #jsmodels(apps=['common','contenttypes'], filename='static/js/gen/custom_form_tpl.js',)
    prepare_node_packages()
    prepare_assets()

    #manage('migrate --noinput')
    manage('syncdb --noinput')

    prepare_hidden_files()
    ownership()

    restart_apache()

@task
def ownership():
    sudo('chown -fR {owner} {basepath}/media'.format(**env))
    sudo('chown -fR {owner} {basepath}'.format(**env))
    with settings(hide('warnings',), warn_only=True):
        sudo('chown -fR {owner} {basepath}/sqlite.db'.format(**env))

@task
def dirs():
    sudo('mkdir -p {basepath} {basepath}/packages {basepath}/releases {basepath}/media {basepath}/dist {basepath}/static'.format(**env))

    # backups
    sudo('mkdir -p /srv/backup/postgres'.format(**env))
    sudo('chown -fR {owner} /srv/backup/postgres'.format(**env))

@task
def setup():
    ask_sudo_password()

    dirs()
    ownership()
    tar_from_git()
    upload_tar()

    prepare_python_packages()
    synchronize_python_packages()
    create_virtualenv()
    install_python_packages()

    prepare_node_packages()
    prepare_assets()
    prepare_hidden_files()

    restart_apache()

@task
def prepare_hidden_files():
    with settings(hide('warnings',), warn_only=True):
        sudo('cp {basepath}/secret_facegame_settings.py {project_root}/'.format(**env))
<commit_msg>secrets to under settings dir<commit_after>from contextlib import contextmanager as _contextmanager
from fabric.api import cd, env, local, run, sudo, task, put, hide
from fabric.context_managers import prefix, settings
from fabric.contrib.files import append
from fabric.operations import prompt
import os, re, tempfile, time, copy
import subprocess, json

#from helpers.models_to_forms import jsmodels

env.use_ssh_config = True # ~/.ssh/config
env.use_sudo = True

env.local_project_root = os.path.dirname(__file__)
env.local_python_packages_dir = os.path.join(env.local_project_root, 'dist')
# SETTINGS
env.project = 'facegame'
env.deploy_group = 'Users' # deploy users must belong to this group
env.www_root = '/srv/www'
env.user = os.environ['USER']
env.owner = 'www-data'
env.release = '%s_%s' % (env.project, time.strftime('%Y%m%d%H%M%S'))
env.pkg = '/tmp/{release}.tar.gz'.format(**env)
env.apache_restart_command = 'service apache2 restart'
env.basepath = '{www_root}/{project}'.format(**env)
env.project_root = '{www_root}/{project}/www'.format(**env)
env.reldir = '{basepath}/releases/{release}/'.format(**env)
env.usedir = copy.deepcopy(env.reldir)
env.python_packages_dir = '{www_root}/{project}/dist'.format(**env)
env.virtualenv = '{www_root}/{project}/venv'.format(**env)
env.supervisor_conf_dir = '/etc/supervisor'
env.branch = 'fum5'

#
#
# TASKS
#
#

# supervisor_conf()
# supervisor_restart()

@task
def deploy():
    ask_sudo_password()

    dirs()

    tar_from_git()
    upload_tar()

    prepare_python_packages()
    synchronize_python_packages()
    install_python_packages()
    
    # anything that depends on requirements under here
    # jsurls need to be re-generated with production settings
    #jsmodels(apps=['common','contenttypes'], filename='static/js/gen/custom_form_tpl.js',)
    prepare_node_packages()
    prepare_assets()

    #manage('migrate --noinput')
    manage('syncdb --noinput')

    prepare_hidden_files()
    ownership()

    restart_apache()

@task
def ownership():
    sudo('chown -fR {owner} {basepath}/media'.format(**env))
    sudo('chown -fR {owner} {basepath}'.format(**env))
    with settings(hide('warnings',), warn_only=True):
        sudo('chown -fR {owner} {basepath}/sqlite.db'.format(**env))

@task
def dirs():
    sudo('mkdir -p {basepath} {basepath}/packages {basepath}/releases {basepath}/media {basepath}/dist {basepath}/static'.format(**env))

    # backups
    sudo('mkdir -p /srv/backup/postgres'.format(**env))
    sudo('chown -fR {owner} /srv/backup/postgres'.format(**env))

@task
def setup():
    ask_sudo_password()

    dirs()
    ownership()
    tar_from_git()
    upload_tar()

    prepare_python_packages()
    synchronize_python_packages()
    create_virtualenv()
    install_python_packages()

    prepare_node_packages()
    prepare_assets()
    prepare_hidden_files()

    restart_apache()

@task
def prepare_hidden_files():
    with settings(hide('warnings',), warn_only=True):
        sudo('cp {basepath}/secret_facegame_settings.py {project_root}/facegame/settings/'.format(**env))

{'fraction_non_alphanumeric': 0.15155482815057283, 'fraction_numerical': 0.0006546644844517185, 'mean_word_length': 4.738028169014084, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 16, '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': '3977222', 'n_tokens_mistral': 2110, 'n_tokens_neox': 2024, 'n_words': 400}