Exemplo n.º 1
0
def prompt_to_create_first_account():
    '''
    Asks whether a user wants to create an account
    (called when the database has no users)
    '''
    from tensorhive.core.utils.AccountCreator import AccountCreator
    click.echo('Database has no users.')
    if click.confirm('Would you like to create a user account?', default=True):
        AccountCreator().run_prompt()
Exemplo n.º 2
0
def init():
    """Entry point for semi-automatic configuration process."""
    from tensorhive.config import CONFIG_FILES
    from tensorhive.config import config as main_config
    from tensorhive.core.utils.AccountCreator import AccountCreator
    from inspect import cleandoc
    from tensorhive.database import ensure_db_with_current_schema
    from tensorhive.models.User import User
    from tensorhive.models.Group import Group
    from tensorhive.models.Restriction import Restriction
    setup_logging(log_level=logging.INFO)

    logging.info('[•] Initializing configuration...')

    # Exposed host
    if click.confirm(
            '[1/3] Do you want TensorHive to be accessible to other users in your network?'
    ):
        host = click.prompt(
            '[1/3] What is the public hostname/address of this node (which is visible by all end users)?'
        )
    else:
        host = '0.0.0.0'
    main_config.set('api', 'url_hostname', host)
    with open(CONFIG_FILES.MAIN_CONFIG_PATH, 'w') as main_config_file:
        main_config.write(main_config_file)
    click.echo(green('[⚙] TensorHive will be accessible via: {}'.format(host)))

    ensure_db_with_current_schema()

    # First user account
    if User.query.count() == 0:
        if click.confirm('[2/3] ' + orange('Database has no users.') +
                         ' Would you like to create an account now?',
                         default=True):
            AccountCreator().run_prompt()
    else:
        click.echo(
            '[•] There are some users in the database already, skipping...')

    # Edit configs
    click.echo('[3/3] ' + green('Done ✔!') +
               ' Now you just need to adjust these configs to your needs:\n')
    click.echo(
        cleandoc('''
        (required) {hosts}
        (optional) {main}
        (optional) {mailbot}
    ''').format(hosts=orange(CONFIG_FILES.HOSTS_CONFIG_PATH),
                main=CONFIG_FILES.MAIN_CONFIG_PATH,
                mailbot=CONFIG_FILES.MAILBOT_CONFIG_PATH))
Exemplo n.º 3
0
def user(multiple):
    from tensorhive.core.utils.AccountCreator import AccountCreator
    creator = AccountCreator()
    # Create one user
    creator.run_prompt()

    # Create more users
    while multiple:
        creator.run_prompt()