|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -144,6 +144,22 class JROAPI(): | |||
|
144 | 144 | # if len(self.str) > 0: |
|
145 | 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 | 163 | try: |
|
148 | 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 | 165 | except: |
@@ -288,7 +304,7 class JROAPI(): | |||
|
288 | 304 | else: |
|
289 | 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 | 308 | # Agregar si es interruptido por teclado |
|
293 | 309 | ''' |
|
294 | 310 | FINALIDAD: |
@@ -300,6 +316,18 class JROAPI(): | |||
|
300 | 316 | ESTRUCTURA: |
|
301 | 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 | 332 | params_dict = {'upload':[], 'name':[]} |
|
305 | 333 | #if not 'format' in kwargs: |
@@ -310,6 +338,11 class JROAPI(): | |||
|
310 | 338 | path_files.sort() |
|
311 | 339 | for u in path_files: |
|
312 | 340 | if os.path.isfile(u): |
|
341 | if os.path.basename(u).lower() in resources_name: | |
|
342 | if not ignore_repetition: | |
|
343 | return 'ERROR:: "%s" file already exist in this dataset' % (os.path.basename(u)) | |
|
344 | print('WARRING:: "'+ str(os.path.basename(u)) +'" file was ignored because already exist in this dataset') | |
|
345 | else: | |
|
313 | 346 | params_dict['upload'].append(open(u, 'rb')) |
|
314 | 347 | params_dict['name'].append(os.path.basename(u)) |
|
315 | 348 | #if not 'format' in kwargs: |
@@ -328,6 +361,11 class JROAPI(): | |||
|
328 | 361 | path_order.sort() |
|
329 | 362 | if path_order: |
|
330 | 363 | for name in path_order: |
|
364 | if name.lower() in resources_name: | |
|
365 | if not ignore_repetition: | |
|
366 | return 'ERROR:: "%s" file already exist in this dataset' % (name) | |
|
367 | print('WARRING:: "'+ str(name) +'" file was ignored because already exist in this dataset') | |
|
368 | else: | |
|
331 | 369 | params_dict['upload'].append(open(os.path.join(path_files, name), 'rb')) |
|
332 | 370 | params_dict['name'].append(name) |
|
333 | 371 | #if not 'format' in kwargs: |
General Comments 0
You need to be logged in to leave comments.
Login now