1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -144,6 +144,22 class JROAPI(): | |||||
144 | # if len(self.str) > 0: |
|
144 | # if len(self.str) > 0: | |
145 | # self.dict['format'] = self.str.upper()[1:] |
|
145 | # self.dict['format'] = self.str.upper()[1:] | |
146 |
|
146 | |||
|
147 | #-------------------------PACKAGE SHOW-----------------------# | |||
|
148 | try: | |||
|
149 | dataset_show = getattr(self.ckan.action, 'package_show')(id=dataset_id)['resources'] | |||
|
150 | except: | |||
|
151 | _, exc_value, _ = sys.exc_info() | |||
|
152 | print('ERROR obtaining metadata dataset:: Use the "print" for more information') | |||
|
153 | return exc_value | |||
|
154 | ||||
|
155 | resources_name = [] | |||
|
156 | for u in dataset_show: | |||
|
157 | resources_name.append(u['name'].lower()) | |||
|
158 | ||||
|
159 | if os.path.basename(file_path).lower() in resources_name: | |||
|
160 | return 'ERROR:: "%s" file already exist in this dataset' % (os.path.basename(file_path)) | |||
|
161 | #------------------------------------------------------------# | |||
|
162 | ||||
147 | try: |
|
163 | try: | |
148 | return getattr(self.ckan.action, 'resource_create')(package_id=dataset_id, file_date=file_date, upload=open(file_path, 'rb'), voc_file_type=file_type, name=os.path.basename(file_path), **self.dict) |
|
164 | return getattr(self.ckan.action, 'resource_create')(package_id=dataset_id, file_date=file_date, upload=open(file_path, 'rb'), voc_file_type=file_type, name=os.path.basename(file_path), **self.dict) | |
149 | except: |
|
165 | except: | |
@@ -288,7 +304,7 class JROAPI(): | |||||
288 | else: |
|
304 | else: | |
289 | return "ERROR:: No file(s) found to upload" |
|
305 | return "ERROR:: No file(s) found to upload" | |
290 |
|
306 | |||
291 | def upload_multiple_files(self, dataset_id, path_files, date_files, type_files, **kwargs): |
|
307 | def upload_multiple_files(self, dataset_id, path_files, date_files, type_files, ignore_repetition=False, **kwargs): | |
292 | # Agregar si es interruptido por teclado |
|
308 | # Agregar si es interruptido por teclado | |
293 | ''' |
|
309 | ''' | |
294 | FINALIDAD: |
|
310 | FINALIDAD: | |
@@ -300,6 +316,18 class JROAPI(): | |||||
300 | ESTRUCTURA: |
|
316 | ESTRUCTURA: | |
301 | <access_name>.upload_multiple_files(dataset_id = <class 'str'>, path_files = <class 'str'> or <class 'list of strings'>, date_files = <class 'str'> or <class 'list of strings'>, type_files = <class 'str'> or <class 'list of strings'>, param_1 = <class 'param_1'>, ...) |
|
317 | <access_name>.upload_multiple_files(dataset_id = <class 'str'>, path_files = <class 'str'> or <class 'list of strings'>, date_files = <class 'str'> or <class 'list of strings'>, type_files = <class 'str'> or <class 'list of strings'>, param_1 = <class 'param_1'>, ...) | |
302 | ''' |
|
318 | ''' | |
|
319 | #-------------------------PACKAGE SHOW-----------------------# | |||
|
320 | try: | |||
|
321 | dataset_show = getattr(self.ckan.action, 'package_show')(id=dataset_id)['resources'] | |||
|
322 | except: | |||
|
323 | _, exc_value, _ = sys.exc_info() | |||
|
324 | print('ERROR obtaining metadata dataset:: Use the "print" for more information') | |||
|
325 | return exc_value | |||
|
326 | #------------------------------------------------------------# | |||
|
327 | resources_name = [] | |||
|
328 | for u in dataset_show: | |||
|
329 | resources_name.append(u['name'].lower()) | |||
|
330 | #------------------------------------------------------------# | |||
303 |
|
331 | |||
304 | params_dict = {'upload':[], 'name':[]} |
|
332 | params_dict = {'upload':[], 'name':[]} | |
305 | #if not 'format' in kwargs: |
|
333 | #if not 'format' in kwargs: | |
@@ -310,14 +338,19 class JROAPI(): | |||||
310 | path_files.sort() |
|
338 | path_files.sort() | |
311 | for u in path_files: |
|
339 | for u in path_files: | |
312 | if os.path.isfile(u): |
|
340 | if os.path.isfile(u): | |
313 | params_dict['upload'].append(open(u, 'rb')) |
|
341 | if os.path.basename(u).lower() in resources_name: | |
314 | params_dict['name'].append(os.path.basename(u)) |
|
342 | if not ignore_repetition: | |
315 | #if not 'format' in kwargs: |
|
343 | return 'ERROR:: "%s" file already exist in this dataset' % (os.path.basename(u)) | |
316 | # format = ''.join(pathlib.Path(u).suffixes) |
|
344 | print('WARRING:: "'+ str(os.path.basename(u)) +'" file was ignored because already exist in this dataset') | |
317 |
|
|
345 | else: | |
318 |
|
|
346 | params_dict['upload'].append(open(u, 'rb')) | |
319 | # else: |
|
347 | params_dict['name'].append(os.path.basename(u)) | |
320 |
|
|
348 | #if not 'format' in kwargs: | |
|
349 | # format = ''.join(pathlib.Path(u).suffixes) | |||
|
350 | # if len(format) > 0: | |||
|
351 | # params_dict['format'].append(format.upper()[1:]) | |||
|
352 | # else: | |||
|
353 | # params_dict['format'].append('') | |||
321 | else: |
|
354 | else: | |
322 | return 'File "%s" does not exist' % (u) |
|
355 | return 'File "%s" does not exist' % (u) | |
323 | else: |
|
356 | else: | |
@@ -328,14 +361,19 class JROAPI(): | |||||
328 | path_order.sort() |
|
361 | path_order.sort() | |
329 | if path_order: |
|
362 | if path_order: | |
330 | for name in path_order: |
|
363 | for name in path_order: | |
331 | params_dict['upload'].append(open(os.path.join(path_files, name), 'rb')) |
|
364 | if name.lower() in resources_name: | |
332 | params_dict['name'].append(name) |
|
365 | if not ignore_repetition: | |
333 | #if not 'format' in kwargs: |
|
366 | return 'ERROR:: "%s" file already exist in this dataset' % (name) | |
334 | # format = ''.join(pathlib.Path(name).suffixes) |
|
367 | print('WARRING:: "'+ str(name) +'" file was ignored because already exist in this dataset') | |
335 |
|
|
368 | else: | |
336 |
|
|
369 | params_dict['upload'].append(open(os.path.join(path_files, name), 'rb')) | |
337 |
|
|
370 | params_dict['name'].append(name) | |
338 |
|
|
371 | #if not 'format' in kwargs: | |
|
372 | # format = ''.join(pathlib.Path(name).suffixes) | |||
|
373 | # if len(format) > 0: | |||
|
374 | # params_dict['format'].append(format.upper()[1:]) | |||
|
375 | # else: | |||
|
376 | # params_dict['format'].append('') | |||
339 | else: |
|
377 | else: | |
340 | return "ERROR:: There aren't files in this directory" |
|
378 | return "ERROR:: There aren't files in this directory" | |
341 | else: |
|
379 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now