|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -11,7 +11,7 import zipfile | |||
|
11 | 11 | import concurrent.futures |
|
12 | 12 | import requests |
|
13 | 13 | import json |
|
14 | import pathlib | |
|
14 | #import pathlib | |
|
15 | 15 | import uuid |
|
16 | 16 | |
|
17 | 17 | class JROAPI(): |
@@ -25,7 +25,6 class JROAPI(): | |||
|
25 | 25 | En Python 2 |
|
26 | 26 | - pip install ckanapi==4.5 |
|
27 | 27 | - pip install requests |
|
28 | - pip install pathlib | |
|
29 | 28 | - pip install futures |
|
30 | 29 | - pip install tqdm |
|
31 | 30 | En Python > 3 |
@@ -67,6 +66,7 class JROAPI(): | |||
|
67 | 66 | self.ckan = RemoteCKAN(url, apikey=Authorization, user_agent=ua) |
|
68 | 67 | #self.ckan = RemoteCKAN(url, apikey=Authorization) |
|
69 | 68 | self.Authorization = Authorization |
|
69 | # Change for --> self.separator = os.sep | |
|
70 | 70 | if platform.system() == 'Windows': |
|
71 | 71 | self.separator = '\\' |
|
72 | 72 | else: |
@@ -139,13 +139,13 class JROAPI(): | |||
|
139 | 139 | if not os.path.isfile(file_path): |
|
140 | 140 | return 'File "%s" not exist' % (file_path) |
|
141 | 141 | |
|
142 | if not 'format' in self.dict: | |
|
143 | self.str = ''.join(pathlib.Path(file_path).suffixes) | |
|
144 | if len(self.str) > 0: | |
|
145 | self.dict['format'] = self.str.upper()[1:] | |
|
142 | #if not 'format' in self.dict: | |
|
143 | # self.str = ''.join(pathlib.Path(file_path).suffixes) | |
|
144 | # if len(self.str) > 0: | |
|
145 | # self.dict['format'] = self.str.upper()[1:] | |
|
146 | 146 | |
|
147 | 147 | 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= |
|
|
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) | |
|
149 | 149 | except: |
|
150 | 150 | _, exc_value, _ = sys.exc_info() |
|
151 | 151 | return exc_value |
@@ -192,12 +192,12 class JROAPI(): | |||
|
192 | 192 | path_files.sort() |
|
193 | 193 | for u in path_files: |
|
194 | 194 | if os.path.isfile(u): |
|
195 |
if |
|
|
195 | if os.path.basename(u).lower() in resources_name: | |
|
196 | 196 | if not ignore_repetition: |
|
197 |
return 'ERROR:: "%s" file already exist in this dataset' % ( |
|
|
198 |
print('WARRING:: "'+ str( |
|
|
197 | return 'ERROR:: "%s" file already exist in this dataset' % (os.path.basename(u)) | |
|
198 | print('WARRING:: "'+ str(os.path.basename(u)) +'" file was ignored because already exist in this dataset') | |
|
199 | 199 | else: |
|
200 |
total_list.append({'name': |
|
|
200 | total_list.append({'name':os.path.basename(u), 'size': os.stat(u).st_size, 'upload':open(u, 'rb')}) | |
|
201 | 201 | else: |
|
202 | 202 | return 'File "%s" does not exist' % (u) |
|
203 | 203 | else: |
@@ -262,10 +262,10 class JROAPI(): | |||
|
262 | 262 | value2['voc_file_type'] = file_type |
|
263 | 263 | value2.update(self.dict) |
|
264 | 264 | |
|
265 | if not 'format' in value2: | |
|
266 | format = ''.join(pathlib.Path(value2['name']).suffixes) | |
|
267 | if len(format) > 0: | |
|
268 | value2['format'] = format.upper()[1:] | |
|
265 | #if not 'format' in value2: | |
|
266 | # format = ''.join(pathlib.Path(value2['name']).suffixes) | |
|
267 | # if len(format) > 0: | |
|
268 | # value2['format'] = format.upper()[1:] | |
|
269 | 269 | |
|
270 | 270 | files_dict['update__resources__-'+ str(len(block)-count2) +'__upload'] = (value2['name'], value2['upload']) |
|
271 | 271 | del value2['upload'] |
@@ -302,8 +302,8 class JROAPI(): | |||
|
302 | 302 | ''' |
|
303 | 303 | |
|
304 | 304 | params_dict = {'upload':[], 'name':[]} |
|
305 | if not 'format' in kwargs: | |
|
306 | params_dict.update({'format':[]}) | |
|
305 | #if not 'format' in kwargs: | |
|
306 | # params_dict.update({'format':[]}) | |
|
307 | 307 | #---------------CASO : "path" or "path_list"-----------------# |
|
308 | 308 | if type(path_files) is list: |
|
309 | 309 | if len(path_files) != 0: |
@@ -311,13 +311,13 class JROAPI(): | |||
|
311 | 311 | for u in path_files: |
|
312 | 312 | if os.path.isfile(u): |
|
313 | 313 | params_dict['upload'].append(open(u, 'rb')) |
|
314 |
params_dict['name'].append( |
|
|
315 | if not 'format' in kwargs: | |
|
316 | format = ''.join(pathlib.Path(u).suffixes) | |
|
317 | if len(format) > 0: | |
|
318 | params_dict['format'].append(format.upper()[1:]) | |
|
319 | else: | |
|
320 | params_dict['format'].append('') | |
|
314 | params_dict['name'].append(os.path.basename(u)) | |
|
315 | #if not 'format' in kwargs: | |
|
316 | # format = ''.join(pathlib.Path(u).suffixes) | |
|
317 | # if len(format) > 0: | |
|
318 | # params_dict['format'].append(format.upper()[1:]) | |
|
319 | # else: | |
|
320 | # params_dict['format'].append('') | |
|
321 | 321 | else: |
|
322 | 322 | return 'File "%s" does not exist' % (u) |
|
323 | 323 | else: |
@@ -330,12 +330,12 class JROAPI(): | |||
|
330 | 330 | for name in path_order: |
|
331 | 331 | params_dict['upload'].append(open(os.path.join(path_files, name), 'rb')) |
|
332 | 332 | params_dict['name'].append(name) |
|
333 | if not 'format' in kwargs: | |
|
334 | format = ''.join(pathlib.Path(name).suffixes) | |
|
335 | if len(format) > 0: | |
|
336 | params_dict['format'].append(format.upper()[1:]) | |
|
337 | else: | |
|
338 | params_dict['format'].append('') | |
|
333 | #if not 'format' in kwargs: | |
|
334 | # format = ''.join(pathlib.Path(name).suffixes) | |
|
335 | # if len(format) > 0: | |
|
336 | # params_dict['format'].append(format.upper()[1:]) | |
|
337 | # else: | |
|
338 | # params_dict['format'].append('') | |
|
339 | 339 | else: |
|
340 | 340 | return "ERROR:: There aren't files in this directory" |
|
341 | 341 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now