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