def gunicorn_process_ensure(path, template, config, key_env, venv_path='.venv'): with virtualenv(path, venv_path): python_package_ensure('gunicorn') run("cp %s %s" % (template, config)) file_update(config, lambda x: text_template(x,key_env)) dir_ensure('%s/logs' % path) dir_ensure('%s/run' % path)
def solr_ensure(project_path, venv_path='.venv'): with mode_sudo(): package_ensure('openjdk-7-jdk libxml2-dev libxslt1-dev python-dev') dir_ensure('/usr/java') file_link('/usr/lib/jvm/java-7-openjdk-amd64', '/usr/java/default') package_ensure('solr-tomcat') with virtualenv(project_path, venv_path): python_package_ensure('pysolr lxml cssselect')
def postgresql_ensure(name, username, path, db_password, venv_path='.venv'): package_ensure('postgresql postgresql-contrib libpq-dev') with virtualenv(path, venv_path): python_package_ensure('psycopg2') postgresql_role_ensure(username, db_password, createdb=True) postgresql_database_ensure(name, owner=username, locale='en_US.utf8', template='template0', encoding='UTF8')
def django_cache_ensure(project_path, project_name, schedule, venv_path='.venv'): script = "%s/bin/python %s/manage.py rebuild_index --noinput" % ( os.path.join(project_path, venv_path), project_path) cron_name = "%s-cache" % project_name crontab_ensure(schedule, script, cron_name, root=True) with virtualenv(project_path, venv_path): run('python manage.py clear_cache')
def django_database_push(project_path, db_name, db_username, db_password, config_template_path, config_path): """ Recreate and load local database to remote host""" local("python manage.py dumpdata > /tmp/db.json") with cd(project_path): put('/tmp/db.json', '/tmp/db.json') if postgresql_database_check(db_name): postgresql_database_drop(db_name) django_config_ensure(project_path, config_template_path, config_path) postgresql_ensure(db_name, db_username, project_path, db_password) django_database_ensure(project_path) with virtualenv(project_path): run("python manage.py loaddata /tmp/db.json")
def django_database_pull(project_path, venv_path='.venv'): """ Download database dump to /tmp/db.json """ with virtualenv(project_path, venv_path): run("python manage.py dumpdata --natural -e sessions -e admin -e contenttypes -e auth.Permission > /tmp/db.json" ) get('/tmp/db.json', '/tmp/db.json')
def django_search_ensure(project_path, venv_path='.venv'): with virtualenv(project_path, venv_path): run("python manage.py build_solr_schema > schema.xml") sudo("mv schema.xml /etc/solr/conf/") sudo("service tomcat6 restart") sudo('python manage.py rebuild_index --noinput')
def django_database_ensure(project_path, venv_path='.venv', migration=''): with virtualenv(project_path, venv_path): run("python manage.py migrate %s" % migration)
def django_static_ensure(project_path, venv_path='.venv'): with virtualenv(project_path, venv_path): run("python manage.py collectstatic --noinput")
def django_create_superuser(project_path, venv_path='.venv'): with virtualenv(project_path, venv_path): run('python manage.py createsuperuser')