Exemple #1
0
def main(argv: t.List[str] = sys.argv):
    """Wrapper for pgsql-dump.bash script.

    :param argv: Command line arguments, second one needs to be the uri to a configuration file.
    :raises sys.SystemExit:
    """
    if len(argv) < 2:
        usage_message(
            argv,
            additional_params='[ARG1, ARG2]',
            additional_line='All arguments are passed to pg_dump command')

    config_uri = get_config_uri(argv)
    request = init_websauna(config_uri)

    # Export all secrets and settings
    bash_env = create_settings_env(request.registry)

    # subprocess.check_output([DUMP_SCRIPT] + args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
    args = argv[2:]
    cmd = [DUMP_SCRIPT] + args

    logger.info("Running %s", " ".join(cmd))

    with subprocess.Popen(cmd,
                          stdout=subprocess.PIPE,
                          bufsize=1,
                          env=bash_env,
                          universal_newlines=True) as p:
        for line in p.stdout:
            print(line, end='')
Exemple #2
0
def main(argv: t.List[str]=sys.argv):
    """Read through all configured static views and compile their assets to ``collected-static`` folder.

    :param argv: Command line arguments, second one needs to be the uri to a configuration file.
    :raises sys.SystemExit:
    """
    if len(argv) < 2:
        usage_message(argv)

    config_uri = get_config_uri(argv)
    request = init_websauna(config_uri, sanity_check=False)
    request.registry.static_asset_policy.collect_static()
    feedback_and_exit('ws-collect-static: Collected all static assets', 0, True)
Exemple #3
0
def main(argv: t.List[str]=sys.argv):
    """Display settings for a given configuration file.

    :param argv: Command line arguments, second one needs to be the uri to a configuration file.
    :raises sys.SystemExit:
    """
    if len(argv) < 2:
        usage_message(argv)

    config_uri = get_config_uri(argv)

    request = init_websauna(config_uri, sanity_check=False)
    message = 'Active deployment settings in {config_uri}'.format(config_uri=config_uri)
    feedback(message)
    pprint(request.registry.settings)
    feedback_and_exit('', status_code=0, display_border=True)
Exemple #4
0
def main(argv: t.List[str] = sys.argv):
    """Create initial tables for the database specified on the configuration file.

    :param argv: Command line arguments, second one needs to be the uri to a configuration file.
    :raises sys.SystemExit:
    """
    if len(argv) < 2:
        usage_message(argv)

    config_uri = get_config_uri(argv)
    request = init_websauna(config_uri)

    with transaction.manager:
        engine = request.dbsession.get_bind()
        # Enable pgcrypto and implement a uuid_generate_v4 function
        engine.execute(UUID_SUPPORT_STMT)

        Base.metadata.create_all(engine)
Exemple #5
0
def main(argv: t.List[str] = sys.argv):
    """Execute a sanity check on the configuration.

    :param argv: Command line arguments, second one needs to be the uri to a configuration file.
    :raises sys.SystemExit:
    """
    if len(argv) < 2:
        usage_message(argv)

    config_uri = get_config_uri(argv)

    try:
        init_websauna(config_uri, sanity_check=True)
    except SanityCheckFailed as exc:
        feedback_and_exit(FAIL_MSG.format(exception=str(exc)), 10)
    except FileNotFoundError as exc:
        feedback_and_exit(NOT_FOUND_MSG.format(config_uri=config_uri), 10)

    feedback_and_exit(SUCCESS_MSG, 0)
Exemple #6
0
def main(argv: t.List[str] = sys.argv):
    """Print out sql statements needed to construct currently configured models.

    :param argv: Command line arguments, second one needs to be the uri to a configuration file.
    :raises sys.SystemExit:
    """
    if len(argv) < 2:
        usage_message(argv)

    config_uri = get_config_uri(argv)
    request = init_websauna(config_uri)
    engine = request.dbsession.get_bind()

    for name, cls in Base._decl_class_registry.items():

        if name == "_sa_module_registry":
            continue

        print(CreateTable(cls.__table__, bind=engine))
Exemple #7
0
def main(argv: t.List[str] = sys.argv):
    """Create initial tables for the database specified on the configuration file.

    :param argv: Command line arguments, second one needs to be the uri to a configuration file.
    :raises sys.SystemExit:
    """
    if len(argv) < 2:
        usage_message(argv)

    config_uri = get_config_uri(argv)
    request = init_websauna(config_uri)

    with transaction.manager:
        engine = request.dbsession.get_bind()
        # Always enable UUID extension for PSQL
        # TODO: Convenience for now, because we assume UUIDs, but make this somehow configurable
        engine.execute('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"')

        Base.metadata.create_all(engine)
Exemple #8
0
def main(argv: t.List[str]=sys.argv):
    """Run pgcli shell on the database specified on the configuration file.

    :param argv: Command line arguments, second one needs to be the uri to a configuration file.
    """
    if len(argv) < 2:
        usage_message(argv, additional_params='[var=value]')

    config_uri = get_config_uri(argv)
    request = init_websauna(config_uri)
    url = request.registry.settings.get('sqlalchemy.url')

    engine = request.dbsession.get_bind()

    if not which('pgcli'):
        message = 'pgcli is not installed\nPlease install Websauna as pip install websauna[utils] to get this dependency'
        feedback_and_exit(message, display_border=False)

    feedback('Connecting to {engine}'.format(engine=engine), display_border=False)
    os.system('pgcli {url}'.format(url=url))
Exemple #9
0
def main(argv: t.List[str] = sys.argv):
    """Execute the IPython shell prompt with Websauna configuration already initialised.

    :param argv: Command line arguments, second one needs to be the uri to a configuration file.
    :raises sys.SystemExit:
    """
    if len(argv) < 2:
        usage_message(argv, additional_params='[var=value]')

    config_uri = get_config_uri(argv)

    request = init_websauna(config_uri)

    imported_objects = OrderedDict()

    imported_objects["request"] = request
    imported_objects["dbsession"] = request.dbsession
    imported_objects["transaction"] = transaction
    imported_objects["redis"] = get_redis(request)
    imported_objects["now"] = now
    imported_objects["datetime"] = datetime

    for name, cls in Base._decl_class_registry.items():

        if name == "_sa_module_registry":
            continue

        imported_objects[name] = cls

    feedback('', False)
    feedback('Following classes and objects are available:', False)
    for var, val in imported_objects.items():
        line = "{key:30}: {value}".format(key=var,
                                          value=str(val).replace(
                                              '\n', ' ').replace('\r', ' '))
        feedback(line)
    feedback('', False)

    embed(user_ns=imported_objects)