Beispiel #1
0
def conditionally_install_and_patch_pil(requirements_file_path, venv_dir,
                                        patch_path):
    """
    PIL's setup.py file needs to be patched on centos to enable JPEG and
    PNG support.

    It will check whether PIL is in the requirements file and if so
    install it and patch it outside of pip's automated system.

    @param requirements_file_path Path to pip's requirements file
    @param venv_dir Path to the virtualenv directory
    @param patch_path Path to the patch file to apply
    """
    if files.contains(requirements_file_path, 'PIL'):
        puts(info="Installing PIL")
        pil_version = run('grep PIL %s' % requirements_file_path)

        with prefix(activate_venv()):
            run('pip install -I %s --no-install' % pil_version)
            # patch setup.py
            run('patch --unified %s %s' % (os.path.join(
                venv_dir, 'build', 'PIL', 'setup.py'), patch_path))
            run('pip install -I %s --no-download' % pil_version)

        puts(success="PIL patched and installed")
    else:
        puts(info="PIL doesn't need to be installed")
Beispiel #2
0
def conditionally_install_and_patch_pil(requirements_file_path, venv_dir,
        patch_path):
    """
    PIL's setup.py file needs to be patched on centos to enable JPEG and
    PNG support.

    It will check whether PIL is in the requirements file and if so
    install it and patch it outside of pip's automated system.

    @param requirements_file_path Path to pip's requirements file
    @param venv_dir Path to the virtualenv directory
    @param patch_path Path to the patch file to apply
    """
    if files.contains(requirements_file_path, 'PIL'):
        puts(info="Installing PIL")
        pil_version = run('grep PIL %s' % requirements_file_path)

        with prefix(activate_venv()):
            run('pip install -I %s --no-install' % pil_version)
            # patch setup.py
            run('patch --unified %s %s' % (os.path.join(venv_dir,
                'build', 'PIL', 'setup.py'), patch_path))
            run('pip install -I %s --no-download'  % pil_version)

        puts(success="PIL patched and installed")
    else:
        puts(info="PIL doesn't need to be installed")
Beispiel #3
0
def install_pip_dependencies(requirements_path):
    """
    Install dependencies using pip from the specified requirements file
    """
    puts(info='Installing dependencies with pip')

    with prefix(activate_venv()):
        run('pip install -r %s' % requirements_path)

    puts(success="Dependencies installed")
Beispiel #4
0
def django_publish_static_content(project_dir):
    """
    Collects django's static content and publishes it to the static directory.
    """
    puts(info="Collecting static content")
    with prefix(activate_venv()):
        run(os.path.join(project_dir, 'manage.py') +
            ' collectstatic --noinput --settings=settings_production')

    puts(success="Static content published")
Beispiel #5
0
def install_pip_dependencies(requirements_path):
    """
    Install dependencies using pip from the specified requirements file
    """
    puts(info='Installing dependencies with pip')

    with prefix(activate_venv()):
        run('pip install -r %s' % requirements_path)

    puts(success="Dependencies installed")
Beispiel #6
0
def django_publish_static_content(project_dir):
    """
    Collects django's static content and publishes it to the static directory.
    """
    puts(info="Collecting static content")
    with prefix(activate_venv()):
        run(
            os.path.join(project_dir, 'manage.py') +
            ' collectstatic --noinput --settings=settings_production')

    puts(success="Static content published")
Beispiel #7
0
def compile_less_css(project_dir):
    """
    Compiles less files to css
    """
    puts(info="Compiling LESS to css")
    if files.exists(os.path.join(project_dir, "plessc.py")):
        with cd(project_dir):
            with prefix(activate_venv()):
                run('./plessc.py')
                puts(success="Stylesheets compiled")
    else:
        puts(info="plessc.py not found - skipping")
Beispiel #8
0
def compile_less_css(project_dir):
    """
    Compiles less files to css
    """
    puts(info="Compiling LESS to css")
    if files.exists(os.path.join(project_dir, "plessc.py")):
        with cd(project_dir):
            with prefix(activate_venv()):
                run('./plessc.py')
                puts(success="Stylesheets compiled")
    else:
        puts(info="plessc.py not found - skipping")
Beispiel #9
0
def django_migrate_schema(project_dir, production=False):
    """
    Migrates the database schema

    @param project_dir The directory containing manage.py
    @param production Whether to use production settings
    """
    puts(info="Applying migrations")
    with prefix(activate_venv()):
        if production == True:
            run(os.path.join(project_dir, 'manage.py') + " migrate --all "
                "--settings=settings_production")
        else:
            run(os.path.join(project_dir, 'manage.py') + ' migrate --all')

    puts(success="Migrations applied")
Beispiel #10
0
def django_syncdb(project_dir, production=False):
    """
    Sets up the database by running django's syncdb command

    @param project_dir The directory containing manage.py
    @param production Whether to use production settings
    """
    puts(info="Running syncdb")
    with prefix(activate_venv()):
        if production == True:
            run(os.path.join(project_dir, 'manage.py') + " syncdb "
                "--settings=settings_production")
        else:
            run(os.path.join(project_dir, 'manage.py') + ' syncdb')

    puts(success='Database synced')
Beispiel #11
0
def django_syncdb(project_dir, production=False):
    """
    Sets up the database by running django's syncdb command

    @param project_dir The directory containing manage.py
    @param production Whether to use production settings
    """
    puts(info="Running syncdb")
    with prefix(activate_venv()):
        if production == True:
            run(
                os.path.join(project_dir, 'manage.py') + " syncdb "
                "--settings=settings_production")
        else:
            run(os.path.join(project_dir, 'manage.py') + ' syncdb')

    puts(success='Database synced')
Beispiel #12
0
def django_migrate_schema(project_dir, production=False):
    """
    Migrates the database schema

    @param project_dir The directory containing manage.py
    @param production Whether to use production settings
    """
    puts(info="Applying migrations")
    with prefix(activate_venv()):
        if production == True:
            run(
                os.path.join(project_dir, 'manage.py') + " migrate --all "
                "--settings=settings_production")
        else:
            run(os.path.join(project_dir, 'manage.py') + ' migrate --all')

    puts(success="Migrations applied")
Beispiel #13
0
def django_load_fixture(project_dir, path):
    """
    Load fixtures from a specific location

    @param project_dir The directory containing manage.py
    @param production The path to the fixture file to load
    """
    puts(info="Loading fixture at %s" % path)

    full_path = os.path.join(project_dir, path)

    if not files.exists(full_path):
        puts(error='Fixture file %s not found' % full_path)

    with prefix(activate_venv()):
        run(os.path.join(project_dir, 'manage.py') + " loaddata " + full_path)

    puts(success='Fixture loaded')
Beispiel #14
0
def django_load_fixture(project_dir, path):
    """
    Load fixtures from a specific location

    @param project_dir The directory containing manage.py
    @param production The path to the fixture file to load
    """
    puts(info="Loading fixture at %s" % path)

    full_path = os.path.join(project_dir, path)

    if not files.exists(full_path):
        puts(error='Fixture file %s not found' % full_path)

    with prefix(activate_venv()):
        run(os.path.join(project_dir, 'manage.py') + " loaddata "
            + full_path)

    puts(success='Fixture loaded')
Beispiel #15
0
def backup_database(project_name, project_dir, destination_dir):
    """
    Backs-up the database
    """
    dump_file = "%s-prod-%s.sql" % (project_name,
                                    datetime.now().strftime('%Y%m%d_%H%M%S'))

    temp_dump_path = os.path.join('/tmp', dump_file)

    puts(info="Backing up database")

    with prefix(activate_venv()):
        with cd(project_dir):
            DATABASE_USER = run(
                "python -c 'import settings_production;"
                "print settings_production.DATABASES[\"default\"][\"USER\"]'")
            DATABASE_PASSWORD = run(
                "python -c 'import settings_production;"
                "print settings_production.DATABASES[\"default\"][\"PASSWORD\"]'"
            )
            DATABASE_NAME = run(
                "python -c 'import settings_production;"
                "print settings_production.DATABASES[\"default\"][\"NAME\"]'")

    run('unset HISTFILE && mysqldump -u %s -p%s %s > %s' %
        (DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME, temp_dump_path))
    puts(success="Database backed up to %s" % temp_dump_path)

    puts(info="Compressing database backup")
    run('bzip2 %s' % temp_dump_path)
    temp_dump_path += '.bz2'
    puts(success="Database backup compressed")

    puts(info="Moving backup to %s" % destination_dir)
    with settings(warn_only=True):
        if sudo("test -d %s" % destination_dir).failed:
            puts(info="Creating destination directory %s" % destination_dir)
            create_directories(destination_dir, 'root')
            puts(success="Destination directory created")
    sudo('mv %s %s' % (temp_dump_path, destination_dir))
    puts(success="Database moved to %s" % destination_dir)
Beispiel #16
0
def backup_database(project_name, project_dir, destination_dir):
    """
    Backs-up the database
    """
    dump_file = "%s-prod-%s.sql" % (project_name,
        datetime.now().strftime('%Y%m%d_%H%M%S'))

    temp_dump_path = os.path.join('/tmp', dump_file)

    puts(info="Backing up database")

    with prefix(activate_venv()):
        with cd(project_dir):
            DATABASE_USER = run("python -c 'import settings_production;"
                "print settings_production.DATABASES[\"default\"][\"USER\"]'")
            DATABASE_PASSWORD = run("python -c 'import settings_production;"
                "print settings_production.DATABASES[\"default\"][\"PASSWORD\"]'")
            DATABASE_NAME = run("python -c 'import settings_production;"
                "print settings_production.DATABASES[\"default\"][\"NAME\"]'")

    run('unset HISTFILE && mysqldump -u %s -p%s %s > %s' % (
        DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME, temp_dump_path))
    puts(success="Database backed up to %s" % temp_dump_path)

    puts(info="Compressing database backup")
    run('bzip2 %s' % temp_dump_path)
    temp_dump_path += '.bz2'
    puts(success="Database backup compressed")

    puts(info="Moving backup to %s" % destination_dir)
    with settings(warn_only=True):
        if sudo("test -d %s" % destination_dir).failed:
            puts(info="Creating destination directory %s" % destination_dir)
            create_directories(destination_dir, 'root')
            puts(success="Destination directory created")
    sudo('mv %s %s' % (temp_dump_path, destination_dir))
    puts(success="Database moved to %s" % destination_dir)