Example #1
0
    def __init__(self):
        try:
            db.connect()
        except Exception:
            db.init(DB_FILE)
            db.connect()

        cmd_list_loaded = self.load_command_list()
        if not cmd_list_loaded:
            logger.error("No commands available")
Example #2
0
def initialize_app(app):
    from models import db

    connection_uri = app.config["DATABASE_URI"]
    if connection_uri == ":memory:":
        app.extensions["htables"] = htables.SqliteDB(connection_uri)
    else:
        app.extensions["htables"] = htables.PostgresqlDB(connection_uri, debug=app.debug)

    @app.teardown_request
    def finalize_connection(response):
        session = getattr(flask.g, "htables_session", None)
        if session is not None:
            app.extensions["htables"].put_session(session)
            del flask.g.htables_session

    db.init(app.config["DATABASE"], user=app.config.get("DATABASE_USER"), password=app.config.get("DATABASE_PASSWORD"))
Example #3
0
Perform database migrations.

Example usage within Vagrant VM:
    $ SOUNDLOCALE_CONFIG=configuration_vagrant ./migrate.py
"""

import peewee
from psycopg2 import ProgrammingError
from app import app
from playhouse.migrate import *
from models import db
from models.user import User
from models.sound import Sound
# from models.migration_log import MigrationLog

db.init(app.config['DB_NAME'],
        **{'password': app.config['DB_PASSWORD'],
           'host': app.config['DB_HOST'],
           'user': app.config['DB_USER']})
db.connect()

User.create_table(fail_silently=True)
Sound.create_table(fail_silently=True)

## TODO: migrations
# MigrationLog.create_table(fail_silently=True)
# max_id = MigrationLog.select(fn.Max(MigrationLog.id)).scalar()
# Generates error about PostgresqlMigrator not being defined:
# although see http://peewee.readthedocs.org/en/latest/peewee/playhouse.html#schema-migrations
# migrator = PostgresqlMigrator(db)
Example #4
0
from peewee import OperationalError
from models import db, Books, Stories, Authors, Files, AuthorsStories
import os

#Initialize flask application
app = Flask(__name__)
app.config.from_object('config')
app.config.from_object('local_config')

#Routings
from routings import mod_routings

app.register_blueprint(mod_routings)

#Initialize databse
db.init(app.config['DBPATH'])
if not os.path.exists(app.config['DBPATH']):
    #Create db if not exist
    try:
        db.create_tables([Books, Stories, Authors, Files, AuthorsStories])
        try:
            #Add sample data
            from add_sample import add_sample
            add_sample()
        except:
            pass
    except OperationalError:
        pass

if __name__ == '__main__':
    #Run flask server
Example #5
0
from flask import Flask, render_template
from models import db

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://localhost/learningflask'
db.init(app)


@app.route("/")
def index():
    return render_template("index.html")


@app.route("/about")
def about():
    return render_template("about.html")


if __name__ == "__main__":
    app.run(debug=True)
Example #6
0
from flask import Flask, render_template, redirect, url_for, request, session, flash, json, jsonify
from models import db, User
from forms import LoginForm, RegisterForm, SearchForm
from werkzeug.security import generate_password_hash, check_password_hash
import requests
from database import db

app = Flask(__name__)

app.config['SECRET_KEY'] = "MemurBeySelcuk"

db.init()


@app.route('/', methods=['GET', 'POST'])
def home():
    form = SearchForm()
    if request.method == "POST":
        searchVariable = form.search.data
        searchUrl = 'https://api.itbook.store/1.0/search/'

        r = requests.get(searchUrl + searchVariable)
        result = r.json()
        books = result['books']
        return render_template('index.html', form=form, books=books)

    return render_template('index.html', form=form)


@app.route('/login/', methods=['GET', 'POST'])
def login():
Example #7
0
 def __init__(self, settings):
     db.init(settings.mmex_dbfile)
Example #8
0
    'database': {
        'host': 'localhost',
        'port': 3306,
        'user': '******',
        'pass': '******',
        'driver': 'mysql',
        'db': 'tornadoSSO',
        'charset': 'utf8',
        'debug': False
    },

    # SMTP CONFIG #
    'smtp': {
        'host': '',
        'port': 498,
        'user': '',
        'pass': '',
        'ssl': True
    },

    # LOGGING CONFIG #
    'logging': logging
}

# ROUTE CONFIG #
routes = getRoutes({
    'db': init(APPLICATION_SETTINGS['database']),
    'functions': functions,
    'logging': APPLICATION_SETTINGS['logging']
})
Example #9
0
        imf_push_appguid = vcap['imfpush'][0]['credentials']['appGuid']
        try:
            options = {
                'org': iot_org,
                'auth-key': iot_auth_key,
                'auth-token': iot_auth_token,
                'clean-session': 'true'
            }
            iot_client = ibmiotf.application.Client(
                options, logHandlers=logger.handlers)
        except Exception as e:
            print(e)
    if 'compose-for-postgresql' in vcap:
        postgresql_uri = vcap['compose-for-postgresql'][0]['credentials'][
            'uri']
        db.init('compose', dsn=postgresql_uri)
elif os.path.isfile('vcap-local.json'):
    with open('vcap-local.json') as f:
        vcap = json.load(f)['VCAP_SERVICES']
        print('Found local VCAP_SERVICES')
        iot_creds = vcap['iotf-service'][0]['credentials']
        iot_org = iot_creds['org']
        iot_auth_key = iot_creds['apiKey']
        iot_auth_token = iot_creds['apiToken']

        imf_push_api = vcap['imfpush'][0]['credentials']['apikey']
        imf_push_appguid = vcap['imfpush'][0]['credentials']['appGuid']
        try:
            options = {
                'org': iot_org,
                'auth-key': iot_auth_key,
 def setUp(self):
     db.init(':memory:')
     db.connect()
     db.create_tables([User, DrinkType, Purchase])