Skip to content

Commit 36cc747

Browse files
authored
Merge pull request #42 from eodms-sgdot/development
Development
2 parents a9de0a9 + 43dc2ba commit 36cc747

File tree

10 files changed

+888
-596
lines changed

10 files changed

+888
-596
lines changed

eodms_cli.py

Lines changed: 373 additions & 209 deletions
Large diffs are not rendered by default.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
py-eodms-rapi>=1.4.5
1+
py-eodms-rapi>=1.5.0
22
requests>=2.23.0
33
dateparser>=1.0.0
44
geomet>=0.3.0

scripts/config_util.py

Lines changed: 33 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
##############################################################################
2+
#
3+
# Copyright (c) His Majesty the King in Right of Canada, as
4+
# represented by the Minister of Natural Resources, 2023
5+
#
6+
# Licensed under the MIT license
7+
# (see LICENSE or <http://opensource.org/licenses/MIT>) All files in the
8+
# project carrying such notice may not be copied, modified, or distributed
9+
# except according to those terms.
10+
#
11+
##############################################################################
12+
113
import configparser
214
import os
315
import shutil
@@ -50,7 +62,10 @@ def __init__(self):
5062
"# The minimum date the download files will "
5163
"be kept; all files prior to this date will "
5264
"be deleted (format = yyyy-mm-dd)": None,
53-
"keep_downloads": ''},
65+
"keep_downloads": '',
66+
"# Determines whether to use colours in the "
67+
"CLI output": None,
68+
"colourize": 'True'},
5469
"Credentials":
5570
{"# Username of the eodms account used to "
5671
"access the rapi": None,
@@ -83,113 +98,6 @@ def __init__(self):
8398
}
8499
}
85100

86-
# # The contents of the configuration file
87-
# self.config_contents = {'Paths':
88-
# [
89-
# {
90-
# 'name': 'downloads',
91-
# 'desc': 'Path of the image files downloaded from the '
92-
# 'RAPI; if blank, files will be saved in the '
93-
# 'script folder under "downloads"',
94-
# 'default': '',
95-
# 'value': None
96-
# },
97-
# {
98-
# 'name': 'results',
99-
# 'desc': 'Path of the results CSV files from the '
100-
# 'script; if blank, files will be saved in the '
101-
# 'script folder under "results"',
102-
# 'default': '',
103-
# 'value': None
104-
# },
105-
# {
106-
# 'name': 'log',
107-
# 'desc': 'Path of the log files; if blank, log files '
108-
# 'will be saved in the script folder under '
109-
# '"log"',
110-
# 'default': '',
111-
# 'value': None
112-
# }
113-
# ],
114-
# 'Script':
115-
# [
116-
#
117-
# {
118-
# 'name': 'keep_results',
119-
# 'desc': 'The minimum date the CSV result files will be '
120-
# 'kept; all files prior to this date will be '
121-
# 'deleted (format: yyyy-mm-dd)',
122-
# 'default': '',
123-
# 'value': None
124-
# },
125-
# {
126-
# 'name': 'keep_downloads',
127-
# 'desc': 'The minimum date the download files will be kept; '
128-
# 'all files prior to this date will be deleted '
129-
# '(format: yyyy-mm-dd)',
130-
# 'default': '',
131-
# 'value': None
132-
# }
133-
# ],
134-
# 'Credentials':
135-
# [
136-
# {
137-
# 'name': 'username',
138-
# 'desc': 'Username of the EODMS account used to access '
139-
# 'the RAPI',
140-
# 'default': '',
141-
# 'value': None
142-
# },
143-
# {
144-
# 'name': 'password',
145-
# 'desc': 'Password of the EODMS account used to access '
146-
# 'the RAPI',
147-
# 'default': '',
148-
# 'value': None
149-
# },
150-
# ],
151-
# 'RAPI':
152-
# [
153-
# {
154-
# 'name': 'access_attempts',
155-
# 'desc': 'Number of attempts made to the rapi when a '
156-
# 'timeout occurs',
157-
# 'default': 4,
158-
# 'value': None
159-
# },
160-
# {
161-
# 'name': 'max_results',
162-
# 'desc': 'Maximum number of results to return from the '
163-
# 'RAPI',
164-
# 'default': 1000,
165-
# 'value': None
166-
# },
167-
# {
168-
# 'name': 'timeout_query',
169-
# 'desc': 'Number of seconds before a timeout occurs '
170-
# 'when querying the RAPI',
171-
# 'default': 120.0,
172-
# 'value': None
173-
# },
174-
# {
175-
# 'name': 'timeout_order',
176-
# 'desc': 'Number of seconds before a timeout occurs '
177-
# 'when ordering using the RAPI',
178-
# 'default': 180.0,
179-
# 'value': None
180-
# },
181-
# {
182-
# 'name': 'order_check_date',
183-
# 'desc': 'When checking for AVAILABLE_FOR_DOWNLOAD '
184-
# 'orders, this date is the earliest they '
185-
# 'will be checked. Can be hours, days, '
186-
# 'months or years',
187-
# 'default': '3 days',
188-
# 'value': None
189-
# },
190-
# ]
191-
# }
192-
193101
def _set_dict(self, dict_sect, sections, option):
194102
"""
195103
Sets a value in the config_dict based on an option from the config_info
@@ -212,8 +120,10 @@ def _set_dict(self, dict_sect, sections, option):
212120

213121
for sec in sections:
214122
if self.config_info.has_option(sec, option):
215-
self.config_dict[dict_sect][option] = self.config_info.get(
216-
sec, option)
123+
val = self.config_info.get(sec, option)
124+
if val.lower() == 'true' or val.lower() == 'false':
125+
val = eval(val)
126+
self.config_dict[dict_sect][option] = val
217127

218128
def _ask_input(self, section, in_opts):
219129

@@ -282,7 +192,7 @@ def ask_user(self, in_sect='all'):
282192
if sect_title not in self.config_dict.keys():
283193
err = f"The section '{sect_title}' does not exist in the " \
284194
f"configuration file."
285-
print(f"WARNING: {err}")
195+
self.eod.print_msg(err, heading="warning")
286196
self.logger.warning(err)
287197
return None
288198

@@ -304,7 +214,7 @@ def ask_user(self, in_sect='all'):
304214
if sect_opts is None:
305215
err = f"The section '{in_sect}' does not exist in the " \
306216
f"configuration file."
307-
print(f"WARNING: {err}")
217+
self.eod.print_msg(err, heading="warning")
308218
self.logger.warning(err)
309219
return None
310220

@@ -369,6 +279,16 @@ def ask_user(self, in_sect='all'):
369279
#
370280
# return out_str
371281

282+
def get_filename(self):
283+
"""
284+
Gets the filename and path of the configuration file being used.
285+
286+
:return: The path of the configuration file.
287+
:rtype: str
288+
"""
289+
290+
return self.config_fn
291+
372292
def get_info(self):
373293
"""
374294
Gets the configuration parser object
@@ -434,6 +354,7 @@ def update_dict(self):
434354

435355
self._set_dict('Script', 'Script', 'keep_results')
436356
self._set_dict('Script', 'Script', 'keep_downloads')
357+
self._set_dict('Script', 'Script', 'colourize')
437358

438359
cr = ['Credentials', 'RAPI'] # For backwards compatibility
439360
self._set_dict('Credentials', cr, 'username')

scripts/csv_util.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
##############################################################################
2-
# MIT License
3-
#
2+
#
43
# Copyright (c) His Majesty the King in Right of Canada, as
5-
# represented by the Minister of Natural Resources, 2023.
6-
#
7-
# Permission is hereby granted, free of charge, to any person obtaining a
8-
# copy of this software and associated documentation files (the "Software"),
9-
# to deal in the Software without restriction, including without limitation
10-
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
11-
# and/or sell copies of the Software, and to permit persons to whom the
12-
# Software is furnished to do so, subject to the following conditions:
13-
#
14-
# The above copyright notice and this permission notice shall be included in
15-
# all copies or substantial portions of the Software.
4+
# represented by the Minister of Natural Resources, 2023
165
#
17-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22-
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23-
# DEALINGS IN THE SOFTWARE.
6+
# Licensed under the MIT license
7+
# (see LICENSE or <http://opensource.org/licenses/MIT>) All files in the
8+
# project carrying such notice may not be copied, modified, or distributed
9+
# except according to those terms.
2410
#
2511
##############################################################################
2612

@@ -98,7 +84,7 @@ def determine_collection(self, rec):
9884
self.coll_id = self.eod.get_collid_by_name(satellite)
9985
msg = f"The satellite/collection '{self.coll_id}'' is " \
10086
f"not supported with this script at this time."
101-
print(f"\n{msg}")
87+
self.eod.print_msg(msg, heading="warning")
10288
self.logger.warning(msg)
10389
return None
10490

0 commit comments

Comments
 (0)