Example #1
0
def _createdb(dbname, owner):
    """Creates a database."""
    sql = "CREATE DATABASE %s WITH ENCODING 'UTF8' OWNER %s" % (dbname, owner)
    with running_db():
        run_cmd(psqlparams(sql, database='postgres'),
                'Creating database',
                user='******')
Example #2
0
def _setpwd(username, password):
    """Sets the password for the given user."""

    sql = "ALTER USER %s WITH PASSWORD '%s'" % (username, password)

    with running_db():
        run_cmd(psqlparams(sql), 'Setting password', user='******')
Example #3
0
def _setpwd(username, password):
    """Sets the password for the given user."""

    sql = "ALTER USER %s WITH PASSWORD '%s'" % (username, password)

    with running_db():
        run_cmd(psqlparams(sql), 'Setting password', user='******')
Example #4
0
def run():
    ensure_dir('/data/static', owner='developer', group='developer')
    ensure_dir('/data/static/react', owner='developer', group='developer')
    run_cmd(['npm', 'config', 'set', 'static_root',
             getvar('STATIC_ROOT')],
            user='******')
    run_daemon(['npm', 'install'], user='******', exit_on_finish=False)
Example #5
0
def _createuser(username, password):
    """Creates a user with the given password."""

    sql = "CREATE USER %s WITH PASSWORD '%s'" % (username, password)

    with running_db():
        run_cmd(psqlparams(sql), 'Creating user', user='******')
Example #6
0
def _restore(backupname, user, database, do_backup=True):
    """
    Recreates the database from a backup file. Will drop the
    original database.
    Creates a backup if do_backup is True.
    """

    filename = os.path.join(BACKUP_DIR, backupname)
    if not os.path.isfile(filename):
        click.secho('File %s does not exist.' % filename, fg='red')
        sys.exit(1)

    with running_db():
        if do_backup:
            backupname = 'pre_restore_%s' % int(time.time())
            _backup(backupname, user, database)

        sql = 'DROP DATABASE %s;' % database

        run_cmd(psqlparams(sql),
                message='Dropping database %s' % database,
                user=USER_NAME)

        _createdb(database, user)

        run_cmd(psqlparams() + ['-f', filename],
                message='Restoring',
                user=USER_NAME)
Example #7
0
def start_worker(podcast=None):
    cmd = ['django-admin.py', 'scrap',
           '--batch', os.environ['SCRAP_BATCH'],
           '--batch-interval', os.environ['SCRAP_BATCH_INTERVAL']]
    if podcast is not None:
        cmd += ['--podcast', podcast]
    run_cmd(cmd, user='******')
Example #8
0
def _createuser(username, password):
    """Creates a user with the given password."""

    sql = "CREATE USER %s WITH PASSWORD '%s'" % (username, password)

    with running_db():
        run_cmd(psqlparams(sql), 'Creating user', user='******')
Example #9
0
def _createdb(dbname, owner):
    """Creates a database."""

    sql = "CREATE DATABASE %s WITH ENCODING 'UTF8' OWNER %s"
    sql = sql % (dbname, owner)

    with running_db():
        run_cmd(psqlparams(sql), 'Creating database', user='******')
Example #10
0
def _createdb(dbname, owner):
    sql = "CREATE DATABASE %s WITH ENCODING 'UTF8' OWNER %s"
    sql = sql % (dbname, owner)

    with running_db():
        run_cmd(psqlparams(sql),
                'Creating database %s' % dbname,
                user=USER_NAME)
Example #11
0
def _createschema(schemaname, dbname, owner):
    sql = "CREATE SCHEMA %s AUTHORIZATION %s"
    sql = sql % (schemaname, owner)

    with running_db():
        run_cmd(psqlparams(sql, database=dbname),
                'Creating schema %s' % schemaname,
                user=USER_NAME)
Example #12
0
def _createschema(schemaname, dbname, owner):
    """Creates a database."""

    sql = "CREATE SCHEMA %s AUTHORIZATION %s"
    sql = sql % (schemaname, owner)

    with running_db():
        run_cmd(psqlparams(sql, database=dbname),
                'Creating schema',
                user='******')
Example #13
0
def _createschema(schemaname, dbname, owner):
    """Creates a database."""

    sql = "CREATE SCHEMA %s AUTHORIZATION %s"
    sql = sql % (schemaname, owner)

    with running_db():
        run_cmd(psqlparams(sql, database=dbname),
                'Creating schema',
                user='******')
Example #14
0
def _createuser(username, password):
    """Creates a user with the given password."""

    password = md5(username, password)
    sql = "CREATE USER %s WITH PASSWORD '%s'" % (username, password)

    with running_db():
        run_cmd(psqlparams(sql),
                'Creating user %s' % username,
                user=USER_NAME)
Example #15
0
def _setpwd(username, password):
    """Sets the password for the given user."""

    password = md5(username, password)
    sql = "ALTER USER %s WITH PASSWORD '%s'" % (username, password)

    with running_db():
        run_cmd(psqlparams(sql),
                'Setting password for %s' % username,
                user=USER_NAME)
def _restore(backupname):
    filename = os.path.join(BACKUP_DIR, backupname)
    if not os.path.isfile(filename):
        click.secho('File %s does not exist.' % filename, fg='red')
        sys.exit(1)

    with running_db():
        run_cmd(['psql', '-h', SOCKET_DIR, '-c', 'DROP DATABASE django'],
                message='Dropping database django', user='******')

        _createdb('django', 'postgres')
        run_cmd(psqlparams() + ['-f', filename],  message='Restoring',
                user='******')
Example #17
0
def _clear(confirm=True):
    """
    Removes all files unker PGDATA. Backup is recommended!
    """
    if not os.path.isdir(PGDATA):
        return

    if confirm and not click.confirm('Are you absolutely sure?'):
        return

    if os.path.isfile(os.path.join(PGDATA, 'postmaster.pid')):
        click.secho('Database is running. Stop it before clear.', fg='red')
        sys.exit(1)

    run_cmd(['rm', '-rf', PGDATA], message='Removing directory %s' % PGDATA)
Example #18
0
def _restore(backupname):
    filename = os.path.join(BACKUP_DIR, backupname)
    if not os.path.isfile(filename):
        click.secho('File %s does not exist.' % filename, fg='red')
        sys.exit(1)

    with running_db():
        run_cmd(['psql', '-h', SOCKET_DIR, '-c', 'DROP DATABASE django'],
                message='Dropping database django',
                user='******')

        _createdb('django', 'postgres')
        run_cmd(psqlparams() + ['-f', filename],
                message='Restoring',
                user='******')
Example #19
0
def _clear(confirm=True):
    """
    Removes all files unker PGDATA. Backup is recommended!
    """
    if not os.path.isdir(PGDATA):
        return

    if confirm and not click.confirm('Are you absolutely sure?'):
        return

    if os.path.isfile(os.path.join(PGDATA, 'postmaster.pid')):
        click.secho('Database is running. Stop it before clear.', fg='red')
        sys.exit(1)

    run_cmd(['rm', '-rf', PGDATA],
            message='Removing directory %s' % PGDATA)
Example #20
0
def _restore(backupname, user, database, do_backup=True):
    """
    Recreatest the database from a backup file. Will drop the
    original database.
    Creates a backup if do_backup is True.
    """

    filename = os.path.join(BACKUP_DIR, backupname)
    if not os.path.isfile(filename):
        click.secho('File %s does not exist.' % filename, fg='red')
        sys.exit(1)

    with running_db():
        if do_backup:
            backupname = 'pre_restore_%s' % int(time.time())
            _backup(backupname, user, database)

        sql = 'DROP DATABASE %s;' % database

        run_cmd(psqlparams(sql),
                message='Dropping database %s' % database,
                user='******')

        sql = ("CREATE DATABASE %s "
               "WITH OWNER %s "
               "ENCODING 'UTF8'" % (database, user))
        run_cmd(psqlparams(sql),
                message='Creating database %s' % database,
                user='******')

        run_cmd(psqlparams() + ['-f', filename],
                message='Restoring',
                user='******')
Example #21
0
def init(stopper):
    ensure_dir('/data/static',
               owner='django', group='django', permsission_str='777')

    if not stopper.stopped:
        run_cmd(['django-admin', 'migrate'], user='******')

    if not stopper.stopped:
        run_cmd(['django-admin', 'collectstatic', '--noinput'], user='******')

    # This is mainly for demonstartive purposes, but can be handy in
    # development
    if stopper.stopped:
        return

    import django
    django.setup()
    from django.contrib.auth.models import User

    try:
        User._default_manager.create_superuser(
            'admin', '*****@*****.**', 'admin')
    except:
        click.echo('Superuser exists')
Example #22
0
def init(stopper):
    ensure_dir('/data/logs/django', owner='developer', group='developer')
    ensure_dir('/data/static', owner='developer', group='developer')

    if not stopper.stopped:
        if settings.DEBUG is False:
            cmd = ['django-admin', 'collectstatic', '--noinput', '-i', 'react']
            run_cmd(cmd, user='******')
            run_cmd(['django-admin', 'migrate'], user='******')

        # Create db cache
        if os.path.isfile('/data/.init') is False:
            run_cmd(['django-admin', 'migrate'], user='******')
            run_cmd(['django-admin', 'createcachetable', '-v', '0'],
                    user='******')
            with open("/data/.init", "a+") as f:
                f.write('')
Example #23
0
def rerun_worker(url, podcast=None):
    print(url)
    cmd = ['django-admin.py', 'scrap', '--url', url, '--podcast', podcast]
    run_cmd(cmd, user='******')
Example #24
0
def _initdb():
    """Initialize the database."""
    run_cmd(['initdb'], user='******', message='Initializing the database')
    _createdb('django', 'postgres')
Example #25
0
def run():
    ensure_dir('/data/static', owner='developer', group='developer')
    ensure_dir('/data/static/react', owner='developer', group='developer')
    run_cmd(['npm', 'config', 'set', 'static_root', getvar('STATIC_ROOT')],
            user='******')
    run_daemon(['npm', 'install'], user='******', exit_on_finish=False)
Example #26
0
def start_build():
    run_cmd(['npm', 'config', 'set', 'NODE_ENV', 'production'],
            user='******')
    run_cmd(['npm', 'run', 'build'], message="npm run build", user='******')
Example #27
0
# INIT: WILL RUN BEFORE ANY COMMAND AND START  #
def init(stopper):
    ensure_dir('/data/logs/', owner='developer', group='developer')
    ensure_dir('/data/logs/django', owner='developer', group='developer')
    ensure_dir('/data/static', owner='developer', group='developer')
    {% if cookiecutter.use_translation == 'True' -%}
    ensure_dir('/src/locale', owner='developer', group='developer')
    {%- endif %}
    if not stopper.stopped:
        if settings.DEBUG is False:
            {%- if cookiecutter.use_react == 'True' %}
            cmd = ['django-admin', 'collectstatic', '--noinput', '-i', 'react']
            {% else %}
            cmd = ['django-admin', 'collectstatic', '--noinput']
            {% endif -%}
            run_cmd(cmd, user='******')

        # Create db cache and other one time commands
        if os.path.isfile('/data/.init') is False:
            run_cmd(['django-admin', 'migrate'], user='******')
            run_cmd(['django-admin', 'createcachetable', '-v', '0'],
                    user='******')

            with open("/data/.init", "a+") as f:
                f.write(''){% if cookiecutter.use_translation == 'True' %}

        run_cmd(generate_makemessages_command('django'), user='******')
        run_cmd(generate_makemessages_command('djangojs'), user='******'){% endif %}


@click.group()
def _initdb():
    """Initialize the database."""
    run_cmd(['initdb'], user='******', message='Initializing the database')
    _createdb('django', 'postgres')
# INIT: WILL RUN BEFORE ANY COMMAND AND START  #
def init(stopper):
    ensure_dir('/data/logs/django', owner='developer', group='developer')
    ensure_dir('/data/static', owner='developer', group='developer')
    {% if cookiecutter.use_translation == 'True' -%}
    ensure_dir('/src/locale', owner='developer', group='developer')
    {%- endif %}

    if not stopper.stopped:
        if settings.DEBUG is False:
            {%- if cookiecutter.use_react == 'True' %}
            cmd = ['django-admin', 'collectstatic', '--noinput', '-i', 'react']
            {% else %}
            cmd = ['django-admin', 'collectstatic', '--noinput']
            {% endif -%}
            run_cmd(cmd, user='******')
            run_cmd(['django-admin', 'migrate'], user='******')

        # Create db cache
        if os.path.isfile('/data/.init') is False:
            run_cmd(['django-admin', 'migrate'], user='******')
            run_cmd(['django-admin', 'createcachetable', '-v', '0'],
                    user='******')
            with open("/data/.init", "a+") as f:
                f.write('')

        {% if cookiecutter.use_translation == 'True' -%}
        run_cmd(generate_makemessages_command('django'), user='******')
        run_cmd(generate_makemessages_command('djangojs'), user='******')
        {%- endif %}
Example #30
0
def start_build():
    run_cmd(['npm', 'config', 'set', 'NODE_ENV', 'production'],
            user='******')
    run_cmd(['npm', 'run', 'build'], message="npm run build", user='******')