Exemple #1
0
def run_command(args, rc):
    from ambry.library import new_library
    from ambry.cli import global_logger

    try:
        l = new_library(rc)
        l.logger = global_logger
    except Exception as e:
        warn('No library: {}'.format(e))
        l = None

    args.subcommand(args, l, rc) # Note the calls to sp.set_defaults(subcommand=...)
Exemple #2
0
def run_command(args, rc):
    from ambry.library import new_library
    from ambry.cli import global_logger

    try:
        l = new_library(rc)
        l.logger = global_logger
    except Exception as e:
        warn('No library: {}'.format(e))
        l = None

    args.subcommand(args, l,
                    rc)  # Note the calls to sp.set_defaults(subcommand=...)
Exemple #3
0
def remove_user(args, l, rc):

    from ambry.orm.exc import NotFoundError

    try:
        account = l.account(args.user_name)

        if account.major_type != 'user':
            raise NotFoundError()

        l.delete_account(account)
        l.commit()

    except NotFoundError:
        warn("No account found for {}".format(args.user_name))
Exemple #4
0
def start_ui(args, l, rc):

    from ambry_ui import app
    import ambry_ui.views
    import ambry_ui.jsonviews
    import ambry_ui.api
    import ambry_ui.user
    import webbrowser
    import socket
    from ambry.util import random_string, set_url_part

    if args.use_proxy:
        from werkzeug.contrib.fixers import ProxyFix
        app.wsgi_app = ProxyFix(app.wsgi_app)

    if not args.debug:
        webbrowser.open("http://{}:{}".format(args.host, args.port))

    else:
        import logging
        import os
        logging.basicConfig(level=logging.DEBUG)
        log = logging.getLogger('werkzeug')
        log.setLevel(logging.DEBUG)

        os.environ["AMBRY_UI_DEBUG"] = 'true' # DOn't know why this needs to be done, but it does.
        #prt("Running at http://{}:{}".format(args.host, args.port))

    if not app.config.get('AMBRY_ADMIN_PASS') and not args.no_accounts:
        app.config['AMBRY_ADMIN_PASS'] = random_string(20)
        app.config['LOGGED_IN_USER'] = '******'
        l.logger.info("Setting admin password to: {}".format(app.config['AMBRY_ADMIN_PASS'] ))

    db_init(args,l,rc)

    try:

        app.config['SECRET_KEY'] = 'secret'  # To Ensure logins persist
        app.config["WTF_CSRF_SECRET_KEY"] = 'secret'
        app.run(host=args.host, port=int(args.port), debug=args.debug)
    except socket.error as e:
        warn("Failed to start ui: {}".format(e))
Exemple #5
0
def user_admin(args, l, rc):
    """Add or update a user"""

    from ambry.orm.exc import NotFoundError

    try:
        account = l.account(args.user_name)

        if account.major_type != 'user':
            raise NotFoundError()

        if args.remove:
            account.minor_type = None
        else:
            account.minor_type = 'admin'

        l.commit()

    except NotFoundError:
        warn("No account found for {}".format(args.user_name))