def collect_files(): require('static_root','virtualenv_root', provided_by=('staging', 'production')) # safety checks assert env.static_root.strip() != '' and env.static_root.strip() != '/' # Before Django 1.4 we don't have the ``--clear`` option to ``collectstatic`` run('rm -rf %(static_root)s/*' % env) run_venv('django-admin.py collectstatic -v 0 --noinput --settings=%(settings)s' % env)
def update_index(): """ update solr index<< """ require('settings', 'virtualenv_root', provided_by=('staging', 'production')) run_venv('django-admin.py update_index --settings=%(settings)s' % env)
def sync_remote(): """ Sync the application's database on the server machine. """ require('settings', 'virtualenv_root', provided_by=('staging', 'production')) run_venv('django-admin.py syncdb --noinput --settings=%(settings)s' % env)
def rebuild_index(): """ Rebuild Solr index from scratch. """ require('settings', provided_by=('staging', 'production')) fastprint("Rebuilding Solr index... ", show_prefix=True) run_venv('django-admin.py rebuild_index --noinput --settings=%(settings)s' % env) fastprint(" done." % env, end='\n')
def rebuild_index(): """ rebuild solr index from scratch """ require('settings', 'virtualenv_root', provided_by=('staging', 'production')) run_venv('django-admin.py rebuild_index --settings=%(settings)s' % env)
def update_index(): """ Update Solr index. """ require("settings", "virtualenv_root", provided_by=("staging", "production")) with hide("stdout", "running"): fastprint("Updating Solr index... ", show_prefix=True) run_venv("django-admin.py update_index --settings=%(settings)s" % env) fastprint(" done." % env, end="\n")
def rebuild_index(): """ Rebuild Solr index from scratch. """ require("settings", provided_by=("staging", "production")) with hide("commands"): fastprint("Rebuilding Solr index... ", show_prefix=True) run_venv("django-admin.py rebuild_index --settings=%(settings)s" % env) fastprint(" done." % env, end="\n")
def sync_db(): """ Syncronize the application's database on the server machine. """ require('settings', provided_by=('staging', 'production')) fastprint("Running `syncdb'...", show_prefix=True) with hide('commands'): run_venv('django-admin.py syncdb --noinput --settings=%(settings)s' % env) fastprint(" done." % env, end='\n')
def rebuild_index(): """ Rebuild Solr index from scratch. """ require('settings', provided_by=('staging', 'production')) with hide('commands'): fastprint("Rebuilding Solr index... ", show_prefix=True) run_venv('django-admin.py rebuild_index --settings=%(settings)s' % env) fastprint(" done." % env, end='\n')
def update_index(): """ Update Solr index. """ require('settings', 'virtualenv_root', provided_by=('staging', 'production')) with hide('stdout', 'running'): fastprint("Updating Solr index... ", show_prefix=True) run_venv('django-admin.py update_index --settings=%(settings)s' % env) fastprint(" done." % env, end='\n')
def collect_files(): require('static_root', 'virtualenv_root', provided_by=('staging', 'production')) # safety checks assert env.static_root.strip() != '' and env.static_root.strip() != '/' # Before Django 1.4 we don't have the ``--clear`` option to ``collectstatic`` run('rm -rf %(static_root)s/*' % env) run_venv( 'django-admin.py collectstatic -v 0 --noinput --settings=%(settings)s' % env)
def update_data_schema(): """ Update Solr data schema. """ require('settings', 'domain_root', 'web_user', provided_by=('staging', 'production')) fastprint("Updating Solr data schema... ", show_prefix=True) run_venv('django-admin.py build_solr_schema --settings=%(settings)s > %(domain_root)s/private/solr/conf/schema.xml' % env) sudo('chown -R %(om_user)s:www-data %(domain_root)s/private/solr' % env) execute(restart_tomcat) fastprint(" done." % env, end='\n')
def update(): """ Update remote database (including South migrations, if any). """ require('settings','code_root', provided_by=('staging', 'production')) drop() run_venv('django-admin.py syncdb --all --noinput --settings=%(settings)s' % env) with cd(env.code_root): if files.exists('sqlite.db'): sudo('chgrp www-data sqlite.db') sudo('chmod g+w sqlite.db')
def update(): """ Update remote database (including South migrations, if any). """ require('settings', 'code_root', provided_by=('staging', 'production')) drop() run_venv('django-admin.py syncdb --all --noinput --settings=%(settings)s' % env) with cd(env.code_root): if files.exists('sqlite.db'): sudo('chgrp www-data sqlite.db') sudo('chmod g+w sqlite.db')
def update_data_schema(): """ Update Solr data schema. """ require('settings', 'domain_root', 'web_user', provided_by=('staging', 'production')) with hide('commands'): fastprint("Updating Solr data schema... ", show_prefix=True) run_venv('django-admin.py build_solr_schema --settings=%(settings)s > %(domain_root)s/private/solr/conf/schema.xml' % env) sudo('chown -R %(web_user)s:www-data %(domain_root)s/private/solr' % env) execute(restart_tomcat) fastprint(" done." % env, end='\n')
def sync_db(input=False): """ Syncronize the application's database on the server machine. """ input_option = '' if input is False: input_option = '--noinput' require('settings', provided_by=('staging', 'production')) fastprint("Running `syncdb'...", show_prefix=True) run_venv('django-admin.py syncdb %s --settings=%s' % (input_option, env.settings)) fastprint(" done." % env, end='\n')
def collect_files(): """ Collect static files on the remote machine. """ require('static_root','virtualenv_root', provided_by=('staging', 'production')) fastprint("Collecting static files..." % env, show_prefix=True) with hide('commands'): # safety checks assert env.static_root.strip() != '' and env.static_root.strip() != '/' # Before Django 1.4 we don't have the ``--clear`` option to ``collectstatic`` run('rm -rf %(static_root)s/*' % env) run_venv('django-admin.py collectstatic -v 0 --noinput --settings=%(settings)s' % env) fastprint(" done." % env, end='\n')
def update_data_schema(): """ Update Solr data schema. """ require("settings", "domain_root", "web_user", provided_by=("staging", "production")) with hide("commands"): fastprint("Updating Solr data schema... ", show_prefix=True) run_venv( "django-admin.py build_solr_schema--settings=%(settings)s > %(domain_root)s/private/solr/conf/schema.xml" % env ) sudo("chmod -R %(web_user)s:www-data %(domain_root)s/private/solr") execute(restart_tomcat) fastprint(" done." % env, end="\n")
def import_votations(mdb_file, dry_run='True', verbosity='2'): """ Import given votations from the specified mdb_file Uses standard people.xml map file, specified in conf.VOTATIONS_PEOPLE_FILE """ dry_run_option = '' if dry_run == 'True': dry_run_option = '--dry-run' require('settings', provided_by=('staging', 'production')) run_venv('django-admin.py senigallia_import_votations %s --verbosity=%s --settings=%s %s' % (dry_run_option, verbosity, env.settings, mdb_file) )
def start_uwsgi(): """ Start a uwsgi instance for the deployed site """ require('domain_root', provided_by=('staging', 'production')) require('project', provided_by=('staging', 'production')) fastprint("Starting running instance of uwsgi ..." % env, show_prefix=True) with hide('stdout','running'): with cd(os.path.join(env.domain_root,'private','nginx')): # fab does not work well with background processes, # see https://github.com/fabric/fabric/issues/395 # add a sleep is a workaround run_venv('nohup uwsgi --ini %(project)s.uwsgi.ini & sleep 3; exit 0' % env) fastprint(" done." % env, end='\n')
def import_acts(act, act_type='CouncilDeliberation', dry_run='True', verbosity='2'): """ Import given act (act type must be esplicitly specified), May import more than one act, using glob Uses standard people.xml map file, specified in conf.ACTS_PEOPLE_FILE """ dry_run_option = '' if dry_run == 'True': dry_run_option = '--dry-run' require('settings', provided_by=('staging', 'production')) run_venv('django-admin.py senigallia_import_acts %s --act-type=%s --verbosity=%s --settings=%s %s' % (dry_run_option, act_type, verbosity, env.settings, act) )
def stop_uwsgi(): """ Kill the master instance of a running uwsgi process """ require('domain_root', provided_by=('staging', 'production')) fastprint("Stopping running instance of uwsgi ..." % env, show_prefix=True) with hide('stdout','running'): with cd(env.domain_root): with settings(warn_only=True): pid_file = "./private/nginx/%(project)s.pid" % env if exists(pid_file): run_venv('uwsgi --stop %s' % pid_file) fastprint(" done." % env, end='\n')
def migrate(app, migration_number=None, fake='False', dryrun='True'): require('settings', provided_by=('staging', 'production')) migration_number_option = '' fake_option = '' dryrun_option = '' if migration_number is not None: migration_number_option = migration_number if fake == 'True': fake_option = '--fake' if dryrun == 'True': dryrun_option = '--db-dry-run' run_venv('django-admin.py migrate %s %s %s %s --no-initial-data --settings=%s ' % (app, migration_number_option, fake_option, dryrun_option, env.settings))
def schemamigration(app, initial='False', auto='True'): """ Generates migrations from schema (models) and database Can be invoked with --initial or --auto parameters """ require('settings', provided_by=('staging', 'production')) initial_option = '' auto_option = '' if initial == 'True': initial_option = '--initial' if auto == 'True': auto_option = '--auto' if auto == 'True' and initial == 'True': raise Exception('only one between initial and auto options can be set to true') run_venv('django-admin.py schemamigration %s %s %s --settings=%s ' % (app, initial_option, auto_option, env.settings))
def list_migrations(): """ List current migrations and their status """ require('settings', provided_by=('staging', 'production')) run_venv('django-admin.py migrate --settings=%s --list' % (env.settings,))