@@ -0,0 +1,2417 @@
+from fabric.contrib.files import append, exists, sed%0Afrom fabric.api import env, local, run%0Aimport random%0A%0AREPO_URL = 'https://github.com/gajimenezmaggiora/gus-django.git'  #1%0A%0Adef deploy():%0A    site_folder = '/home/%25s/sites/%25s' %25 (env.user, env.host)  #23%0A    source_folder = site_folder + '/source'%0A    _create_directory_structure_if_necessary(site_folder)%0A    _get_latest_source(source_folder)%0A    _update_settings(source_folder, env.host)%0A    _update_virtualenv(source_folder)%0A    _update_static_files(source_folder)%0A    _update_database(source_folder)%0A%0Adef _create_directory_structure_if_necessary(site_folder):%0A    for subfolder in ('database', 'static', 'virtualenv', 'source'):%0A        run('mkdir -p %25s/%25s' %25 (site_folder, subfolder))  #12%0A%0Adef _get_latest_source(source_folder):%0A    if exists(source_folder + '/.git'):  #1%0A        run('cd %25s && git fetch' %25 (source_folder,))  #23%0A    else:%0A        run('git clone %25s %25s' %25 (REPO_URL, source_folder))  #4%0A    current_commit = local(%22git log -n 1 --format=%25H%22, capture=True)  #5%0A    run('cd %25s && git reset --hard %25s' %25 (source_folder, current_commit))  #6%0A%0Adef _update_settings(source_folder, site_name):%0A    settings_path = source_folder + '/superlists/settings.py'%0A    sed(settings_path, %22DEBUG = True%22, %22DEBUG = False%22)  #1%0A    sed(settings_path,%0A        'ALLOWED_HOSTS =.+$',%0A        'ALLOWED_HOSTS = %5B%22%25s%22%5D' %25 (site_name,)  #2%0A    )%0A    secret_key_file = source_folder + '/superlists/secret_key.py'%0A    if not exists(secret_key_file):  #3%0A        chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%25%5E&*(-_=+)'%0A        key = ''.join(random.SystemRandom().choice(chars) for _ in range(50))%0A        append(secret_key_file, %22SECRET_KEY = '%25s'%22 %25 (key,))%0A    append(settings_path, '%5Cnfrom .secret_key import SECRET_KEY')  #45%0A%0Adef _update_virtualenv(source_folder):%0A    virtualenv_folder = source_folder + '/../virtualenv'%0A    if not exists(virtualenv_folder + '/bin/pip'): #1%0A        run('virtualenv --python=python3 %25s' %25 (virtualenv_folder,))%0A    run('%25s/bin/pip install -r %25s/requirements.txt' %25 ( #2%0A            virtualenv_folder, source_folder%0A    ))%0A%0Adef _update_static_files(source_folder):%0A    run('cd %25s && ../virtualenv/bin/python3 manage.py collectstatic --noinput' %25 ( # 1%0A        source_folder,%0A    ))%0A%0Adef _update_database(source_folder):%0A    run('cd %25s && ../virtualenv/bin/python3 manage.py migrate --noinput' %25 (%0A        source_folder,%0A    ))%0A

Add a fabfile for automated deploys