-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfair.py
executable file
·56 lines (47 loc) · 1.63 KB
/
fair.py
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
#!/usr/bin/env python3
import configparser
import logging
import os
import sys
import connexion
from connexion.resolver import RestyResolver
logging.basicConfig(
stream=sys.stdout,
level=logging.DEBUG,
format="%(levelname)s:'%(name)s:%(lineno)s' | %(message)s",
)
logger = logging.getLogger("api")
app_dirname = os.path.dirname(os.path.abspath(__file__))
def load_config(plugin, fail_if_no_config=True):
config_file_main = os.path.join(app_dirname, "config.ini")
config_file_plugin = os.path.join(app_dirname, "plugins/%s/config.ini" % plugin)
config = configparser.ConfigParser()
try:
config.read([config_file_main, config_file_plugin])
logging.debug(
"Successfully loaded main & plugin's configuration files (%s, %s)"
% (config_file_main, config_file_plugin)
)
except FileNotFoundError as e:
logging.error("Could not load config file: %s" % str(e))
if fail_if_no_config:
raise (e)
except configparser.MissingSectionHeaderError as e:
message = "Could not find any/all of the following config files: %s, %s" % (
config_file_main,
config_file_plugin,
)
logging.error(message)
logging.debug(e)
error = {"code": 500, "message": "%s" % message}
logging.debug("Returning API response: %s" % error)
return json.dumps(error), 500
return config
if __name__ == "__main__":
app = connexion.FlaskApp(__name__)
app.add_api(
"fair-api.yaml",
arguments={"title": "FAIR evaluator Example"},
resolver=RestyResolver("api"),
)
app.run(port=9090)