def resetdb(): """ Reset the project's database by dropping an creating it again. """ urun('dropdb luke') createdb() migrate()
def resetdb(): """ Reset the project's database by dropping an creating it again. """ urun('dropdb idneo') createdb() migrate() loaddummydata()
def resetdb(): """ Reset the project's database by dropping an creating it again. """ urun('dropdb tandlr') createdb() migrate() load_dummy_data()
def backup(tarball_name='backup', just_data=False): """ Generates a backup copy of database and uploads """ require('wpworkflow_dir', 'public_dir') env.tarball_name = tarball_name export_data(tarball_name + '.sql', just_data) print 'Preparing backup directory...' if not os.path.exists('./backup/'): os.makedirs('./backup/') if exists('{wpworkflow_dir}backup/'): run('rm -rf {wpworkflow}backup/') if not exists('{wpworkflow_dir}backup/'.format(**env)): run('mkdir {wpworkflow_dir}backup/'.format(**env)) if not exists('{wpworkflow_dir}backup/database/'.format(**env)): run('mkdir {wpworkflow_dir}backup/database/'.format(**env)) if not exists('{wpworkflow_dir}backup/uploads/'.format(**env)): run('mkdir {wpworkflow_dir}backup/uploads/'.format(**env)) run('mv {wpworkflow_dir}/database/{tarball_name}.sql '.format(**env) + '{wpworkflow_dir}/backup/database/'.format(**env)) print 'Copying uploads...' run('cp -r {public_dir}wp-content/uploads/* {wpworkflow_dir}backup/uploads/' .format(**env)) print 'Creating tarball...' with cd(env.wpworkflow_dir): urun('tar -czf {tarball_name}.tar.gz backup/*'.format(**env)) print 'Downloading backup...' download = True if os.path.exists('./backup/{tarball_name}.tar.gz'.format(**env)): download = confirm( yellow('./backup/{tarball_name}.tar.gz'.format(**env) + ' already exists, Do you want to overwrite it?')) if download: get('{wpworkflow_dir}{tarball_name}.tar.gz'.format(**env), './backup/{tarball_name}.tar.gz'.format(**env)) else: print red('Backup canceled by user') print 'Cleaning working directory...' run('rm -rf {wpworkflow_dir}backup/'.format(**env)) run('rm {wpworkflow_dir}{tarball_name}.tar.gz'.format(**env)) if download: print green('Backup succesfully created at' + ' ./backup/{tarball_name}.tar.gz'.format(**env))
def createdb(): """New database. Creates a new database instance with utf-8 encoding for the project. Usage: >>>fab environment:vagrant createdb. """ urun('createdb notivinco -l en_US.UTF-8 -E UTF8 -T template0')
def dropdb(): """Restore database. Drop database named luke. Usage: >>>fab environment:vagrant dropdb. """ urun('dropdb luke')
def createdb(): """New database. Creates a new database instance with utf-8 encoding for the project. Usage: >>>fab environment:vagrant createdb. """ urun('createdb sita -l en_US.UTF-8 -E UTF8 -T template0')
def dropdb(): """Drop database. Drop database without create it again Usage: >>>fab environment:vagrant dropdb. """ urun('dropdb knowledge_base')
def resetdb(): """Restore database. Reset the project's database by dropping an creating it again. Usage: >>>fab environment:vagrant resetdb. """ urun('dropdb socialregister') createdb() migrate()
def backup(tarball_name='backup', just_data=False): """ Generates a backup copy of database and uploads """ require('wpworkflow_dir', 'public_dir') env.tarball_name = tarball_name export_data(tarball_name + '.sql', just_data) print 'Preparing backup directory...' if not os.path.exists('./backup/'): os.makedirs('./backup/') if exists('{wpworkflow_dir}backup/'): run('rm -rf {wpworkflow}backup/') if not exists('{wpworkflow_dir}backup/'.format(**env)): run('mkdir {wpworkflow_dir}backup/'.format(**env)) if not exists('{wpworkflow_dir}backup/database/'.format(**env)): run('mkdir {wpworkflow_dir}backup/database/'.format(**env)) if not exists('{wpworkflow_dir}backup/uploads/'.format(**env)): run('mkdir {wpworkflow_dir}backup/uploads/'.format(**env)) run( 'mv {wpworkflow_dir}/database/{tarball_name}.sql '.format(**env) + '{wpworkflow_dir}/backup/database/'.format(**env) ) print 'Copying uploads...' run('cp -r {public_dir}wp-content/uploads/* {wpworkflow_dir}backup/uploads/'. format(**env)) print 'Creating tarball...' with cd(env.wpworkflow_dir): urun('tar -czf {tarball_name}.tar.gz backup/*'.format(**env)) print 'Downloading backup...' get( '{wpworkflow_dir}{tarball_name}.tar.gz'.format(**env), './backup/{tarball_name}.tar.gz'.format(**env) ) print 'Cleaning working directory...' run('rm -rf {wpworkflow_dir}backup/'.format(**env)) run('rm {wpworkflow_dir}{tarball_name}.tar.gz'.format(**env)) print green('Backup succesfully created at ./backup/{tarball_name}.tar.gz'. format(**env))
def resetdb(): """Restore database. Reset the project's database by dropping an creating it again. Usage: >>>fab environment:vagrant resetdb. """ urun('dropdb notivinco') createdb() migrate()
def resetdb(): """Restore database. Reset the project's database by dropping an creating it again. Usage: >>>fab environment:vagrant resetdb. """ urun('dropdb sita') createdb() migrate() load_dummy_data()
def backup(tarball_name="backup", just_data=False): """ Generates a backup copy of database """ require("public_dir") env.tarball_name = tarball_name export_data(tarball_name + ".sql", just_data) print "Preparing backup directory..." if not os.path.exists("./backup/"): os.makedirs("./backup/") if exists("{public_dir}backup/"): run("rm -rf {public_dir}backup/") if not exists("{public_dir}backup/".format(**env)): run("mkdir {public_dir}backup/".format(**env)) if not exists("{public_dir}backup/database/".format(**env)): run("mkdir {public_dir}backup/database/".format(**env)) run("mv {public_dir}/database/{tarball_name}.sql ".format(**env) + "{public_dir}/backup/database/".format(**env)) print "Creating tarball..." with cd(env.public_dir): urun("tar -czf {tarball_name}.tar.gz backup/*".format(**env)) print "Downloading backup..." download = True if os.path.exists("./backup/{tarball_name}.tar.gz".format(**env)): download = confirm( yellow("./backup/{tarball_name}.tar.gz".format(**env) + " already exists, Do you want to overwrite it?") ) if download: get("{public_dir}{tarball_name}.tar.gz".format(**env), "./backup/{tarball_name}.tar.gz".format(**env)) else: print red("Backup canceled by user") print "Cleaning working directory..." run("rm -rf {public_dir}backup/".format(**env)) run("rm {public_dir}{tarball_name}.tar.gz".format(**env)) if download: print green("Backup succesfully created at" + " ./backup/{tarball_name}.tar.gz".format(**env))
def set_webserver(webserver="nginx"): """ Changes project's web server, nginx or apache2 available, nginx by default. """ require('public_dir') if webserver == "apache2": sudo("service nginx stop") sudo("a2enmod rewrite") with open('wordpress-workflow/defaults/htaccess') as htaccess: urun(" echo '{0}' > {1}.htaccess".format(htaccess.read(), env.public_dir)) sudo("service apache2 start", pty=False) else: sudo("service apache2 stop") if exists("{0}.htaccess".format(env.public_dir)): urun("rm {0}.htaccess".format(env.public_dir)) sudo("service nginx start") print "Web server switched to " + blue(webserver, bold=True) + "."
def set_webserver(webserver="nginx"): """ Changes project's web server, nginx or apache2 available, nginx by default. """ require('public_dir') if webserver == "apache2": sudo("service nginx stop") sudo("a2enmod rewrite") with open('wordpress-workflow/defaults/htaccess') as htaccess: urun(" echo '{0}' > {1}.htaccess". format(htaccess.read(), env.public_dir)) sudo("service apache2 start", pty=False) else: sudo("service apache2 stop") if exists("{0}.htaccess".format(env.public_dir)): urun("rm {0}.htaccess".format(env.public_dir)) sudo("service nginx start") print "Web server switched to " + blue(webserver, bold=True) + "."
def _prestashop_install(): """ Downloads the Prestashop version specified in settings.json and installs the database. """ require("cpchuy_dir", "public_dir", "dbname", "dbuser", "dbpassword", "version") print "Delete project..." run("rm -rf {public_dir}*".format(**env)) run('find {public_dir} -name ".*" -delete'.format(**env)) # Downloads PrestaShop print "Downloading PrestaShop..." with cd(env.public_dir): urun("wget https://github.com/PrestaShop/PrestaShop/archive/{version}.tar.gz".format(**env)) urun("tar -xzvf {version}.tar.gz".format(**env)) urun("mv PrestaShop-{version}/* .".format(**env)) urun("rm -rf PrestaShop-{version}".format(**env)) run("mkdir {public_dir}database".format(**env))
def createdb(): """ Creates a new database instance. """ urun('echo "CREATE DATABASE laravel;"|mysql --batch --user=root --password=password --host=localhost')
def createdb(): """ Creates a new database instance with utf-8 encoding for the project. """ urun('createdb tandlr -l en_US.UTF-8 -E UTF8 -T template0') urun('psql -d tandlr -c "CREATE EXTENSION postgis;"')
def createdb(): """ Creates a new database instance with utf-8 encoding for the project. """ urun('createdb luke -l en_US.UTF-8 -E UTF8 -T template0')
def backup(tarball_name='backup', just_data=False): """ Generates a backup copy of database """ require('public_dir') env.tarball_name = tarball_name export_data(tarball_name + '.sql', just_data) print 'Preparing backup directory...' if not os.path.exists('./backup/'): os.makedirs('./backup/') if exists('{public_dir}backup/'): run('rm -rf {public_dir}backup/') if not exists('{public_dir}backup/'.format(**env)): run('mkdir {public_dir}backup/'.format(**env)) if not exists('{public_dir}backup/database/'.format(**env)): run('mkdir {public_dir}backup/database/'.format(**env)) run( 'mv {public_dir}/database/{tarball_name}.sql '.format(**env) + '{public_dir}/backup/database/'.format(**env) ) print 'Creating tarball...' with cd(env.public_dir): urun('tar -czf {tarball_name}.tar.gz backup/*'.format(**env)) print 'Downloading backup...' download = True if os.path.exists('./backup/{tarball_name}.tar.gz'.format(**env)): download = confirm( yellow( './backup/{tarball_name}.tar.gz'.format(**env) + ' already exists, Do you want to overwrite it?' ) ) if download: get( '{public_dir}{tarball_name}.tar.gz'.format(**env), './backup/{tarball_name}.tar.gz'.format(**env) ) else: print red('Backup canceled by user') print 'Cleaning working directory...' run('rm -rf {public_dir}backup/'.format(**env)) run('rm {public_dir}{tarball_name}.tar.gz'.format(**env)) if download: print green( 'Backup succesfully created at' + ' ./backup/{tarball_name}.tar.gz'. format(**env) )
def make_tarball(target_environment, tar_name="wordpress-dist"): """ Generates a tallbar to upload to servers without ssh. """ environment('vagrant') env.tmp_dir = "/home/vagrant/wordpress-dist/" env.tmp_dir_name = "wordpress-dist" env.host_string = env.hosts[0] check_plugins() if not os.path.exists('./dist/'): print "Creating dist folder..." os.makedirs('./dist/') # Creates necesary dirs print "Creating directory structure..." if exists(env.tmp_dir): urun('rm -rf {tmp_dir}'.format(**env)) urun('mkdir {tmp_dir}'.format(**env)) # Downloads print "Downloading and generating wordpress configuration..." #Downloads wordpress urun('wp core download --version={version} --path={tmp_dir} ' '--locale={locale} --force'.format(**env)) #creates config with open('environments.json', 'r') as json_file: db_config = json.load(json_file)[target_environment] db_config['tmp_dir'] = env.tmp_dir urun('wp core config --dbname={dbname} --dbuser={dbuser} ' '--dbpass={dbpassword} --skip-check --path={tmp_dir}'.format( **db_config)) # Configure temp database create_database_command = ''' echo " CREATE DATABASE {dbname}; CREATE USER '{dbuser}'@'localhost' IDENTIFIED BY '{dbpassword}'; GRANT ALL PRIVILEGES ON *.* TO '{dbuser}'@'localhost'; FLUSH PRIVILEGES; "'''.format(**db_config) print "Configurating temporary database..." urun(create_database_command + '|mysql --batch --user={dbuser} --password={dbpassword}'.format( **env)) # Install wodpress print "Installing temporary wordpress..." urun('wp core install --url="{url}" --title="{title}" ' '--admin_user="******" --admin_password="******" ' ' --admin_email="{admin_email}" --path={tmp_dir}'.format(**db_config)) # Cleans default wordpress files urun('rm -rf {tmp_dir}wp-content/themes/*'.format(**env)) urun('rm -rf {tmp_dir}wp-content/plugins/*'.format(**env)) # Copy theme urun('cp -rf {wpworkflow_dir}themes/* {tmp_dir}wp-content/themes/'.format( **env)) # Download all require plugins with cd(env.tmp_dir): for plugin in env.get("plugins", []): print "Downloading plugin: " + blue(plugin['name'], bold=True) urun(""" wp plugin install {0} """.format(plugin['name'])) # Copy custom plugins for plugin in env.get("custom_plugins", []): env.plugin = plugin['name'] print "Copying plugin: " + blue(plugin['name'], bold=True) urun(""" cp -rf {wpworkflow_dir}plugins/{plugin} \ {tmp_dir}wp-content/plugins """.format(**env)) # Download all require plugins print "Generating packaging..." env.tar_name = tar_name with cd(env.tmp_dir + ".."): urun('tar -czf {wpworkflow_dir}{tar_name}.tar.gz {tmp_dir_name}/*'. format(**env)) os.rename('./src/{tar_name}.tar.gz'.format(**env), './dist/{tar_name}.tar.gz'.format(**env)) # Delete temp database print "Cleaning temporary data..." clean_database_command = ''' echo " DROP USER '{dbuser}'@'localhost'; DROP DATABASE {dbname}; "'''.format(**db_config) urun(clean_database_command + '|mysql --batch --user={dbuser} --password={dbpassword}'.format( **env)) urun('rm -rf {tmp_dir}'.format(**env)) print green("Packaging generated in dist/{tar_name}.tar.gz".format(**env))
def make_tarball(target_environment="test", tar_name="wordpress-dist"): """ Generates a tallbar to upload to servers without ssh. """ environment('vagrant') env.tmp_dir = "/home/vagrant/wordpress-dist/" env.tmp_dir_name = "wordpress-dist" env.host_string = env.hosts[0] check_plugins() if not os.path.exists('./dist/'): print "Creating dist folder..." os.makedirs('./dist/') # Creates necesary dirs print "Creating directory structure..." if exists(env.tmp_dir): urun('rm -rf {tmp_dir}'.format(**env)) urun('mkdir {tmp_dir}'.format(**env)) # Downloads print "Downloading and generating wordpress configuration..." #Downloads wordpress urun('wp core download --version={version} --path={tmp_dir} ' '--locale={locale} --force'.format(**env)) #creates config with open('environments.json', 'r') as json_file: db_config = json.load(json_file)[target_environment] db_config['tmp_dir'] = env.tmp_dir urun('wp core config --dbname={dbname} --dbuser={dbuser} ' '--dbpass={dbpassword} --skip-check --path={tmp_dir}'.format(**db_config)) # Configure temp database create_database_command = ''' echo " CREATE DATABASE {dbname}; CREATE USER '{dbuser}'@'localhost' IDENTIFIED BY '{dbpassword}'; GRANT ALL PRIVILEGES ON *.* TO '{dbuser}'@'localhost'; FLUSH PRIVILEGES; "'''.format(**db_config) print "Configurating temporary database..." urun( create_database_command + '|mysql --batch --user={dbuser} --password={dbpassword}'.format(**env) ) # Install wodpress print "Installing temporary wordpress..." urun('wp core install --url="{url}" --title="{title}" ' '--admin_user="******" --admin_password="******" ' ' --admin_email="{admin_email}" --path={tmp_dir}'.format(**db_config)) # Cleans default wordpress files urun('rm -rf {tmp_dir}wp-content/themes/*'.format(**env)) urun('rm -rf {tmp_dir}wp-content/plugins/*'.format(**env)) # Copy theme urun('cp -rf {wpworkflow_dir}themes/* {tmp_dir}wp-content/themes/'. format(**env)) # Download all require plugins with cd(env.tmp_dir): for plugin in env.get("plugins", []): print "Downloading plugin: " + blue(plugin['name'], bold=True) urun(""" wp plugin install {0} """.format(plugin['name'])) # Copy custom plugins for plugin in env.get("custom_plugins", []): env.plugin = plugin['name'] print "Copying plugin: " + blue(plugin['name'], bold=True) urun( """ cp -rf {wpworkflow_dir}plugins/{plugin} \ {tmp_dir}wp-content/plugins """.format(**env) ) # Download all require plugins print "Generating packaging..." env.tar_name = tar_name with cd(env.tmp_dir + ".."): urun('tar -czf {wpworkflow_dir}{tar_name}.tar.gz {tmp_dir_name}/*' .format(**env)) os.rename( './src/{tar_name}.tar.gz'.format(**env), './dist/{tar_name}.tar.gz'.format(**env) ) # Delete temp database print "Cleaning temporary data..." clean_database_command = ''' echo " DROP USER '{dbuser}'@'localhost'; DROP DATABASE {dbname}; "'''.format(**db_config) urun( clean_database_command + '|mysql --batch --user={dbuser} --password={dbpassword}'.format(**env) ) urun('rm -rf {tmp_dir}'.format(**env)) print green("Packaging generated in dist/{tar_name}.tar.gz".format(**env))
def import_backup(tarball_name='backup'): """ Import backup generated by backup task """ require('wpworkflow_dir', 'public_dir') env.tarball_name = tarball_name env.import_backup_dir = '{wpworkflow_dir}import_backup/'.format(**env) confirm_task() print blue('Uploading backup...') if not os.path.exists('./backup/{tarball_name}.tar.gz'.format(**env)): print red('File {tarball_name}.tar.gz not exist.'.format(**env)) sys.exit(1) if exists('{import_backup_dir}'.format(**env)): run('rm -fr {import_backup_dir}'.format(**env)) run('mkdir {import_backup_dir}'.format(**env)) put( './backup/{tarball_name}.tar.gz'.format(**env), '{import_backup_dir}{tarball_name}.tar.gz'.format(**env) ) print green('Done.') print blue('Unzipping backup...') with cd('{import_backup_dir}'.format(**env)): urun('tar -xzf {tarball_name}.tar.gz'.format(**env)) print green('Done.') print blue('Validating backup...') is_valid_backup = True if not exists('{import_backup_dir}backup/'.format(**env)): is_valid_backup = False if not exists('{import_backup_dir}backup/database/'.format(**env)): is_valid_backup = False if not exists('{import_backup_dir}backup/database/{tarball_name}.sql'.format(**env)): is_valid_backup = False if not exists('{import_backup_dir}backup/uploads/'.format(**env)): is_valid_backup = False if is_valid_backup: print green('Done.') print blue('Importing uploads...') run('rm -rf {public_dir}wp-content/uploads/'.format(**env)) run( 'mv {import_backup_dir}backup/uploads/ '.format(**env) + '{public_dir}wp-content/uploads/'.format(**env) ) print green('Done.') print blue('Importing database...') run( 'mv {import_backup_dir}backup/database/{tarball_name}.sql '.format(**env) + '{wpworkflow_dir}database/{tarball_name}.sql '.format(**env) ) resetdb() import_data(tarball_name + '.sql') print green('Done.') else: print red("The backup file is not valid.") print 'Cleaning working directory...' run('rm -rf {import_backup_dir}'.format(**env))
def dropdb(): """ Drops the project's database """ urun('dropdb {0}'.format(project_conf['name']))
def resetdb(): """ Deletes a new database instance. """ urun('echo "DROP DATABASE laravel;"|mysql --batch --user=root --password=password --host=localhost') bootstrap()
def createdb(): """ Creates a new database instance with utf-8 encoding for the project. """ urun('createdb {0} -l en_US.UTF-8 -E UTF8 -T template0'.format( project_conf['name']))