예제 #1
0
def update_project(skip_test="true", target_dir='tolong'):
    """ Updates the source directory with most recent code, create migration
    and then restarts the webserver """
    setup_env(target_dir)
    if skip_test != "true":
        run_test()

    check_django_shell()

    # update temporary source code first, so we can know whether migration has addition
    # or deletion
    update_source_code(path=env.TEMP_SRC_PATH)
    symlink_settings_local()
    install_project_requirements(os.path.join(env.TEMP_SRC_PATH, 'requirements.txt'))

    migration_type = check_migration_type()
    if migration_type == "update_source_then_migrate":
        update_source_code()
        collect_static()
        # compress_static()
        restart_webserver()
        migrate()
        return
    elif migration_type == "migrate_then_update_source":
        # Migrate from temporary first
        migrate(env.TEMP_SRC_PATH)
        #  then normal stuff without migration again
        update_source_code()
    elif migration_type is None:
        update_source_code()

    collect_static()
    # compress_static()
    restart_webserver()
예제 #2
0
def deploy_project(target_dir='mentawai'):
    """ Deploys a project for the first time """
    # setup_env(target_dir)

    # if exists("%s" % env.PROJECT_PATH):
    #     abort('Project already deployed. Run "fab update_project -H <host>" instead')

    # setup_os()
    # require.files.directory(env.PROJECT_PATH, use_sudo=True,
    #                         owner='www-data', group='www-data')
    # update_source_code()
    # setup_virtualenv()
    # log_dir = os.path.join(env.PROJECT_PATH, 'logs')
    # require.files.directory(log_dir, use_sudo=True,
    #                         owner='www-data', group='www-data')
    # setup_webserver()

    # TODO: Create DB is broken
    # create_db()

    # TODO: Settings_local preparation is broken
    # context = {
    # 'db_name': env.db_name,
    # 'db_user': env.db_user,
    # 'db_pass': env.db_pass,
    # }
    # sudo('mv %ssettings_local.py.tpl %s/%s/settings_local.py' %
    # (env.HOME_PATH, env.SRC_PATH, env.PROJECT_NAME))
    # install_project_requirements()
    # install_front_end_requirements()
    # collect_static()
    # compress_static()
    sudo('chown -R www-data.www-data %s' % env.PROJECT_PATH)
    migrate()
예제 #3
0
def update_project(skip_test="true", target_dir='tolong'):
    """ Updates the source directory with most recent code, create migration
    and then restarts the webserver """
    setup_env(target_dir)
    if skip_test != "true":
        run_test()

    check_django_shell()

    # update temporary source code first, so we can know whether migration has addition
    # or deletion
    update_source_code(path=env.TEMP_SRC_PATH)
    symlink_settings_local()
    install_project_requirements(os.path.join(env.TEMP_SRC_PATH, 'requirements.txt'))

    migration_type = check_migration_type()
    if migration_type == "update_source_then_migrate":
        update_source_code()
        collect_static()
        # compress_static()
        restart_webserver()
        migrate()
        return
    elif migration_type == "migrate_then_update_source":
        # Migrate from temporary first
        migrate(env.TEMP_SRC_PATH)
        #  then normal stuff without migration again
        update_source_code()
    elif migration_type is None:
        update_source_code()

    collect_static()
    # compress_static()
    restart_webserver()
예제 #4
0
def update_project(skip_test="true",
                   target_dir='overtime',
                   init_module='systemd'):
    """ Updates the source directory with most recent code, create migration
    and then restarts the webserver """
    setup_env(target_dir)
    if skip_test != "true":
        run_test()

    # Determine which init system to use
    if init_module == 'systemd':
        init_module = systemd
    else:
        init_module = service

    check_django_shell()

    # update temporary source code first, so we can know whether migration has addition
    # or deletion
    update_source_code(path=env.TEMP_SRC_PATH)
    symlink_settings_local()
    install_project_requirements(
        os.path.join(env.TEMP_SRC_PATH, 'requirements.txt'))

    # migration_type = check_migration_type()
    # if migration_type == "update_source_then_migrate":
    update_source_code()
    # Update & Reload all before migrating code
    # install_front_end_requirements()
    collect_static()
    # compress_static()
    # copy_email_templates()
    # init_module.restart("nindya")
    # if target_dir == 'nindya':
    #     init_module.restart('rqworker')
    #     init_module.restart('rqworker-elastic')
    #     with settings(warn_only=True):
    #         init_module.restart('rqworker2')
    migrate()
    #     return
    # elif migration_type == "migrate_then_update_source":
    #     # Migrate from temporary first
    #     migrate(env.TEMP_SRC_PATH)
    #     #  then normal stuff without migration again
    #     update_source_code()
    # elif migration_type is None:
    #     update_source_code()

    # install_front_end_requirements()
    collect_static()
    # compress_static()
    # copy_email_templates()

    init_module.restart("overtime")
    # if target_dir == 'nindya':
    init_module.restart('rqworker')
예제 #5
0
def _migrate():
    from migrations import get_migrations
    schema = SchemaVersion.get_or_insert('current')
    old_version = schema.version
    if request.method == 'POST' and 'fGo' in request.form:
        from migrations import migrate
        migrate(schema)
        return render_template('_migrate_result.html', schema=schema, old_version=old_version)
    elif 'fCancel' in request.form:
        return redirect(url_for('index'))
    return render_template('_migrate.html', schema=schema, migrations=get_migrations()[schema.version+1:])
예제 #6
0
파일: deploy.py 프로젝트: vivinisna/tolong
def deploy_project(target_dir='tolong'):
    """ Deploys a project for the first time """
    setup_env(target_dir)

    if exists("%s" % env.PROJECT_PATH):
        abort(
            'Project already deployed. Run "fab update_project -H <host>" instead'
        )

    setup_os()
    require.files.directory(env.PROJECT_PATH,
                            use_sudo=True,
                            owner='www-data',
                            group='www-data')
    update_source_code(deploy=True)
    setup_virtualenv()
    log_dir = os.path.join(env.PROJECT_PATH, 'logs')
    require.files.directory(log_dir,
                            use_sudo=True,
                            owner='www-data',
                            group='www-data')
    setup_webserver()
    create_db()
    context = {
        'db_name': env.db_name,
        'db_user': env.db_user,
        'db_pass': env.db_pass,
    }
    upload_template('fabfiles/conf_templates/settings_local.py.tpl',
                    env.HOME_PATH,
                    context=context)
    sudo('mv %ssettings_local.py.tpl %s/%s/settings_local.py' %
         (env.HOME_PATH, env.SRC_PATH, env.PROJECT_NAME))
    install_project_requirements()
    collect_static()
    # compress_static()
    sudo('chown -R www-data:www-data %s' % env.PROJECT_PATH)
    sudo('{0} syncdb'.format(env.MANAGE_BIN))
    migrate()
    '''
    print("""Finished deployment. Now you need to:\n
      1. Edit your %s/settings_local.py file\n
      2. Run "fab create_initial_migration -H <host>"\n
      3. Connect to server and run "%s manage.py syncdb" from %ssrc\n
      4. Run "fab migrate -H <host>"\n
      5. Run "fab collect_static -H <host>" """ %
        (env.SRC_PATH, env.PYTHON_BIN, env.PROJECT_PATH))
    '''
    restart_webserver()
예제 #7
0
def _migrate():
    from migrations import get_migrations
    schema = SchemaVersion.get_or_insert('current')
    old_version = schema.version
    if request.method == 'POST' and 'fGo' in request.form:
        from migrations import migrate
        migrate(schema)
        return render_template('_migrate_result.html',
                               schema=schema,
                               old_version=old_version)
    elif 'fCancel' in request.form:
        return redirect(url_for('index'))
    return render_template('_migrate.html',
                           schema=schema,
                           migrations=get_migrations()[schema.version + 1:])
예제 #8
0
파일: db.py 프로젝트: CDAT/cdatgui
def connect():
    global __dbconn__
    if __dbconn__ is None:
        dotdir = os.path.expanduser("~/.uvcdat")
        path = os.path.expanduser(os.path.join(dotdir, "cdatgui_%s.db" %
                                  cdatgui.info.version))
        if os.path.exists(path):
            engine = create_engine("sqlite:///%s" % path)
        else:
            # Find highest version
            version = (0, 0, '')
            for f in os.listdir(dotdir):
                v = db_version(f)
                version = db_version_greater(v, version)

            if version == (0, 0, ''):
                # Clean .uvcdat directory
                engine = create_db(path)
            else:
                # Found an older DB
                old_path = os.path.join(dotdir, "cdatgui_%d.%d%s.db" % version)
                # Do custom migrations
                engine = migrations.migrate(old_path, path)

        __dbconn__ = sessionmaker(bind=engine)
    return __dbconn__()
예제 #9
0
def deploy_project(target_dir='tolong'):
    """ Deploys a project for the first time """
    setup_env(target_dir)

    if exists("%s" % env.PROJECT_PATH):
        abort('Project already deployed. Run "fab update_project -H <host>" instead')

    setup_os()
    require.files.directory(env.PROJECT_PATH, use_sudo=True,
                            owner='www-data', group='www-data')
    update_source_code(deploy=True)
    setup_virtualenv()
    log_dir = os.path.join(env.PROJECT_PATH, 'logs')
    require.files.directory(log_dir, use_sudo=True,
                            owner='www-data', group='www-data')
    setup_webserver()
    create_db()
    context = {
        'db_name': env.db_name,
        'db_user': env.db_user,
        'db_pass': env.db_pass,
    }
    upload_template('fabfiles/conf_templates/settings_local.py.tpl',
                    env.HOME_PATH, context=context)
    sudo('mv %ssettings_local.py.tpl %s/%s/settings_local.py' %
         (env.HOME_PATH, env.SRC_PATH, env.PROJECT_NAME))
    install_project_requirements()
    collect_static()
    # compress_static()
    sudo('chown -R www-data:www-data %s' % env.PROJECT_PATH)
    sudo('{0} syncdb'.format(env.MANAGE_BIN))
    migrate()
    '''
    print("""Finished deployment. Now you need to:\n
      1. Edit your %s/settings_local.py file\n
      2. Run "fab create_initial_migration -H <host>"\n
      3. Connect to server and run "%s manage.py syncdb" from %ssrc\n
      4. Run "fab migrate -H <host>"\n
      5. Run "fab collect_static -H <host>" """ %
        (env.SRC_PATH, env.PYTHON_BIN, env.PROJECT_PATH))
    '''
    restart_webserver()
예제 #10
0
from Database import Database
from Scraper import Scraper
from migrations import migrate

migrate()  # runs all migrations, only new migrations are executed

database = Database()  # create db connection

product_ids = Database.get_product_ids(
    database)  # get product_ids from database

for product_id in product_ids:  # for each product
    url = Database.get_url(database, product_id)  # get url from database
    price = Scraper.get_price(url)  # scrape current price from web
    Database.insert_price(database, product_id, price)  # insert price in db
예제 #11
0
from migrations import migrate

migrate("""
ALTER TABLE season ADD COLUMN done bool;
ALTER TABLE season ALTER COLUMN done set DEFAULT false;
UPDATE season set done = false;
""")