Skip to content

Commit

Permalink
Adaptions for multi intance version
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Jan 8, 2025
1 parent d5b27ae commit 03dbad6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config/default.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Don't edit this file. To override settings please use instance/production.py
import os
from pathlib import Path

from config.database_versions import DATABASE_VERSIONS
Expand Down Expand Up @@ -27,6 +28,8 @@
# To override them (in instance/production.py) either use them like here
# or use absolute paths like e.g. pathlib.Path('/some/location/somewhere')
FILES_PATH = Path(__file__).parent.parent / 'files'
if 'INSTANCE_PATH' in os.environ:
FILES_PATH = Path(os.environ['INSTANCE_PATH']) / 'files'
EXPORT_PATH = Path(FILES_PATH) / 'export'
UPLOAD_PATH = Path(FILES_PATH) / 'uploads'
TMP_PATH = Path('/tmp') # For processing files e.g. at import and export
Expand Down
3 changes: 3 additions & 0 deletions openatlas.wsgi
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, '/usr/local/openatlas') # Todo: remove hardcoded path

os.environ['INSTANCE_PATH'] = f'{os.path.dirname(os.path.abspath(__file__))}/'

from openatlas import app as application
7 changes: 6 additions & 1 deletion openatlas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import locale
import os
from typing import Any, Optional

from flask import Flask, Response, g, request, session
Expand All @@ -10,11 +11,15 @@
from openatlas.api.resources.error import AccessDeniedError
from openatlas.database.connect import close_connection, open_connection

instance_config_path = ''
if 'INSTANCE_PATH' in os.environ:
instance_config_path = os.environ['INSTANCE_PATH'] + 'instance/'

app: Flask = Flask(__name__, instance_relative_config=True)
csrf = CSRFProtect(app) # Make sure all forms are CSRF protected
app.config.from_object('config.default')
app.config.from_object('config.api')
app.config.from_pyfile('production.py')
app.config.from_pyfile(f'{instance_config_path}production.py')
app.config['WTF_CSRF_TIME_LIMIT'] = None # Set CSRF token valid for session

locale.setlocale(locale.LC_ALL, 'en_US.utf-8')
Expand Down
6 changes: 6 additions & 0 deletions runserver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import os
import sys

from openatlas import app

sys.path.append('/usr/local/openatlas/')
os.environ['INSTANCE_PATH'] = f'{os.path.dirname(os.path.abspath(__file__))}/'

if __name__ == "__main__":
app.run()

0 comments on commit 03dbad6

Please sign in to comment.