Example #1
0
def init():

    # create the database
    db.configure_mappers()
    db.create_all()

    # create the super user
    u = User(name=settings.SUPER_USER,
             email=settings.SUPER_USER_EMAIL,
             password=settings.SUPER_USER_PASSWORD,
             admin=True,
             super_user=True)

    # optionally add super user apikey
    if getattr(settings, 'SUPER_USER_APIKEY', None):
        u.apikey = settings.SUPER_USER_APIKEY
    db_session.add(u)

    # load sql extensions + functions
    for sql in load_sql():
        db_session.execute(sql)

    # load built-in sous-chefs
    for sc in load_sous_chefs():
        sc = sous_chef_schema.validate(sc)
        s = SousChef(**sc)
        db_session.add(s)

    # commit
    db_session.commit()
Example #2
0
def sous_chefs(org):
    """
    (Re)load all sous chefs.
    """
    # load all sous-chefs
    for sc, fp in init.load_sous_chefs():
        sc = sous_chef_schema.validate(sc, fp)
        sc['org_id'] = org.id
        sc_obj = db.session.query(SousChef).filter_by(slug=sc['slug']).first()
        if not sc_obj:
            log.info('Creating sous chef: "{slug}"'.format(**sc))
            sc_obj = SousChef(**sc)
        else:
            log.warning('Updating sous chef: "{slug}"'.format(**sc))
            sc = sous_chef_schema.update(sc_obj.to_dict(), sc)
            for name, value in sc.items():
                setattr(sc_obj, name, value)
        db.session.add(sc_obj)
    db.session.commit()
    return org
Example #3
0
def sous_chefs(org):
    """
    (Re)load all sous chefs.
    """
    # load all sous-chefs
    for sc, fp in init.load_sous_chefs():
        sc = sous_chef_schema.validate(sc, fp)
        sc['org_id'] = org.id
        sc_obj = db.session.query(SousChef).filter_by(
            slug=sc['slug']).first()
        if not sc_obj:
            log.info('Creating sous chef: "{slug}"'.format(**sc))
            sc_obj = SousChef(**sc)
        else:
            log.warning('Updating sous chef: "{slug}"'.format(**sc))
            sc = sous_chef_schema.update(sc_obj.to_dict(), sc)
            for name, value in sc.items():
                setattr(sc_obj, name, value)
        db.session.add(sc_obj)
    db.session.commit()
    return org
Example #4
0
    def test_schema(self):

        for sc, fp in load_sous_chefs(SOUS_CHEF_DIR, incl_internal=False):
            sous_chef_schema.validate(sc, fp)
        assert True
Example #5
0
    def test_schema(self):

        for sc, fp in load_sous_chefs(SOUS_CHEF_DIR, incl_internal=False):
            sous_chef_schema.validate(sc, fp)
        assert True
Example #6
0
def run(opts, **kw):

    for sc, fp in load_sous_chefs(sous_chef_dir=opts.module_path, incl_internal=False):
        print sc_docs.create(sc, fp, opts.format)
Example #7
0
def run(opts, **kwargs):
    # create the database
    try:
        with app.app_context():
            echo('Creating database "{}"'.format(settings.SQLALCHEMY_DATABASE_URI), 
                no_color=opts.no_color)
            db.configure_mappers()
            db.create_all()
            
            # create the super user
            u = User.query.filter_by(email=settings.SUPER_USER_EMAIL).first()
            if not u:
                echo('Creating super user "{}"'.format(settings.SUPER_USER_EMAIL),
                    no_color=opts.no_color)
                u = User(name=settings.SUPER_USER,
                         email=settings.SUPER_USER_EMAIL,
                         password=settings.SUPER_USER_PASSWORD,
                         admin=True,
                         super_user=True)

                # optionally add super user apikey
                if getattr(settings, 'SUPER_USER_APIKEY', None):
                    u.apikey = settings.SUPER_USER_APIKEY
            else:
                echo('Updating super user "{}"'.format(settings.SUPER_USER_EMAIL), 
                    no_color=opts.no_color)
                u.name=settings.SUPER_USER,
                u.email=settings.SUPER_USER_EMAIL,
                u.password=settings.SUPER_USER_PASSWORD,
                u.admin=True
                super_user=True
            db.session.add(u)

            echo('(Re)Loading SQL Extensions', no_color=opts.no_color)
            # load sql extensions + functions
            for sql in load_sql():
                db.session.execute(sql)

            # load built-in sous-chefs
            for sc in load_sous_chefs():
                sc = sous_chef_schema.validate(sc)

                sc_obj = db.session.query(SousChef).filter_by(slug=sc['slug']).first()
                if not sc_obj:
                    echo('Importing Sous Chef "{}"'.format(sc['slug']),
                        no_color=opts.no_color)
                    sc_obj = SousChef(**sc)
                
                else:
                    echo('Updating Sous Chef "{}"'.format(sc['slug']),
                        no_color=opts.no_color)
                    sc = sous_chef_schema.update(sc_obj.to_dict(), sc)
                    # udpate
                    for name, value in sc.items():
                        setattr(sc_obj, name, value)
                db.session.add(sc_obj)

            # commit
            db.session.commit()
            db.session.close()

    except Exception as e:
        db.session.rollback()
        db.session.close()
        raise e