Skip to content

Commit

Permalink
1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaudis committed Feb 20, 2024
1 parent fda7bd9 commit 09813b7
Show file tree
Hide file tree
Showing 47 changed files with 611 additions and 811 deletions.
19 changes: 9 additions & 10 deletions bycon/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# __init__.py
import sys
import sys, traceback
from os import environ, path
from pathlib import Path
import traceback

pkg_path = path.dirname( path.abspath(__file__) )
bycon_lib_path = path.join( pkg_path, "lib" )
sys.path.append( pkg_path )
sys.path.append( bycon_lib_path )

try:

from config import *

from args_parsing import *
from beacon_auth import *
from beacon_response_generation import *
Expand All @@ -31,19 +33,16 @@
byc: object = {
"args": {},
"form_data": {},
"pkg_path": pkg_path,
"bycon_lib_path": bycon_lib_path,
"parsed_config_paths": [],
"env": "server"
"parsed_config_paths": []
}
if not environ.get('HTTP_HOST'):
byc.update({"env": "local"})

read_service_definition_files(byc)
set_byc_config_pars(byc)
# updates `beacon_defaults`, `dataset_definitions` and `local_paths`
update_rootpars_from_local(LOC_PATH, byc)
set_beacon_defaults(byc)
parse_query(byc)
parse_arguments(byc)

except Exception:

if environ.get('HTTP_HOST'):
Expand Down
34 changes: 14 additions & 20 deletions bycon/beaconServer/beacon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from importlib import import_module

from bycon import *
pkg_path = path.dirname( path.abspath(__file__) )

"""
"""
Expand All @@ -20,22 +19,19 @@ def main():
try:
beacon()
except Exception:
print_text_response(traceback.format_exc(), byc["env"], 302)
print_text_response(traceback.format_exc(), 302)

################################################################################

def beacon():

set_debug_state(debug=0)

loc_dir = path.join( pkg_path, "local" )
# updates `beacon_defaults`, `dataset_definitions` and `local_paths`
update_rootpars_from_local(loc_dir, byc)
set_beacon_defaults(byc)
# update_rootpars_from_local(LOC_PATH, byc)
# set_beacon_defaults(byc)

s_a_s = byc["beacon_defaults"].get("service_path_aliases", {})
r_w = byc["beacon_defaults"].get("rewrites", {})
d_p_s = byc["beacon_defaults"].get("data_pipeline_path_ids", [])
defs = byc.get("beacon_defaults", {})
s_a_s = defs.get("service_path_aliases", {})
r_w = defs.get("rewrites", {})
d_p_s = defs.get("data_pipeline_path_ids", [])

"""
The type of execution depends on the requested entity defined in `beacon_defaults`
Expand All @@ -53,18 +49,17 @@ def beacon():
Fallback is `/info`.
"""
byc.update({"request_path_root": "beacon"})

rest_path_elements(byc)
args_update_form(byc)
prdbug(f'beacon.py - request_entity_path_id: {byc.get("request_entity_path_id")}', byc.get("debug_mode"))
# args_update_form(byc)
prdbug(f'beacon.py - request_entity_path_id: {byc.get("request_entity_path_id")}')

e_p_id = byc["form_data"].get("request_entity_path_id", "___none___")
prdbug(f'beacon.py - form e_p_id: {e_p_id}', byc.get("debug_mode"))
prdbug(f'beacon.py - form e_p_id: {e_p_id}')
if e_p_id in s_a_s or e_p_id in r_w:
byc.update({"request_entity_path_id": e_p_id})
r_p_id = byc.get("request_entity_path_id", "info")

prdbug(f'beacon.py - request_entity_path_id: {r_p_id}', byc.get("debug_mode"))
prdbug(f'beacon.py - request_entity_path_id: {r_p_id}')

# check for rewrites
if r_p_id in r_w:
Expand All @@ -81,7 +76,7 @@ def beacon():
initialize_bycon_service(byc, f)
run_beacon_init_stack(byc)
r = BeaconDataResponse(byc).resultsetResponse()
print_json_response(r, byc["env"])
print_json_response(r)
elif f:
# dynamic package/function loading; e.g. `filtering_terms` loads
# `filtering_terms` from `filtering_terms.py`...
Expand All @@ -98,9 +93,8 @@ def beacon():

exit()

e_m = "No correct service path provided. Please refer to the documentation at http://docs.progenetix.org"
e_r = BeaconErrorResponse(byc).error(e_m, 422)
print_json_response(e_r, byc["env"])
BYC["ERRORS"].append("No correct service path provided. Please refer to the documentation at http://docs.progenetix.org")
BeaconErrorResponse(byc).response(422)


################################################################################
Expand Down
4 changes: 2 additions & 2 deletions bycon/beaconServer/cohorts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ def main():
try:
cohorts()
except Exception:
print_text_response(traceback.format_exc(), byc["env"], 302)
print_text_response(traceback.format_exc(), 302)

################################################################################

def cohorts():
initialize_bycon_service(byc, "cohorts")
run_beacon_init_stack(byc)
r = BeaconDataResponse(byc).collectionsResponse()
print_json_response(r, byc["env"])
print_json_response(r)


################################################################################
Expand Down
6 changes: 2 additions & 4 deletions bycon/beaconServer/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@
################################################################################

def main():

try:
configuration()
except Exception:
print_text_response(traceback.format_exc(), byc["env"], 302)
print_text_response(traceback.format_exc(), 302)

################################################################################

def configuration():

initialize_bycon_service(byc, "configuration")
r = BeaconInfoResponse(byc)
c_f = get_schema_file_path(byc, "beaconConfiguration")
c = load_yaml_empty_fallback(c_f)
print_json_response(r.populatedInfoResponse(c), byc["env"])
print_json_response(r.populatedInfoResponse(c))


################################################################################
Expand Down
4 changes: 2 additions & 2 deletions bycon/beaconServer/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def main():
try:
datasets()
except Exception:
print_text_response(traceback.format_exc(), byc["env"], 302)
print_text_response(traceback.format_exc(), 302)


################################################################################
Expand All @@ -28,7 +28,7 @@ def datasets():
initialize_bycon_service(byc, "datasets")
run_beacon_init_stack(byc)
r = BeaconDataResponse(byc)
print_json_response(r.collectionsResponse(), byc["env"])
print_json_response(r.collectionsResponse())


################################################################################
Expand Down
4 changes: 2 additions & 2 deletions bycon/beaconServer/entry_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def main():
try:
entry_types()
except Exception:
print_text_response(traceback.format_exc(), byc["env"], 302)
print_text_response(traceback.format_exc(), 302)


################################################################################
Expand All @@ -26,7 +26,7 @@ def entry_types():
r = BeaconInfoResponse(byc)
e_f = get_schema_file_path(byc, "beaconConfiguration")
e_t_s = load_yaml_empty_fallback( e_f )
print_json_response(r.populatedInfoResponse({"entry_types": e_t_s["entryTypes"] }), byc["env"])
print_json_response(r.populatedInfoResponse({"entry_types": e_t_s["entryTypes"] }))


################################################################################
Expand Down
4 changes: 2 additions & 2 deletions bycon/beaconServer/filtering_terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def main():
try:
filtering_terms()
except Exception:
print_text_response(traceback.format_exc(), byc["env"], 302)
print_text_response(traceback.format_exc(), 302)


################################################################################
Expand All @@ -27,7 +27,7 @@ def filtering_terms():
initialize_bycon_service(byc, "filtering_terms")
run_beacon_init_stack(byc)
r = BeaconDataResponse(byc)
print_json_response(r.filteringTermsResponse(), byc["env"])
print_json_response(r.filteringTermsResponse())


################################################################################
Expand Down
9 changes: 5 additions & 4 deletions bycon/beaconServer/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ def main():
try:
info()
except Exception:
print_text_response(traceback.format_exc(), byc["env"], 302)
print_text_response(traceback.format_exc(), 302)

################################################################################

def info():

initialize_bycon_service(byc)
initialize_bycon_service(byc, "info")
r = BeaconInfoResponse(byc)

b_e_d = byc["beacon_defaults"].get("entity_defaults", {})
defs = byc.get("beacon_defaults", {})
b_e_d = defs.get("entity_defaults", {})
info = b_e_d.get("info", {})
pgx_info = info.get("content", {})
beacon_info = object_instance_from_schema_name(byc, "beaconInfoResults", "")
Expand All @@ -44,7 +45,7 @@ def info():
beacon_schemas.append(b_s)

response.update( { "returned_schemas": beacon_schemas } )
print_json_response(response, byc["env"])
print_json_response(response)


################################################################################
Expand Down
4 changes: 2 additions & 2 deletions bycon/beaconServer/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def main():
try:
map()
except Exception:
print_text_response(traceback.format_exc(), byc["env"], 302)
print_text_response(traceback.format_exc(), 302)

################################################################################

Expand All @@ -25,7 +25,7 @@ def map():
r = BeaconInfoResponse(byc)
m_f = get_schema_file_path(byc, "beaconMap")
beaconMap = load_yaml_empty_fallback( m_f )
print_json_response(r.populatedInfoResponse(beaconMap), byc["env"])
print_json_response(r.populatedInfoResponse(beaconMap))


################################################################################
Expand Down
9 changes: 3 additions & 6 deletions bycon/beaconServer/service_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@
################################################################################

def main():

try:
service_info()
except Exception:
print_text_response(traceback.format_exc(), byc["env"], 302)
print_text_response(traceback.format_exc(), 302)

################################################################################

def service_info():

initialize_bycon_service(byc)

initialize_bycon_service(byc, "service_info")
defs = byc.get("beacon_defaults", {})
b_e_d = defs.get("entity_defaults", {})
pgx_info = b_e_d.get("info", {})
Expand All @@ -33,7 +30,7 @@ def service_info():
for k in info.keys():
if k in c:
info.update({k:c[k]})
print_json_response(info, byc["env"])
print_json_response(info)

################################################################################
################################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"datasetIds": ["progenetix"]
}
},
"filters": [{ "id": "NCIT:C4536" }]
"filters": [{"id": "NCIT:C4536"}]
},
"debugMode": 0
}
54 changes: 54 additions & 0 deletions bycon/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import inspect
from os import environ, path, pardir

pkg_path = path.dirname( path.abspath(__file__) )

"""
Global variables
"""

ENV = environ.get('HTTP_HOST', "local")

PKG_PATH = pkg_path
CONF_PATH = path.join( pkg_path, "definitions")
LIB_PATH = path.join( pkg_path, "lib")

# path of the calling script is used to point to a local config directory
__caller_path = path.dirname(path.abspath((inspect.stack()[1])[1]))
LOC_PATH = path.join(__caller_path, "local")

# Database settings
# TODO: wrap them into object to make them mutable for local changes
DB_MONGOHOST = environ.get("BYCON_MONGO_HOST", "localhost")
HOUSEKEEPING_DB = "_byconHousekeepingDB"
HOUSEKEEPING_INFO_COLL = "beaconinfo"
HOUSEKEEPING_HO_COLL = "querybuffer"

SERVICES_DB = "_byconServicesDB"
GENES_COLL = "genes"
GEOLOCS_COLL = "geolocs"

#------------------------------------------------------------------------------#

# not really to be modified...

GRANULARITY_LEVELS = {
"none": 0,
"boolean": 1,
"count": 2,
"record": 3
}

################################################################################

# to be modified during execution

BYC = {
"DEBUG_MODE": False,
"TEST_MODE": False,
"ERRORS": [],
"WARNINGS": []
}

################################################################################

1 change: 0 additions & 1 deletion bycon/config/__init__.py

This file was deleted.

Loading

0 comments on commit 09813b7

Please sign in to comment.