<s> from time import sleep <EOL> from fabric import colors <EOL> from fabric . api import task , env , run , cd <EOL> from fabric . utils import abort , puts <EOL> from fabric . context_managers import hide <EOL> def set_env_defaults ( ) : <EOL> env . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> env . setdefault ( '<STR_LIT>' , env . remote_workdir + '<STR_LIT>' ) <EOL> env . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> set_env_defaults ( ) <EOL> def gunicorn_running ( ) : <EOL> return run ( '<STR_LIT>' + env . gunicorn_pidpath , quiet = True ) . succeeded <EOL> def gunicorn_running_workers ( ) : <EOL> count = None <EOL> with hide ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> count = run ( '<STR_LIT>' % <EOL> env . gunicorn_pidpath ) <EOL> return count <EOL> @ task <EOL> def status ( ) : <EOL> """<STR_LIT>""" <EOL> set_env_defaults ( ) <EOL> if gunicorn_running ( ) : <EOL> puts ( colors . green ( "<STR_LIT>" ) ) <EOL> puts ( colors . yellow ( '<STR_LIT>' % gunicorn_running_workers ( ) ) ) <EOL> else : <EOL> puts ( colors . blue ( "<STR_LIT>" ) ) <EOL> @ task <EOL> def start ( ) : <EOL> """<STR_LIT>""" <EOL> set_env_defaults ( ) <EOL> if gunicorn_running ( ) : <EOL> puts ( colors . red ( "<STR_LIT>" ) ) <EOL> return <EOL> if '<STR_LIT>' not in env : <EOL> abort ( colors . red ( '<STR_LIT>' ) ) <EOL> with cd ( env . remote_workdir ) : <EOL> prefix = [ ] <EOL> if '<STR_LIT>' in env : <EOL> prefix . append ( '<STR_LIT>' % env . virtualenv_dir ) <EOL> if '<STR_LIT>' in env : <EOL> prefix . append ( '<STR_LIT>' % <EOL> env . django_settings_module ) <EOL> prefix_string = '<STR_LIT>' . join ( prefix ) <EOL> if len ( prefix_string ) > <NUM_LIT:0> : <EOL> prefix_string += '<STR_LIT>' <EOL> options = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % env . gunicorn_pidpath , <EOL> '<STR_LIT>' % env . gunicorn_bind , <EOL> ] <EOL> if '<STR_LIT>' in env : <EOL> options . append ( '<STR_LIT>' % env . gunicorn_workers ) <EOL> if '<STR_LIT>' in env : <EOL> options . append ( '<STR_LIT>' % env . gunicorn_worker_class ) <EOL> options_string = '<STR_LIT:U+0020>' . join ( options ) <EOL> if '<STR_LIT>' in env : <EOL> run ( '<STR_LIT>' % ( prefix_string , options_string , <EOL> env . paster_config_file ) ) <EOL> else : <EOL> run ( '<STR_LIT>' % ( prefix_string , options_string , <EOL> env . gunicorn_wsgi_app ) ) <EOL> if gunicorn_running ( ) : <EOL> puts ( colors . green ( "<STR_LIT>" ) ) <EOL> else : <EOL> abort ( colors . red ( "<STR_LIT>" ) ) <EOL> @ task <EOL> def stop ( ) : <EOL> """<STR_LIT>""" <EOL> set_env_defaults ( ) <EOL> if not gunicorn_running ( ) : <EOL> puts ( colors . red ( "<STR_LIT>" ) ) <EOL> return <EOL> run ( '<STR_LIT>' % ( env . gunicorn_pidpath ) ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT:5> ) : <EOL> puts ( '<STR_LIT:.>' , end = '<STR_LIT>' , show_prefix = i == <NUM_LIT:0> ) <EOL> if gunicorn_running ( ) : <EOL> sleep ( <NUM_LIT:1> ) <EOL> else : <EOL> puts ( '<STR_LIT>' , show_prefix = False ) <EOL> puts ( colors . green ( "<STR_LIT>" ) ) <EOL> break <EOL> else : <EOL> puts ( colors . red ( "<STR_LIT>" ) ) <EOL> return <EOL> @ task <EOL> def restart ( ) : <EOL> """<STR_LIT>""" <EOL> stop ( ) <EOL> start ( ) <EOL> @ task <EOL> def reload ( ) : <EOL> """<STR_LIT>""" <EOL> set_env_defaults ( ) <EOL> if not gunicorn_running ( ) : <EOL> puts ( colors . red ( "<STR_LIT>" ) ) <EOL> return <EOL> puts ( colors . yellow ( '<STR_LIT>' ) ) <EOL> run ( '<STR_LIT>' % ( env . gunicorn_pidpath ) ) <EOL> @ task <EOL> def add_worker ( ) : <EOL> """<STR_LIT>""" <EOL> set_env_defaults ( ) <EOL> if not gunicorn_running ( ) : <EOL> puts ( colors . red ( "<STR_LIT>" ) ) <EOL> return <EOL> puts ( colors . green ( '<STR_LIT>' ) ) <EOL> run ( '<STR_LIT>' % ( env . gunicorn_pidpath ) ) <EOL> puts ( colors . yellow ( '<STR_LIT>' % gunicorn_running_workers ( ) ) ) <EOL> @ task <EOL> def remove_worker ( ) : <EOL> """<STR_LIT>""" <EOL> set_env_defaults ( ) <EOL> if not gunicorn_running ( ) : <EOL> puts ( colors . red ( "<STR_LIT>" ) ) <EOL> return <EOL> puts ( colors . green ( '<STR_LIT>' ) ) <EOL> run ( '<STR_LIT>' % ( env . gunicorn_pidpath ) ) <EOL> puts ( colors . yellow ( '<STR_LIT>' % gunicorn_running_workers ( ) ) ) </s>
