|
1 | 1 | import click |
2 | | -import logging |
3 | | -import pathlib |
4 | | -from configparser import ConfigParser |
5 | 2 | from datetime import datetime |
6 | 3 | from mars_lib.target_repo import TargetRepository |
7 | 4 | from mars_lib.models.isa_json import IsaJson |
8 | 5 | from mars_lib.submit import submission |
9 | 6 | from mars_lib.credential import CredentialManager |
10 | | -from mars_lib.logging import print_and_log |
| 7 | +from mars_lib.logging import print_and_log, init_logging |
11 | 8 | from mars_lib.validation import validate, CustomValidationException |
12 | | -from logging.handlers import RotatingFileHandler |
13 | 9 | import requests |
14 | 10 | import sys |
15 | | -import os |
16 | 11 | import json |
| 12 | +from pathlib import Path |
| 13 | +import os |
| 14 | +from configparser import ConfigParser |
17 | 15 |
|
18 | 16 | # Load CLI configuration |
19 | 17 | home_dir = ( |
20 | | - pathlib.Path(str(os.getenv("MARS_SETTINGS_DIR"))) |
| 18 | + Path(str(os.getenv("MARS_SETTINGS_DIR"))) |
21 | 19 | if os.getenv("MARS_SETTINGS_DIR") |
22 | | - else pathlib.Path.home() |
| 20 | + else Path.home() |
23 | 21 | ) |
24 | 22 |
|
25 | 23 | config_file = home_dir / ".mars" / "settings.ini" |
|
28 | 26 | config = ConfigParser() |
29 | 27 | config.read(config_file) |
30 | 28 |
|
31 | | -# Logging configuration |
32 | | -log_level = config.get("logging", "log_level", fallback="ERROR") |
33 | | -log_file = config.get("logging", "log_file", fallback=fallback_log_file) |
34 | | -log_max_size = int( |
35 | | - config.get("logging", "log_max_size", fallback="1024") |
36 | | -) # in kilobytes. 1 MB by default. |
37 | | -log_max_files = int( |
38 | | - config.get("logging", "log_max_files", fallback="5") |
39 | | -) # number of backup files. 5 by default. |
40 | | - |
41 | | -handler = RotatingFileHandler( |
42 | | - log_file, maxBytes=log_max_size * 1024, backupCount=log_max_files |
43 | | -) |
44 | | -handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")) |
45 | | - |
46 | | -logging.basicConfig( |
47 | | - handlers=[handler], |
48 | | - level=log_level, |
49 | | -) |
| 29 | +# Load logging configuration |
| 30 | +init_logging(config, fallback_log_file) |
50 | 31 |
|
51 | 32 | # Read in all the URLs from the config file |
52 | | -urls = { |
53 | | - "DEV": { |
54 | | - "ENA": { |
55 | | - "SERVICE": config.get( |
56 | | - "ena", |
57 | | - "development-url", |
58 | | - fallback="https://wwwdev.ebi.ac.uk/biosamples/samples", |
59 | | - ), |
60 | | - "SUBMISSION": config.get( |
61 | | - "ena", |
62 | | - "development-submission-url", |
63 | | - fallback="https://wwwdev.ebi.ac.uk/biosamples/samples/submit", |
64 | | - ), |
65 | | - "DATA-SUBMISSION": config.get( |
66 | | - "ena", |
67 | | - "development-data-submission-url", |
68 | | - fallback="webin2.ebi.ac.uk", |
69 | | - ), |
70 | | - }, |
71 | | - "WEBIN": { |
72 | | - "SERVICE": config.get( |
73 | | - "webin", |
74 | | - "development-url", |
75 | | - fallback="https://wwwdev.ebi.ac.uk/ena/submit/webin/auth", |
76 | | - ), |
77 | | - "TOKEN": config.get( |
78 | | - "webin", |
79 | | - "development-token-url", |
80 | | - fallback="https://wwwdev.ebi.ac.uk/ena/submit/webin/auth/token", |
81 | | - ), |
82 | | - }, |
83 | | - "METABOLIGHTS": { |
84 | | - "SERVICE": config.get( |
85 | | - "metabolights", |
86 | | - "development-url", |
87 | | - fallback="https://www-test.ebi.ac.uk/metabolights/mars/ws3/submissions/", |
88 | | - ), |
89 | | - "SUBMISSION": config.get( |
90 | | - "metabolights", |
91 | | - "development-submission-url", |
92 | | - fallback="https://www-test.ebi.ac.uk/metabolights/mars/ws3/submissions/", |
93 | | - ), |
94 | | - "TOKEN": config.get( |
95 | | - "metabolights", |
96 | | - "development-token-url", |
97 | | - fallback="https://www-test.ebi.ac.uk/metabolights/mars/ws3/auth/token", |
98 | | - ), |
99 | | - }, |
100 | | - "BIOSAMPLES": { |
101 | | - "SERVICE": config.get( |
102 | | - "biosamples", |
103 | | - "development-url", |
104 | | - fallback="https://wwwdev.ebi.ac.uk/biosamples/samples/", |
105 | | - ), |
106 | | - "SUBMISSION": config.get( |
107 | | - "biosamples", |
108 | | - "development-submission-url", |
109 | | - fallback="https://wwwdev.ebi.ac.uk/biosamples/samples/", |
110 | | - ), |
111 | | - }, |
112 | | - }, |
113 | | - "PROD": { |
114 | | - "ENA": { |
115 | | - "SERVICE": config.get( |
116 | | - "ena", |
117 | | - "production-url", |
118 | | - fallback="https://www.ebi.ac.uk/ena/submit/webin-v2/", |
119 | | - ), |
120 | | - "SUBMISSION": config.get( |
121 | | - "ena", |
122 | | - "production-submission-url", |
123 | | - fallback="https://www.ebi.ac.uk/ena/submit/drop-box/submit/?auth=ENA", |
124 | | - ), |
125 | | - "DATA-SUBMISSION": config.get( |
126 | | - "ena", |
127 | | - "development-data-submission-url", |
128 | | - fallback="webin2.ebi.ac.uk", |
129 | | - ), |
130 | | - }, |
131 | | - "WEBIN": { |
132 | | - "SERVICE": config.get( |
133 | | - "webin", |
134 | | - "production-url", |
135 | | - fallback="https://wwwdev.ebi.ac.uk/ena/dev/submit/webin/auth", |
136 | | - ), |
137 | | - "TOKEN": config.get( |
138 | | - "webin", |
139 | | - "production-token-url", |
140 | | - fallback="https://wwwdev.ebi.ac.uk/ena/dev/submit/webin/auth/token", |
141 | | - ), |
142 | | - }, |
143 | | - "METABOLIGHTS": { |
144 | | - "SERVICE": config.get( |
145 | | - "metabolights", |
146 | | - "production-url", |
147 | | - fallback="https://www-test.ebi.ac.uk/metabolights/mars/ws3/submissions/", |
148 | | - ), |
149 | | - "SUBMISSION": config.get( |
150 | | - "metabolights", |
151 | | - "production-submission-url", |
152 | | - fallback="https://www-test.ebi.ac.uk/metabolights/mars/ws3/submissions/", |
153 | | - ), |
154 | | - "TOKEN": config.get( |
155 | | - "metabolights", |
156 | | - "production-token-url", |
157 | | - fallback="https://www-test.ebi.ac.uk/metabolights/mars/ws3/auth/token", |
158 | | - ), |
159 | | - }, |
160 | | - "BIOSAMPLES": { |
161 | | - "SERVICE": config.get( |
162 | | - "biosamples", |
163 | | - "production-url", |
164 | | - fallback="https://www.ebi.ac.uk/biosamples/samples/", |
165 | | - ), |
166 | | - "SUBMISSION": config.get( |
167 | | - "biosamples", |
168 | | - "production-submission-url", |
169 | | - fallback="https://www.ebi.ac.uk/biosamples/samples/", |
170 | | - ), |
171 | | - }, |
172 | | - }, |
173 | | -} |
| 33 | +urls = TargetRepository.get_repository_urls_from_config(config) |
174 | 34 |
|
175 | 35 |
|
176 | 36 | @click.group() |
|
183 | 43 | @click.pass_context |
184 | 44 | def cli(ctx, development): |
185 | 45 | print_and_log("############# Welcome to the MARS CLI. #############") |
| 46 | + print_and_log( |
| 47 | + "Sensitive information might be dumped in the log files when setting the 'log_level' to DEBUG in the config file. Logging in debug mode should only be used for developing purpose a can implicate security issues if used in a production environment!", |
| 48 | + "debug", |
| 49 | + ) |
186 | 50 | print_and_log( |
187 | 51 | f"Running in {'Development environment' if development else 'Production environment'}" |
188 | 52 | ) |
|
0 commit comments