Beispiel #1
0
    def setUp(self):
        (self.db_fd, self.db_file) = tempfile.mkstemp()

        app = lapsite.create_app('testing_config.py')
        app.config['DATABASE_URI'] = 'sqlite:///' + self.db_file

        with app.test_client() as c:
            c.get('/')
            load_data()
Beispiel #2
0
#!/usr/bin/env python


from lapsite import create_app

app = create_app()
app.run(host='0.0.0.0')

Beispiel #3
0
def load_data():
    app = lapsite.app
    app.logger.info('Loading data from %(DATA_FILE)s.' % lapsite.app.config)

    cxn = g.db.connect() if hasattr(g, 'db') else lapsite.connect_db(app).connect()
    with closing(cxn):
        txn = cxn.begin()
        try:
            with app.open_resource(app.config['DATA_FILE']) as f:
                buffer = ''
                for line in f:
                    buffer += line

                    if sqlite3.complete_statement(buffer):
                        cxn.execute(buffer)
                        buffer = ''
            txn.commit()

        except:
            txn.rollback()
            raise

    app.logger.info('Done loading data.')


if __name__ == '__main__':
    app = lapsite.create_app()
    load_data()