Example #1
0
File: app.py Project: mianos/etemp
def create_app():
    app = Flask(__name__)
    app.secret_key = "sdjadsldjasklj"

    app.settings = configobj.ConfigObj('settings.ini')

    engine = create_engine(app.settings['database']['connection'])
    Session = sessionmaker(bind=engine)  # autocommit=True)

    menu.init_app(app)
    jinja_local.jinja_filters.init_app(app)
    app.register_blueprint(reports.reports, url_prefix='/reports')
    app.register_blueprint(graphs.graphs, url_prefix='/graphs')
    app.register_blueprint(receiver.receiver)
    app.register_blueprint(auth)

    @app.route('/')
    def root():
        return redirect(url_for('reports.values'))

    @app.after_request
    def session_commit(response):
        session = getattr(g, 'session', None)
        if session is not None:
            g.session.commit()
        return response

    @app.before_request
    def before_request():
        g.session = Session()

    @app.teardown_request
    def teardown_request(exception):
        session = getattr(g, 'session', None)
        if session is not None:
            session.close()
    return app
Example #2
0
def create_app():
    app = Flask(__name__)
#    app.config['STATIC_RESOURCES'] = True
    app.secret_key = "\xca\xcf\x16O\x04\x47\x0eFN\xf9\x0c,\xfb4{''<\x9b\xfc\x08\x87\xe9\x13"

    app.settings = configobj.ConfigObj('settings.ini')

    engine = create_engine(app.settings['database']['connection'], echo=True, pool_recycle=3600)
    Session = sessionmaker(bind=engine)  # autocommit=True)

    menu.init_app(app)
    jinja_local.jinja_filters.init_app(app)
    app.register_blueprint(reports.reports, url_prefix='/reports')
    app.register_blueprint(auth)

    @app.route('/')
    def root():
        return redirect(url_for('reports.users_list'))

    @app.after_request
    def session_commit(response):
        session = getattr(g, 'session', None)
        if session is not None:
            g.session.commit()
        return response

    @app.before_request
    def before_request():
        g.session = Session()

    @app.teardown_request
    def teardown_request(exception):
        session = getattr(g, 'session', None)
        if session is not None:
            session.close()
    return app
Example #3
0
import os
from flask import Flask
from configparser import ConfigParser

# Create the Flask app
app = Flask(__name__)

# Prepare Paths
PACKAGE_PATH = os.path.dirname(os.path.abspath(__file__))
GALLERY_GLUE_PATH = os.environ.get('GALLERY_GLUE_PATH', PACKAGE_PATH)

# Load Config
app.settings = ConfigParser()
app.settings.read(os.path.join(GALLERY_GLUE_PATH, 'config.ini'))

# Extract Adapter
ADAPTER = app.settings['General']['Adapter']

# Normalize Paths
for key in app.settings['Paths']:
    os.path.normpath(app.settings['Paths'][key])

# Analyze General Settingss
# Galleries Folder Name
if 'GalleriesFolderName' not in app.settings['General']:
    app.settings['General']['GalleriesFolderName'] = 'Galleries'

# Galleries Path
GALLERIES_PATH = os.path.join(GALLERY_GLUE_PATH, app.settings['General']['GalleriesFolderName'])
if app.settings['General']['GalleriesOnDifferentPath'] == 'yes':
    GALLERIES_PATH = os.path.join(GALLERY_GLUE_PATH, app.settings['Paths']['Galleries'], app.settings['General']['GalleriesFolderName'])
Example #4
0
if os.path.exists(file_path):
    # Check secret key file permissions
    mode = os.stat(file_path).st_mode

    if mode & stat.S_IRWXU != 384 or mode & stat.S_IRWXG != 0 or mode & stat.S_IRWXO != 0:
        raise Exception("%s file permissions should be 600\n" % file_path)

    parser = ConfigParser.ConfigParser()
    parser.read([file_path])

    # Set application secret key
    app.secret_key = parser.get('main', 'secret_key')
    parser.remove_option('main', 'secret_key')

    # Set application settings parser
    app.settings = parser

# Register modules
app.register_blueprint(jira)
app.register_blueprint(nagios)
app.register_blueprint(rman)
app.register_blueprint(sqlrelay)


@app.before_request
def before_request():
    g.cache = FileSystemCache(os.path.join(DATA_DIR, 'cache'))


@app.teardown_request
def teardown_request(e):