コード例 #1
0
ファイル: db_manage.py プロジェクト: yyang42/assembl
def main():
    parser = argparse.ArgumentParser(
        description="Manage database bootstrap, backup and update.")
    parser.add_argument("configuration", help="configuration file")
    parser.add_argument("command",
                        help="command",
                        choices=['bootstrap', 'backup', 'alembic'])
    parser.add_argument('alembic_args', nargs='*')
    args = parser.parse_args()
    settings = get_appsettings(args.configuration, 'assembl')
    set_config(settings)
    configure_zmq(settings['changes.socket'], False)
    engine = configure_engine(settings, True)
    admin_engine = engine
    from assembl.lib.sqla import using_virtuoso
    if using_virtuoso():
        admin_engine = create_engine_sqla('virtuoso://*****:*****@VOSU')
    else:
        admin_engine = engine
    if args.command == "bootstrap":
        SessionMaker = sessionmaker(admin_engine)
        session = SessionMaker()
        if using_virtuoso() and not session.execute(
                "select count(*) from db..sys_users"
                " where u_name = '%(db_user)s'" % settings).scalar():
            for i in init_instructions:
                session.execute(i % settings)
            session.commit()
        db = bootstrap_db(args.configuration)
        bootstrap_db_data(db)
        mark_changed()
        transaction.commit()

    elif args.command == "backup":
        admin_engine.execute("backup_context_clear()")

        filename_prefix = 'assembl-virtuoso-backup'  # % time.strftime('%Y%m%d%H%M%S')
        #virtuoso will add this suffix to the filename no matter what we do
        virtuoso_suffix = "1.bp"
        # Unfortunately adding , 3600, vector('"+os.getcwd()+"') typically
        # doesn't work as forbidden by default virtuoso configuration.
        admin_engine.execute("backup_online('" + filename_prefix +
                             "', 524288)")

        sys.stdout.write(filename_prefix + virtuoso_suffix + '\n')
    elif args.command == "alembic":
        context = MigrationContext.configure(engine.connect())
        db_version = context.get_current_revision()

        if not db_version:
            sys.stderr.write('Database not initialized.\n'
                             'Try this: "assembl-db-manage %s bootstrap"\n' %
                             args.configuration)
            sys.exit(2)

        cmd = ['alembic', '-c', args.configuration] + args.alembic_args

        print(subprocess.check_output(cmd))
コード例 #2
0
ファイル: db_manage.py プロジェクト: festrade/assembl
def main():
    parser = argparse.ArgumentParser(description="Manage database bootstrap, backup and update.")
    parser.add_argument("configuration", help="configuration file")
    parser.add_argument("command", help="command",  choices=['bootstrap', 'backup', 'alembic'])
    parser.add_argument('alembic_args', nargs='*')
    args = parser.parse_args()
    settings = get_appsettings(args.configuration, 'assembl')
    set_config(settings)
    configure_zmq(settings['changes.socket'], False)
    engine = configure_engine(settings, True)
    admin_engine = engine
    from assembl.lib.sqla import using_virtuoso
    if using_virtuoso():
        admin_engine = create_engine_sqla('virtuoso://*****:*****@VOSU')
    else:
        admin_engine = engine
    if args.command == "bootstrap":
        SessionMaker = sessionmaker(admin_engine)
        session = SessionMaker()
        if using_virtuoso() and not session.execute(
                "select count(*) from db..sys_users"
                " where u_name = '%(db_user)s'" % settings).scalar():
            for i in init_instructions:
                session.execute(i % settings)
            session.commit()
        db = bootstrap_db(args.configuration)
        bootstrap_db_data(db)
        mark_changed()
        transaction.commit()

    elif args.command == "backup":
        admin_engine.execute("backup_context_clear()")
        
        filename_prefix = 'assembl-virtuoso-backup' # % time.strftime('%Y%m%d%H%M%S')
        #virtuoso will add this suffix to the filename no matter what we do
        virtuoso_suffix = "1.bp"
        # Unfortunately adding , 3600, vector('"+os.getcwd()+"') typically
        # doesn't work as forbidden by default virtuoso configuration.
        admin_engine.execute("backup_online('"+filename_prefix+"', 524288)")
        
        sys.stdout.write(filename_prefix+virtuoso_suffix+'\n')
    elif args.command == "alembic":
        context = MigrationContext.configure(engine.connect())
        db_version = context.get_current_revision()

        if not db_version:
            sys.stderr.write('Database not initialized.\n'
                             'Try this: "assembl-db-manage %s bootstrap"\n'
                             % args.configuration)
            sys.exit(2)

        cmd = ['alembic', '-c', args.configuration] + args.alembic_args

        print(subprocess.check_output(cmd))
コード例 #3
0
ファイル: db_manage.py プロジェクト: hellsingblack/assembl
def main():
    if len(sys.argv) < 3:
        sys.stderr.write('Usage: %s CONFIG_URI {bootstrap | ALEMBIC_OPTS}\n'
                         % sys.argv[0])
        sys.exit(1)

    config_uri = sys.argv.pop(1)

    settings = get_appsettings(config_uri)
    configure_zmq(settings['changes.socket'], False)
    engine = configure_engine(settings, True)
    if sys.argv[1] == 'bootstrap':
        admin_engine = create_engine_sqla('virtuoso://*****:*****@VOSU')
        SessionMaker = sessionmaker(admin_engine)
        session = SessionMaker()
        if not session.execute(
                "select count(*) from db..sys_users"
                " where u_name = '%(db_user)s'" % settings).scalar():
            for i in init_instructions:
                session.execute(i % settings)
            session.commit()
        bootstrap_db(config_uri)
        mark_changed()
        transaction.commit()
    else:
        context = MigrationContext.configure(engine.connect())
        db_version = context.get_current_revision()

        if not db_version:
            sys.stderr.write('Database not initialized.\n'
                             'Try this: "assembl-db-manage %s bootstrap"\n'
                             % config_uri)
            sys.exit(2)

        cmd = ['alembic', '-c', config_uri] + sys.argv[1:]

        print(subprocess.check_output(cmd))