-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
63 lines (47 loc) · 2.57 KB
/
util.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
57
58
59
60
61
62
63
import configparser
from os import getenv, environ, path
SCRIPT_DIR = path.dirname(__file__)
config = configparser.RawConfigParser()
config.read(path.join(SCRIPT_DIR, 'project.cfg'))
def read_property(env_name, config_tuple):
property_name = ''
if getenv(env_name):
property_name = environ.get(env_name)
else:
try:
property_name = config.get(config_tuple[0], config_tuple[1])
except Exception as ex:
print(ex)
return property_name
solr_url = read_property('NLP_SOLR_URL', ('solr', 'url'))
conn_string = "host='%s' dbname='%s' user='%s' password='%s' port=%s" % (read_property('NLP_PG_HOSTNAME', ('pg', 'host')),
read_property('NLP_PG_DATABASE', ('pg', 'dbname')),
read_property('NLP_PG_USER', ('pg', 'user')),
read_property('NLP_PG_PASSWORD', ('pg', 'password')),
str(read_property('NLP_PG_CONTAINER_PORT', ('pg', 'port'))))
mongo_host = read_property('NLP_MONGO_HOSTNAME', ('mongo', 'host'))
mongo_port = int(read_property('NLP_MONGO_CONTAINER_PORT', ('mongo', 'port')))
mongo_db = read_property('NLP_MONGO_DATABASE', ('mongo', 'db'))
mongo_working_index = read_property('NLP_MONGO_WORKING_INDEX', ('mongo', 'working_index'))
mongo_working_collection = read_property('NLP_MONGO_WORKING_COLLECTION', ('mongo', 'working_collection'))
tmp_dir = read_property('NLP_API_TMP_DIR', ('tmp', 'dir'))
log_dir = read_property('NLP_API_LOG_DIR', ('log', 'dir'))
luigi_scheduler = read_property('LUIGI_SCHEDULER_URL', ('luigi', 'scheduler'))
luigi_url = read_property('LUIGI_URL', ('luigi', 'url'))
luigi_workers = read_property('LUIGI_WORKERS', ('luigi', 'workers'))
main_url = read_property('NLP_API_URL', ('main', 'url'))
row_count = 25
delimiter = ','
quote_character = '"'
report_mapper_url = read_property('MAPPER_API_URL', ('report_mapper', 'url'))
report_mapper_key = read_property('MAPPER_API_KEY', ('report_mapper', 'key'))
report_mapper_inst = read_property('MAPPER_API_INSTITUTE', ('report_mapper', 'institute'))
ohdsi_url = read_property('OHDSI_WEBAPI_URL', ('ohdsi', 'webapi'))
def cmp_2_key(mycmp):
# https://bytes.com/topic/python/answers/844614-python-3-sorting-comparison-function
class K:
def __init__(self, obj, *args):
self.obj = obj
def __cmp__(self, other):
return mycmp(self.obj, other.obj)
return K