-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathconfig.py
More file actions
219 lines (167 loc) · 6.48 KB
/
config.py
File metadata and controls
219 lines (167 loc) · 6.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import datetime
import os
from pathlib import Path
basedir = os.path.abspath(os.path.dirname(__file__))
app_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "app")
# In your backend config file or wherever SETTINGS_FILE_FOLDER is used:
MODULE_DIR = Path(__file__).parent # Directory containing this Python file
CHORAS_ROOT = MODULE_DIR.parent # Go up to choras/
class DefaultConfig:
"""
Default Configuration
"""
# Flask Configuration
APP_NAME = os.environ.get("APP_NAME")
SECRET_KEY = os.environ.get("SECRET_KEY")
PROPAGATE_EXCEPTIONS = True
DEBUG = False
TESTING = False
# Configuration of Flask-JWT-Extended
JWT_SECRET_KEY = os.environ.get("JWT_SECRET_KEY")
# Determines the minutes that the access token remains active
JWT_ACCESS_TOKEN_EXPIRES = datetime.timedelta(minutes=30)
# Determines the days that the refresh token remains active
JWT_REFRESH_TOKEN_EXPIRES = datetime.timedelta(days=30)
# Algorithm used to generate the token
JWT_ALGORITHM = "HS256"
# Algorithm used to decode the token
JWT_DECODE_ALGORITHMS = "HS256"
# Header that should contain the JWT in a request
JWT_HEADER_NAME = "Authorization"
# Word that goes before the token in the Authorization header in this case empty
JWT_HEADER_TYPE = "Bearer"
# Where to look for a JWT when processing a request.
JWT_TOKEN_LOCATION = "headers"
# Config API documents
API_TITLE = "UI Backend RESTAPI"
API_VERSION = "v1"
OPENAPI_VERSION = "3.0.3"
OPENAPI_URL_PREFIX = "/"
OPENAPI_SWAGGER_UI_PATH = "/swagger-ui"
OPENAPI_SWAGGER_UI_URL = "https://cdn.jsdelivr.net/npm/swagger-ui-dist/"
# Database configuration
SQLALCHEMY_TRACK_MODIFICATIONS = False
SHOW_SQLALCHEMY_LOG_MESSAGES = False
# App Environments
APP_ENV_LOCAL = "local"
APP_ENV_TESTING = "testing"
APP_ENV_DEVELOP = "develop"
APP_ENV_PRODUCTION = "production"
APP_ENV = APP_ENV_DEVELOP
# Logging
DATE_FMT = "%Y-%m-%d %H:%M:%S"
LOG_FILE_API = f"{basedir}/logs/api.log"
UPLOAD_FOLDER_NAME = "uploads"
UPLOAD_FOLDER = os.path.join(basedir, UPLOAD_FOLDER_NAME)
ALLOWED_EXTENSIONS = {"obj", "geo", "dxf"}
AUDIO_FILE_FOLDER = "example_audios"
USER_AUDIO_FILE_FOLDER_NAME = os.path.join(UPLOAD_FOLDER_NAME, "audiofiles")
USER_AUDIO_FILE_FOLDER = os.path.join(basedir, USER_AUDIO_FILE_FOLDER_NAME)
#SETTINGS_FILE_FOLDER = "/app/simulation-backend/example_settings"
SETTINGS_FILE_FOLDER = os.environ.get(
"SETTINGS_FILE_FOLDER",
"/app/simulation-backend/example_settings"
)
#METHODS_CONFIG_PATH = "/app/simulation-backend/methods-config.json"
METHODS_CONFIG_PATH = os.environ.get(
"METHODS_CONFIG_PATH",
"/app/simulation-backend/methods-config.json"
)
USER_MODEL_IMAGE_FOLDER_NAME = os.path.join(UPLOAD_FOLDER_NAME, "model_images")
# Ensure the upload folder exists
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
if not os.path.exists(USER_AUDIO_FILE_FOLDER):
os.makedirs(USER_AUDIO_FILE_FOLDER)
if not os.path.exists(USER_MODEL_IMAGE_FOLDER_NAME):
os.makedirs(USER_MODEL_IMAGE_FOLDER_NAME)
SQLALCHEMY_DATABASE_URI = "sqlite:///" + os.path.join(basedir, "develop.db")
SQLALCHEMY_TRACK_MODIFICATIONS = False
CELERY_CONFIG = {
"broker_url": "sqla+sqlite:///" + os.path.join(basedir, "celerydb.sqlite"),
"result_backend": "db+sqlite:///" + os.path.join(basedir, "celerydb.sqlite"),
}
class DevelopConfig(DefaultConfig):
# App environment
APP_ENV = DefaultConfig.APP_ENV_DEVELOP
# Activate debug mode
DEBUG = True
# Database configuration
# SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'develop.db')
# # SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL")
class TestingConfig(DefaultConfig):
# App environment
APP_ENV = DefaultConfig.APP_ENV_TESTING
# Flask disables error catching during request handling for better error reporting in tests
TESTING = True
# Activate debug mode
DEBUG = True
# False to disable CSRF protection during tests
WTF_CSRF_ENABLED = False
# Logging
LOG_FILE_API = f"{basedir}/logs/api_tests.log"
# Database configuration
SQLALCHEMY_DATABASE_URI = "sqlite:///" + os.path.join(basedir, "test.db")
class LocalConfig(DefaultConfig):
# App environment
APP_ENV = DefaultConfig.APP_ENV_LOCAL
# Activate debug mode
DEBUG = False
# # Database configuration
SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL")
class ProductionConfig(DefaultConfig):
# App environment
APP_ENV = DefaultConfig.APP_ENV_PRODUCTION
# Activate debug mode
DEBUG = False
# # Database configuration
# SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL")
class AuralizationParametersConfig(DefaultConfig):
# some hardcode values for the auralization parameters
original_fs = 20000
visualization_fs = 44100
filter_order = 8
nth_octave = 1
W = 0.01
dist_sr = 1.5
rho = 1.21
c0 = 343
random_seed = 215
allowedextensions = {'wav'}
maxSize = 10 * 1024 * 1024 # 10MB
class CustomExportParametersConfig(DefaultConfig):
# some hardcode values for the custom export
keys = ["xlsx", "EDC", "Parameters", "Auralization"]
key_simulationId = "SimulationId"
impulse_response_fs = ["44100Hz"]
impulse_response = "Impulse response"
value_wav_file_auralization = "wav"
value_wav_file_IR = "wavIR"
value_csv_file_IR = "csvIR"
key_xlsx = "xlsx"
key_t_column = "t"
class FeatureToggle(DefaultConfig):
# Uncomment this line to enable geo conversion from input geometry
enable_geo_conversion = True
@classmethod
def is_enabled(cls, feature_name: str) -> bool:
return getattr(cls, feature_name, False)
class CloudConfig:
"""
Cloud Configuration
"""
CLOUD_EXECUTOR_HOST = "145.38.205.131" # "145.38.205.107"
CLOUD_EXECUTOR_USER = "kchanioglo"
CLOUD_EXECUTOR_KEY_PATH = f"{Path.home()}/.ssh/id_ed25519"
CLOUD_STORAGE_PATH = "/data/storagesingularitydemo"
CLOUD_EXECUTOR_DIRECTORY = f"{CLOUD_STORAGE_PATH}/{CLOUD_EXECUTOR_USER}"
class TestingConfigs(DefaultConfig):
APP_ENV = DefaultConfig.APP_ENV_TESTING
TESTING = True
DEBUG = True
WTF_CSRF_ENABLED = False
LOG_FILE_API = f"{basedir}/logs/api_tests.log"
SQLALCHEMY_DATABASE_URI = os.environ.get(
"DATABASE_URL",
"sqlite:///" + os.path.join(basedir, "test.db")
)