Пример #1
0
def setup():
    """
    Creates/bootstraps the database.

    If you're a real developer you'll figure out how to remove the
    warning yourself. Don't merge any code the removes it.
    """
    is_devel = options.setup.startswith("dev")
    if is_devel:
        print("%sWARNING:%s Setup is in development mode %s" %
              (WARN + bold, W, WARN))
        message = "I know what the f**k I am doing"
        resp = input(PROMPT + 'Please type "%s": ' % message)
        if resp.replace('"', "").lower().strip() != message.lower():
            os._exit(1)
    else:
        is_devel = options.setup.startswith("docker")
    print(INFO + "%s : Creating the database ..." % current_time())
    from setup.create_database import create_tables, engine, metadata

    create_tables(engine, metadata, options.log_sql)
    sys.stdout.flush()

    from models.Theme import Theme

    themes = Theme.all()
    if len(themes) > 0:
        print(INFO + "It looks like database has already been set up.")
        return

    print(INFO + "%s : Bootstrapping the database ..." % current_time())
    import setup.bootstrap

    # Display Details
    if is_devel:
        environ = bold + R + "Development bootstrap:"
        details = C + "Admin Username: admin, Password: rootthebox" + W
    else:
        environ = bold + "Production bootstrap" + W
        details = ""
    from handlers import update_db

    update_db(False)
    sys.stdout.flush()
    try:
        print(INFO + "%s %s" % (environ, details), flush=True)
    except:
        print(INFO + "%s %s" % (environ, details))