Ejemplo n.º 1
0
def main(argv: t.List[str]=sys.argv):
    """Create a new site user from command line.

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

    config_uri = get_config_uri(argv)

    request = init_websauna(config_uri)
    email = argv[2]
    is_admin = True if '--admin' in argv else False
    password = argv[3] if len(argv) >= 4 and argv[3] != '--admin' else ''

    if not password:
        password = getpass.getpass('Password:'******'Password (again):')
        if password != password2:
            feedback_and_exit('Passwords did not match', display_border=False)

    with request.tm:
        u = create(request, email=email, username=email, password=password, admin=is_admin)
        message = 'Created user #{id}: {email}, admin: {is_admin}'.format(
            id=u.id,
            email=u.email,
            is_admin=u.is_admin()
        )

    feedback_and_exit(message, status_code=None, display_border=True)
Ejemplo n.º 2
0
def usage_message(argv: t.List[str]):
    """Display usage message and exit.

    :param argv: Command line arguments.
    :raises sys.SystemExit:
    """
    cmd = os.path.basename(argv[0])
    msg = ('usage: {cmd} <config_uri> -- worker\n'
           '(example: "{cmd} ws://conf/production.ini -- worker")').format(
               cmd=cmd)
    feedback_and_exit(msg, status_code=1, display_border=False)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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))
Ejemplo n.º 6
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)