changes to run configuration and virtual command model
This commit is contained in:
@@ -122,10 +122,15 @@ class LrcException(Exception):
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
if os.environ.get('FLASK_ENV', None) == "development":
|
||||
if os.environ.get('FLASK_ENV', None) in ["development", "dev"]:
|
||||
print("#using backend.config.DevelopmentConfig")
|
||||
app.config.from_object('backend.config.DevelopmentConfig')
|
||||
elif os.environ.get('FLASK_ENV', None) in ["test", "testing"]:
|
||||
print("#using backend.config.TestingConfig")
|
||||
app.config.from_object('backend.config.TestingConfig')
|
||||
else:
|
||||
app.config.from_object('backend.config.Config')
|
||||
print("#using backend.config.Config")
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
login_manager = LoginManager()
|
||||
|
||||
@@ -9,7 +9,7 @@ import threading
|
||||
|
||||
from jinja2.exceptions import TemplateNotFound
|
||||
|
||||
from backend import app, db
|
||||
from backend import app, db, main_logger
|
||||
from backend.cron import get_default_scheduler, add_default_jobs, async_permanent_cron_recorder_checker
|
||||
from backend.models import *
|
||||
from backend.models import room_model, recorder_model, RecorderCommand, Recorder
|
||||
@@ -34,8 +34,9 @@ def _create_and_start_default_scheduler():
|
||||
return scheduler
|
||||
|
||||
|
||||
def main():
|
||||
def run():
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
print("starting ...")
|
||||
|
||||
# db.drop_all()
|
||||
# db.create_all()
|
||||
@@ -46,25 +47,6 @@ def main():
|
||||
create_default_recorders()
|
||||
add_test_recorder()
|
||||
|
||||
print(app.config.get("SERVER_NAME", None))
|
||||
|
||||
if app.config.get("USE_SSL", False):
|
||||
try:
|
||||
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
|
||||
context.load_cert_chain(app.config.get("CERT", 'cert.pem'), app.config.get("KEY", 'key.pem'))
|
||||
print("using ssl context!")
|
||||
app.run(debug=True, ssl_context=context, threaded=True,
|
||||
#host="0.0.0.0",
|
||||
host=app.config.get("HOST", "0.0.0.0"),
|
||||
port=app.config.get("PORT", 5443)
|
||||
)
|
||||
except FileNotFoundError:
|
||||
print("Could not find cert/key.pem!")
|
||||
app.run(debug=True, threaded=True,
|
||||
host=app.config.get("HOST", None),
|
||||
port=app.config.get("PORT", 5443)
|
||||
)
|
||||
|
||||
try:
|
||||
db.create_all()
|
||||
except Exception as e:
|
||||
@@ -73,12 +55,48 @@ def main():
|
||||
scheduler = _create_and_start_default_scheduler()
|
||||
# _start_initial_recorder_state_update(run_in_thread=False)
|
||||
|
||||
print("Server Name: {}".format(app.config.get("SERVER_NAME", None)))
|
||||
|
||||
wsb = WebSocketBase()
|
||||
print("running websocket...(replaces normal app.run()")
|
||||
wsb.start_websocket(debug=True, host="0.0.0.0")
|
||||
|
||||
if app.config.get("USE_SSL", False):
|
||||
try:
|
||||
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
|
||||
context.load_cert_chain(app.config.get("CERT", 'cert.pem'), app.config.get("KEY", 'key.pem'))
|
||||
print("using ssl context!")
|
||||
#app.run(debug=True, ssl_context=context, threaded=True,
|
||||
# host=app.config.get("HOST", "0.0.0.0"),
|
||||
# port=app.config.get("PORT", 5443)
|
||||
# )
|
||||
print("running websocket...(replaces normal app.run()")
|
||||
|
||||
wsb.start_websocket(debug=app.config.get("DEBUG", False),
|
||||
host=app.config.get("HOST", "0.0.0.0"),
|
||||
port=app.config.get("PORT", 5443),
|
||||
ssl_context=context
|
||||
)
|
||||
except FileNotFoundError:
|
||||
print("Could not find cert/key.pem!")
|
||||
#app.run(debug=True, threaded=True,
|
||||
# host=app.config.get("HOST", None),
|
||||
# port=app.config.get("PORT", 5443)
|
||||
# )
|
||||
print("running websocket...(replaces normal app.run()")
|
||||
wsb.start_websocket(debug=app.config.get("DEBUG", False),
|
||||
host=app.config.get("HOST", "0.0.0.0"),
|
||||
port=app.config.get("PORT", 5443)
|
||||
)
|
||||
|
||||
else:
|
||||
print("running websocket...(replaces normal app.run()")
|
||||
wsb.start_websocket(debug=app.config.get("DEBUG", False),
|
||||
host=app.config.get("HOST", "0.0.0.0"),
|
||||
port=app.config.get("PORT", 5443)
|
||||
)
|
||||
# print("running web app...")
|
||||
# app.run(debug=True, host="0.0.0.0", threaded=True)
|
||||
wsb.send_test_msg()
|
||||
print("running!")
|
||||
|
||||
while True:
|
||||
user_in = input("Type >exit< to quit.")
|
||||
@@ -90,4 +108,4 @@ def main():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
run()
|
||||
|
||||
Binary file not shown.
BIN
backend/app.db_test
Normal file
BIN
backend/app.db_test
Normal file
Binary file not shown.
Binary file not shown.
@@ -20,7 +20,9 @@ from sqlalchemy import or_
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from backend.models.model_base import ModelBase
|
||||
from backend.models.virtual_command_model import virtual_command_recorder_command_table, virtual_command_recorder_table
|
||||
from backend.models.virtual_command_model import virtual_command_recorder_command_table, \
|
||||
virtual_command_recorder_table, \
|
||||
virtual_command_recorder_model_table
|
||||
|
||||
metadata = MetaData()
|
||||
|
||||
@@ -73,6 +75,8 @@ class RecorderModel(db.Model, ModelBase):
|
||||
checksum = db.Column(db.String(63), unique=True,
|
||||
nullable=False) # checksum of the recorder commands! (see: model_updater.py)
|
||||
last_checksum_change = db.Column(db.DateTime, nullable=True, default=None)
|
||||
virtual_commands = db.relationship('VirtualCommand', secondary=virtual_command_recorder_model_table,
|
||||
back_populates='recorder_model_commands')
|
||||
_requires_user = db.Column(db.Integer, default=False, name='requires_user')
|
||||
_requires_password = db.Column(db.Integer, default=True, name='requires_password')
|
||||
|
||||
|
||||
@@ -34,6 +34,20 @@ virtual_command_recorder_table = db.Table('virtual_command_recorder',
|
||||
ondelete="CASCADE"),
|
||||
primary_key=True))
|
||||
|
||||
# This is the association table for the many-to-many relationship between
|
||||
# virtual commands and recorder commands.
|
||||
virtual_command_recorder_model_table = db.Table('virtual_command_recorder_model',
|
||||
db.Column('virtual_command_id', db.Integer,
|
||||
db.ForeignKey('virtual_command.id',
|
||||
onupdate="CASCADE",
|
||||
ondelete="CASCADE"),
|
||||
primary_key=True),
|
||||
db.Column('recorder_model_id', db.Integer,
|
||||
db.ForeignKey('recorder_model.id',
|
||||
onupdate="CASCADE",
|
||||
ondelete="CASCADE"),
|
||||
primary_key=True))
|
||||
|
||||
|
||||
class VirtualCommand(db.Model):
|
||||
id = db.Column(db.Integer, autoincrement=True, primary_key=True)
|
||||
@@ -47,6 +61,9 @@ class VirtualCommand(db.Model):
|
||||
recorder_commands = db.relationship('RecorderCommand', secondary=virtual_command_recorder_command_table,
|
||||
back_populates='virtual_commands')
|
||||
|
||||
recorder_model_commands = db.relationship('RecorderModel', secondary=virtual_command_recorder_model_table,
|
||||
back_populates='virtual_commands')
|
||||
|
||||
# parent_virtual_command = db.relationship('VirtualCommand', back_populates='child_virtual_commands')
|
||||
parent_virtual_command_id = db.Column(db.Integer, db.ForeignKey('virtual_command.id'))
|
||||
child_virtual_commands = db.relationship('VirtualCommand',
|
||||
|
||||
@@ -45,8 +45,6 @@ def get_campus_rooms():
|
||||
'building_number': building_number,
|
||||
'coordinates': r.get('coordinates')}
|
||||
parsed_rooms.append(room)
|
||||
|
||||
print(len(parsed_rooms))
|
||||
return parsed_rooms
|
||||
|
||||
|
||||
|
||||
@@ -21,17 +21,17 @@ class WebSocketBase:
|
||||
self.flask_app_context = app
|
||||
self.socket_thread = None
|
||||
|
||||
def start_websocket_in_thread(self, host=None, port=None, debug=None):
|
||||
def start_websocket_in_thread(self, host=None, port=None, debug=None, **kwargs):
|
||||
self.socket_thread = threading.Thread(
|
||||
target=self.start_websocket,
|
||||
args=(host, port, debug))
|
||||
args=(host, port, debug, kwargs))
|
||||
self.socket_thread.start()
|
||||
return self.socket_thread
|
||||
|
||||
def start_websocket(self, host=None, port=None, debug=None):
|
||||
def start_websocket(self, host=None, port=None, debug=None, **kwargs):
|
||||
if debug is None:
|
||||
debug = self.flask_app_context.debug
|
||||
socketio.run(self.flask_app_context, host=host, port=port, debug=debug)
|
||||
socketio.run(self.flask_app_context, host=host, port=port, debug=debug, **kwargs)
|
||||
|
||||
def send_test_msg(self):
|
||||
socketio.emit('test', "tolle nachricht")
|
||||
|
||||
Reference in New Issue
Block a user