##// END OF EJS Templates
v2.9.2 :: Update 'upload_file' function - Add empty resource
eynilupu -
r14:a8d46058b456
parent child
Show More
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -125,20 +125,21 class JROAPI():
125 except:
125 except:
126 _, exc_value, _ = sys.exc_info()
126 _, exc_value, _ = sys.exc_info()
127 return exc_value
127 return exc_value
128
128
129 def upload_file(self, dataset_id, file_path, file_date, file_type, **kwargs):
129 def upload_file(self, dataset_id, file_date, file_type, file_path=False, url_or_path=False, ignore_repetition=False, **kwargs):
130 # Agregar si es interruptido por teclado
130 # Agregar si es interruptido por teclado
131 '''
131 '''
132 FINALIDAD:
132 FINALIDAD:
133 Funcion para subir un unico archivo al repositorio del ROJ.
133 Funcion para crear un unico recurso (puede incluir un archivo asociado) al repositorio del ROJ.
134
134
135 PARAMETROS DISPONIBLES:
135 PARAMETROS DISPONIBLES:
136 CONSULTAR: "GUIA DE SCRIPT.pdf"
136 CONSULTAR: "GUIA DE SCRIPT.pdf"
137
137
138 ESTRUCTURA:
138 ESTRUCTURA:
139 <access_name>.upload_file(dataset_id = <class 'str'>, file_date = <class 'str'>, file_path = <class 'str'>, file_type = <class 'str'>, param_1 = <class 'param_1'>, ...)
139 <access_name>.upload_file(dataset_id = <class 'str'>, file_date = <class 'str'>, file_type = <class 'str'>, file_path = <class 'str'>, url_or_path = <class 'str'>, param_1 = <class 'param_1'>, ...)
140 '''
140 '''
141 self.list = ['package_id', 'upload', 'voc_file_type', 'name'] #file_date
141 #self.list = ['package_id', 'upload', 'voc_file_type', 'name'] #file_date
142 self.list = ['package_id', 'upload', 'voc_file_type'] #file_date
142 for key1, value1 in kwargs.items():
143 for key1, value1 in kwargs.items():
143 if not key1 in self.list:
144 if not key1 in self.list:
144 self.dict[key1] = value1
145 self.dict[key1] = value1
@@ -151,9 +152,22 class JROAPI():
151 self.dict['others'] = json.dumps(kwargs['others'])
152 self.dict['others'] = json.dumps(kwargs['others'])
152 #---------------------------#
153 #---------------------------#
153
154
154 if not os.path.isfile(file_path):
155 if isinstance(file_path, str) and isinstance(url_or_path, str):
155 return 'File "%s" not exist' % (file_path)
156 return 'ERROR:: Choose one: "file_path" or "url_or_path" parameters'
156
157
158 if isinstance(file_path, str):
159 if not os.path.isfile(file_path):
160 return 'File "%s" not exist' % (file_path)
161
162 self.dict['upload'] = open(file_path, 'rb')
163 self.dict['name'] = os.path.basename(file_path)
164 elif isinstance(url_or_path, str):
165 self.dict['url'] = url_or_path
166 if not 'name' in self.dict:
167 self.dict['name'] = os.path.basename(url_or_path)
168 else:
169 return 'ERROR: Verify "file_path" or "url_or_path" parameters: <class "str"> or choose one'
170
157 #if not 'format' in self.dict:
171 #if not 'format' in self.dict:
158 # self.str = ''.join(pathlib.Path(file_path).suffixes)
172 # self.str = ''.join(pathlib.Path(file_path).suffixes)
159 # if len(self.str) > 0:
173 # if len(self.str) > 0:
@@ -171,12 +185,13 class JROAPI():
171 for u in dataset_show:
185 for u in dataset_show:
172 resources_name.append(u['name'].lower())
186 resources_name.append(u['name'].lower())
173
187
174 if os.path.basename(file_path).lower() in resources_name:
188 if self.dict['name'].lower() in resources_name:
175 return 'ERROR:: "%s" file already exist in this dataset' % (os.path.basename(file_path))
189 if not ignore_repetition:
190 return 'ERROR:: "%s" resource already exist in this dataset' % (self.dict['name'])
191 print('WARRING:: "'+ str(self.dict['name']) +'" resource already exist in this dataset')
176 #------------------------------------------------------------#
192 #------------------------------------------------------------#
177
178 try:
193 try:
179 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)
194 return getattr(self.ckan.action, 'resource_create')(package_id=dataset_id, file_date=file_date, voc_file_type=file_type, **self.dict)
180 except:
195 except:
181 _, exc_value, _ = sys.exc_info()
196 _, exc_value, _ = sys.exc_info()
182 return exc_value
197 return exc_value
@@ -15,8 +15,6 else:
15
15
16 DL_CHUNK_SIZE = 100 * 1024
16 DL_CHUNK_SIZE = 100 * 1024
17
17
18 print()
19
20 def dump_things_change(ckan, thing, arguments, worker_pool=None, stdout=None, stderr=None, **kwargs):
18 def dump_things_change(ckan, thing, arguments, worker_pool=None, stdout=None, stderr=None, **kwargs):
21 if worker_pool is None:
19 if worker_pool is None:
22 worker_pool = workers.worker_pool
20 worker_pool = workers.worker_pool
General Comments 0
You need to be logged in to leave comments. Login now