<s> import json <EOL> from fabric . api import * <EOL> from . deployer . configuration import Configuration <EOL> from . deployer . helpers import mkdir , rmdir <EOL> from . deployer . standard_packages import package_list <EOL> import os <EOL> from StringIO import StringIO <EOL> site_settings = { <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : '<STR_LIT>' , <EOL> } <EOL> def load_configuration ( ) : <EOL> with open ( os . path . join ( os . path . dirname ( os . path . abspath ( __file__ ) ) , '<STR_LIT>' ) , '<STR_LIT:r>' ) as f : <EOL> configuration_file = '<STR_LIT>' . join ( f . readlines ( ) ) <EOL> conf = json . JSONDecoder ( ) . decode ( configuration_file ) <EOL> print "<STR_LIT>" . format ( conf [ '<STR_LIT>' ] ) <EOL> env . hosts . append ( conf [ '<STR_LIT>' ] ) <EOL> env . hosts_data = Configuration ( conf , site_settings ) <EOL> load_configuration ( ) <EOL> @ task <EOL> def install_requirements ( ) : <EOL> sudo ( '<STR_LIT>' ) <EOL> sudo ( '<STR_LIT>' ) <EOL> sudo ( '<STR_LIT>' . format ( package_list ( ) ) ) <EOL> @ task <EOL> def create_folders ( ) : <EOL> mkdir ( env . hosts_data . base_path ( ) ) <EOL> mkdir ( env . hosts_data . log_path ( ) ) <EOL> @ task <EOL> def create_virtual_environment ( ) : <EOL> with cd ( env . hosts_data . base_path ( ) ) : <EOL> run ( '<STR_LIT>' . format ( env . hosts_data . virtualenv_path ( ) ) ) <EOL> with prefix ( "<STR_LIT>" . format ( env . hosts_data . virtualenv_activate_path ( ) ) ) : <EOL> run ( '<STR_LIT>' ) <EOL> run ( '<STR_LIT>' . format ( env . hosts_data . requirements_path ( ) ) ) <EOL> if env . hosts_data . is_mysql ( ) : <EOL> run ( '<STR_LIT>' ) <EOL> run ( '<STR_LIT>' ) <EOL> @ task <EOL> def create_local_settings ( ) : <EOL> rmdir ( env . hosts_data . local_settings_path ( ) ) <EOL> put ( StringIO ( env . hosts_data . local_settings ( ) ) , env . hosts_data . local_settings_path ( ) ) <EOL> @ task <EOL> def create_gunicorn_config ( ) : <EOL> rmdir ( env . hosts_data . gunicorn_config_path ( ) ) <EOL> put ( StringIO ( env . hosts_data . gunicorn_config ( ) ) , env . hosts_data . gunicorn_config_path ( ) ) <EOL> sudo ( '<STR_LIT>' . format ( env . hosts_data . gunicorn_config_path ( ) ) ) <EOL> @ task <EOL> def create_demo_superuser ( ) : <EOL> with cd ( env . hosts_data . app_path ( ) ) : <EOL> with prefix ( "<STR_LIT>" . format ( env . hosts_data . virtualenv_activate_path ( ) ) ) : <EOL> commands = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> run ( '<STR_LIT:U+0020>' . join ( commands ) ) <EOL> @ task <EOL> def create_gunicorn_supervisor ( ) : <EOL> rmdir ( env . hosts_data . gunicorn_supervisor_config_path ( ) ) <EOL> put ( <EOL> StringIO ( env . hosts_data . gunicorn_supervisor_config ( ) ) , <EOL> env . hosts_data . gunicorn_supervisor_config_path ( ) , <EOL> use_sudo = True <EOL> ) <EOL> sudo ( '<STR_LIT>' ) <EOL> sudo ( '<STR_LIT>' ) <EOL> @ task <EOL> def create_celery_supervisor ( ) : <EOL> rmdir ( env . hosts_data . celery_supervisor_config_path ( ) ) <EOL> put ( <EOL> StringIO ( env . hosts_data . celery_supervisor_config ( ) ) , <EOL> env . hosts_data . celery_supervisor_config_path ( ) , <EOL> use_sudo = True <EOL> ) <EOL> sudo ( '<STR_LIT>' ) <EOL> sudo ( '<STR_LIT>' ) <EOL> @ task <EOL> def create_nginx_config ( ) : <EOL> put ( StringIO ( env . hosts_data . nginx_config ( ) ) , env . hosts_data . nginx_available_path ( ) , use_sudo = True ) <EOL> sudo ( '<STR_LIT>' . format ( env . hosts_data . nginx_available_path ( ) , env . hosts_data . nginx_enabled_path ( ) ) ) <EOL> sudo ( '<STR_LIT>' ) <EOL> @ task <EOL> def delete_nginx_config ( ) : <EOL> rmdir ( env . hosts_data . nginx_enabled_path ( ) , sudo_access = True ) <EOL> rmdir ( env . hosts_data . nginx_available_path ( ) , sudo_access = True ) <EOL> sudo ( '<STR_LIT>' ) <EOL> @ task <EOL> def migrate_database ( ) : <EOL> with cd ( env . hosts_data . app_path ( ) ) : <EOL> with prefix ( "<STR_LIT>" . format ( env . hosts_data . virtualenv_activate_path ( ) ) ) : <EOL> run ( "<STR_LIT>" ) <EOL> run ( "<STR_LIT>" ) <EOL> @ task <EOL> def collect_static ( ) : <EOL> with cd ( env . hosts_data . app_path ( ) ) : <EOL> with prefix ( "<STR_LIT>" . format ( env . hosts_data . virtualenv_activate_path ( ) ) ) : <EOL> run ( "<STR_LIT>" ) <EOL> @ task <EOL> def delete_folders ( ) : <EOL> rmdir ( env . hosts_data . base_path ( ) ) <EOL> @ task <EOL> def delete_gunicorn_supervisor ( ) : <EOL> server_stop ( ) <EOL> rmdir ( env . hosts_data . gunicorn_supervisor_config_path ( ) , sudo_access = True ) <EOL> sudo ( '<STR_LIT>' ) <EOL> sudo ( '<STR_LIT>' ) <EOL> @ task <EOL> def delete_celery_supervisor ( ) : <EOL> server_stop ( ) <EOL> rmdir ( env . hosts_data . celery_supervisor_config_path ( ) , sudo_access = True ) <EOL> sudo ( '<STR_LIT>' ) <EOL> sudo ( '<STR_LIT>' ) <EOL> @ task ( default = True ) <EOL> def make_deploy ( ) : <EOL> install_requirements ( ) <EOL> create_folders ( ) <EOL> run ( env . hosts_data . git_clone_command ( ) ) <EOL> with cd ( env . hosts_data . app_path ( ) ) : <EOL> run ( env . hosts_data . git_checkout_command ( ) ) <EOL> create_virtual_environment ( ) <EOL> create_local_settings ( ) <EOL> migrate_database ( ) <EOL> create_demo_superuser ( ) <EOL> collect_static ( ) <EOL> create_gunicorn_config ( ) <EOL> create_gunicorn_supervisor ( ) <EOL> create_celery_supervisor ( ) <EOL> create_nginx_config ( ) <EOL> @ task <EOL> def server_status ( ) : <EOL> sudo ( '<STR_LIT>' . format ( env . hosts_data . application_name ( ) ) ) <EOL> @ task <EOL> def server_stop ( ) : <EOL> sudo ( '<STR_LIT>' . format ( env . hosts_data . application_name ( ) ) ) <EOL> sudo ( '<STR_LIT>' . format ( env . hosts_data . application_name ( ) ) ) <EOL> @ task <EOL> def server_start ( ) : <EOL> sudo ( '<STR_LIT>' . format ( env . hosts_data . application_name ( ) ) ) <EOL> sudo ( '<STR_LIT>' . format ( env . hosts_data . application_name ( ) ) ) <EOL> @ task <EOL> def server_restart ( ) : <EOL> sudo ( '<STR_LIT>' . format ( env . hosts_data . application_name ( ) ) ) <EOL> sudo ( '<STR_LIT>' . format ( env . hosts_data . application_name ( ) ) ) <EOL> @ task <EOL> def destroy_deploy ( ) : <EOL> delete_folders ( ) <EOL> delete_gunicorn_supervisor ( ) <EOL> delete_celery_supervisor ( ) <EOL> delete_nginx_config ( ) <EOL> @ task <EOL> def update_deploy ( ) : <EOL> server_stop ( ) <EOL> with cd ( env . hosts_data . app_path ( ) ) : <EOL> with prefix ( "<STR_LIT>" . format ( env . hosts_data . virtualenv_activate_path ( ) ) ) : <EOL> run ( '<STR_LIT>' ) <EOL> run ( '<STR_LIT>' . format ( env . hosts_data . requirements_path ( ) ) ) <EOL> migrate_database ( ) <EOL> collect_static ( ) <EOL> server_start ( ) </s>
