Robot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

68 lines
2.1 KiB

import os
from flask import Flask
from flask_login import LoginManager
from flask_socketio import SocketIO
#######################
#### Configuration ####
#https://www.patricksoftwareblog.com/structuring-a-flask-project/
#######################
# Create the instances of the Flask extensions (flask-sqlalchemy, flask-login, etc.) in
# the global scope, but without any arguments passed in. These instances are not attached
# to the application at this point.
login = LoginManager()
login.login_view = "users.login"
socketio = SocketIO()
from roberto.camera.camera_opencv import Camera
camera = Camera()
from roberto.camera.camera_gstreamer_webrtc import WebRTCCamera
webrtccamera = WebRTCCamera()
from roberto.Serial import Serial
serial = Serial()
######################################
#### Application Factory Function ####
######################################
def create_app(config_filename=None):
app = Flask(__name__)
app.config.from_mapping(
SECRET_KEY=os.urandom(24),
DATABASE=os.path.join(app.instance_path, 'roberto.sqlite'),
)
if config_filename is None:
app.config.from_pyfile('config.cfg')
else:
app.config.from_pyfile(config_filename)
initialize_extensions(app)
register_blueprints(app)
# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
return app
def initialize_extensions(app):
# Since the application instance is now created, pass it to each Flask
# extension instance to bind it to the Flask application instance (app)
from roberto.model import db
db.init_app(app)
#login.init_app(app)
socketio.init_app(app, cors_allowed_origins="*")
pass
def register_blueprints(app):
# Since the application instance is now created, register each Blueprint
# with the Flask application instance (app)
from roberto.views.frontend import frontend_blueprint
from roberto.views.websocket import websocket_blueprint
app.register_blueprint(frontend_blueprint)
app.register_blueprint(websocket_blueprint)