Skip to content

Commit 9de7575

Browse files
committed
add support for copying files after download
1 parent fc1b706 commit 9de7575

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

geospaas_rest_api/processing_api/models.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ class Meta:
8080

8181
@classmethod
8282
def get_signature(cls, parameters):
83-
tasks = [tasks_core.download.signature()]
83+
tasks = [
84+
tasks_core.download.signature(),
85+
tasks_core.copy.signature(kwargs={'copy_to': parameters.get('copy_to', None)}),
86+
]
8487

8588
# only unarchive if cropping is needed
8689
bounding_box = parameters.get('bounding_box', None)
@@ -104,8 +107,10 @@ def check_parameters(parameters):
104107
- dataset_id: integer
105108
- bounding_box: 4-elements list
106109
"""
107-
if not set(parameters).issubset(set(('dataset_id', 'bounding_box', 'publish'))):
108-
raise ValidationError("The download action accepts only one parameter: 'dataset_id'")
110+
allowed_parameters = ('dataset_id', 'bounding_box', 'publish', 'copy_to')
111+
if not set(parameters).issubset(set(allowed_parameters)):
112+
raise ValidationError(
113+
f"The download action accepts only the following parameters: {allowed_parameters}")
109114
if not isinstance(parameters['dataset_id'], int):
110115
raise ValidationError("'dataset_id' must be an integer")
111116
if ('bounding_box' in parameters and
@@ -115,6 +120,8 @@ def check_parameters(parameters):
115120
"west, north, east, south")
116121
if ('publish' in parameters and not isinstance(parameters['publish'], bool)):
117122
raise ValidationError("'publish' must be a boolean")
123+
if 'copy_to' in parameters and not isinstance(parameters['copy_to'], str):
124+
raise ValidationError("'copy_to' must be a string")
118125
return parameters
119126

120127
@staticmethod
@@ -136,6 +143,7 @@ def get_signature(cls, parameters):
136143
if conversion_format == 'idf':
137144
return celery.chain(
138145
tasks_core.download.signature(),
146+
tasks_core.copy.signature(copy_to=parameters.get('copy_to', None)),
139147
tasks_core.unarchive.signature(),
140148
tasks_core.crop.signature(
141149
kwargs={'bounding_box': parameters.get('bounding_box', None)}),
@@ -145,6 +153,7 @@ def get_signature(cls, parameters):
145153
elif conversion_format == 'syntool':
146154
syntool_tasks = [
147155
tasks_core.download.signature(),
156+
tasks_core.copy.signature(kwargs={'copy_to': parameters.get('copy_to', None)}),
148157
tasks_core.unarchive.signature(),
149158
tasks_core.crop.signature(
150159
kwargs={'bounding_box': parameters.get('bounding_box', None)}),
@@ -181,7 +190,8 @@ def check_parameters(parameters):
181190
'skip_check',
182191
'converter_options',
183192
'remove_downloaded',
184-
'ttl')
193+
'ttl',
194+
'copy_to')
185195
if not set(parameters).issubset(set(accepted_keys)):
186196
raise ValidationError(
187197
f"The convert action accepts only these parameters: {', '.join(accepted_keys)}")
@@ -208,6 +218,9 @@ def check_parameters(parameters):
208218
parameters['ttl'] is None or isinstance(parameters['ttl'], dict))):
209219
raise ValidationError("'ttl' should be a dictionary or None")
210220

221+
if 'copy_to' in parameters and not isinstance(parameters['copy_to'], str):
222+
raise ValidationError("'copy_to' must be a string")
223+
211224
return parameters
212225

213226
@staticmethod

0 commit comments

Comments
 (0)