Пример #1
0
def engine_from_settings(config, full_config=False):
    settings = get_appsettings(config, 'assembl')
    if settings['sqlalchemy.url'].startswith('virtuoso:'):
        db_schema = '.'.join((settings['db_schema'], settings['db_user']))
    else:
        db_schema = settings['db_schema']
    set_config(settings, True)
    session = None
    if full_config:
        env = bootstrap(config)
        configure_zmq(settings['changes_socket'], False)
        configure_indexing()
        configure_model_watcher(env['registry'], 'assembl')
        logging.config.fileConfig(config)
        session = get_session_maker()
        metadata = get_metadata()
    else:
        session = make_session_maker(zope_tr=True)
        import assembl.models
        from assembl.lib.sqla import class_registry
        engine = configure_engine(settings, session_maker=session)
        metadata = get_metadata()
        metadata.bind = engine
        session = sessionmaker(engine)()
    return (metadata, session)
Пример #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("configuration", help="The configuration of the application.", default="local.ini")
    args = parser.parse_args()
    env = bootstrap(args.configuration)
    settings = get_appsettings(args.configuration, 'assembl')
    set_config(settings)
    configure_zmq(settings['changes_socket'], False)
    configure_model_watcher(env['registry'], 'assembl')
    _ = configure_engine(settings, True)
    try:
        from assembl.graphql.schema import Schema, generate_schema_json_from_schema
        generate_schema_json_from_schema(Schema, spec_wrap=True)

    except Exception as _:
        traceback.print_exc()
        pdb.post_mortem()
Пример #3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "configuration",
        help="configuration file with destination database configuration")
    args = parser.parse_args()
    env = bootstrap(args.configuration)
    settings = get_appsettings(args.configuration, 'assembl')
    set_config(settings)
    logging.config.fileConfig(args.configuration)
    configure_zmq(settings['changes_socket'], False)
    configure_indexing()
    configure_engine(settings, True)
    session = get_session_maker()()
    try:
        reindex_all_contents(session)
        transaction.commit()
    except Exception as e:
        traceback.print_exc()
        pdb.post_mortem()
Пример #4
0
                     help="This table will be rebuilt.")
 parser.add_argument("-k", "--rebuild_table_fkey", action="append", default=[],
                     help="This table's fkeys will be rebuilt.")
 parser.add_argument("--rebuild_all_fkeys", action="store_true", default=False,
                     help="All tables fkeys will be rebuilt.")
 parser.add_argument("--rebuild_all_tables", action="store_true", default=False,
                     help="All tables will be rebuilt.")
 parser.add_argument("--ensure_inheritance", action="store_true", default=False,
                     help="Make sure no class has a missing subclass row.")
 parser.add_argument("-d", "--delete_missing", action="store_true", default=False,
                     help="Delete rows with missing corresponding values. (otherwise abort rebuild.)")
 parser.add_argument("--reset_extract_discussion", action="store_true", default=False,
                     help="Special case: rebuild a dependent foreign key on extract table")
 args = parser.parse_args()
 settings = get_appsettings(args.configuration, 'assembl')
 set_config(settings)
 logging.config.fileConfig(args.configuration)
 configure_zmq(settings['changes_socket'], False)
 configure_indexing()
 configure_engine(settings, True)
 session = get_session_maker()()
 import assembl.models
 try:
     if (args.reset_extract_discussion and
             session.query(assembl.models.Extract).filter_by(discussion_id=-1).count()):
         session.execute("""UPDATE "extract" SET discussion_id = (
             SELECT content.discussion_id FROM content
                 JOIN idea_content_link on (content_id=content.id)
                 JOIN "extract" on ("extract".id = idea_content_link.id)
                 WHERE "extract".discussion_id=-1)""")
     if args.rebuild_all_tables:
Пример #5
0
from pyramid.paster import get_appsettings
import requests
import transaction

from assembl.lib.sqla import (configure_engine, get_session_maker)
from assembl.lib.zmqlib import configure_zmq
from assembl.lib.config import set_config


def clean_avatars(db):
    from assembl.models import SocialAuthAccount
    with transaction.manager:
        for idp in db.query(SocialAuthAccount).filter(
                SocialAuthAccount.picture_url != None):
            url = idp.picture_url
            if not requests.head(url).ok:
                print "Not ok", idp.id, url
                idp.picture_url = None


if __name__ == '__main__':
    config_fname = sys.argv[1]
    settings = get_appsettings(config_fname, 'assembl')
    set_config(settings)
    logging.config.fileConfig(config_fname)
    configure_zmq(settings['changes.socket'], False)
    configure_engine(settings, True)
    session = get_session_maker()()
    clean_avatars(session)
Пример #6
0
    get_session_maker, configure_engine, get_metadata)
from assembl.lib.zmqlib import configure_zmq
from assembl.lib.config import set_config
from assembl.indexing.changes import configure_indexing
from assembl.lib.migration import bootstrap_db_data

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
_config = config.file_config._sections['app:assembl']
_config['in_migration'] = True
set_config(_config)
pyramid_env = bootstrap(config.config_file_name)
configure_zmq(pyramid_env['registry'].settings['changes_socket'], False)
configure_engine(pyramid_env['registry'].settings, False)
configure_indexing()


def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    session_maker = get_session_maker()
    engine = session_maker.bind
Пример #7
0
from assembl.lib.zmqlib import configure_zmq
from assembl.lib.config import set_config
from assembl.semantic import upgrade_semantic_mapping

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)

_settings = config.file_config._sections['app:assembl']
# Add a marker that we're in alembic, some things need not happen
_settings['in_alembic'] = True
set_config(_settings)
pyramid_env = bootstrap(config.config_file_name)
configure_zmq(pyramid_env['registry'].settings['changes.socket'], False)

configure_engine(pyramid_env['registry'].settings, False)


def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    engine = get_session_maker().bind
    connection = engine.connect()
Пример #8
0
from assembl.lib.sqla import (get_session_maker, configure_engine,
                              get_metadata)
from assembl.lib.zmqlib import configure_zmq
from assembl.lib.config import set_config
from assembl.semantic import upgrade_semantic_mapping

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)

set_config(config.file_config._sections['app:assembl'])
pyramid_env = bootstrap(config.config_file_name)
configure_zmq(pyramid_env['registry'].settings['changes.socket'], False)

configure_engine(pyramid_env['registry'].settings, False)


def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    engine = get_session_maker().bind
    connection = engine.connect()
Пример #9
0
def app_settings(request):
    from assembl.lib.config import set_config
    app_settings_file = request.config.getoption('test_settings_file')
    app_settings = get_appsettings(app_settings_file, 'assembl')
    set_config(app_settings)
    return app_settings
Пример #10
0
                              get_metadata, connection_url)
from assembl.lib.zmqlib import configure_zmq
from assembl.lib.config import set_config
from assembl.indexing.changes import configure_indexing
# from assembl.lib.migration import bootstrap_db_data

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
_config = config.get_section('app:assembl')
_config['in_migration'] = True
set_config(_config)
pyramid_env = bootstrap(config.config_file_name)
configure_zmq(pyramid_env['registry'].settings['changes_socket'], False)
configure_engine(pyramid_env['registry'].settings, False)
configure_indexing()


def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    session_maker = get_session_maker()
    engine = session_maker.bind
Пример #11
0
from assembl.lib.sqla import (
    get_session_maker, configure_engine, get_metadata)
from assembl.lib.zmqlib import configure_zmq
from assembl.lib.config import set_config
from assembl.semantic import upgrade_semantic_mapping

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)

set_config(config.file_config._sections['app:assembl'])
pyramid_env = bootstrap(config.config_file_name)
configure_zmq(pyramid_env['registry'].settings['changes.socket'], False)

configure_engine(pyramid_env['registry'].settings, False)

def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    engine = get_session_maker().bind
    connection = engine.connect()
    context.configure(connection=connection,