59 home_dir = str(os.getenv(
'FAIRSHIP'))
60 path = home_dir +
"/conditionsDatabase/config.yml"
62 path_details = path.split(
".")
63 file_extention = path_details[len(path_details) - 1]
64 if not(file_extention ==
"yml" or file_extention ==
"yaml"):
65 print(
"The file extension is incorrect. A YAML file is required.")
69 with open(path,
'r')
as ymlfile:
70 cfg = yaml.load(ymlfile, Loader=yaml.FullLoader)
72 print(
"The configuration file does not exit or Invalid path to "
73 "the file:", str(sys.exc_info()[0]))
76 connection_dict = {
'db_name':
'',
'user':
None,
'password':
None,
'host':
"",
'port': 0}
80 db_type = cfg[
"db_type"]
82 print(
"db type should be defined")
85 if db_type
not in cfg.keys():
86 print(
"db config is not defined")
89 connection_dict[
"host"] = cfg[db_type][
"host"]
90 connection_dict[
"db_name"] = cfg[db_type][
"db_name"]
91 connection_dict[
"user"] = cfg[db_type][
"user"]
92 connection_dict[
"password"] = cfg[db_type][
"password"]
93 connection_dict[
"port"] = cfg[db_type][
"port"]
94 ret[db_type.lower()] = connection_dict
99 print(
"Incorrect configuration file, missing some parameters. it should contain: "
100 "db_type, db_name, user, password, host, and port.")