|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -125,20 +125,21 class JROAPI(): | |||
|
125 | 125 | except: |
|
126 | 126 | _, exc_value, _ = sys.exc_info() |
|
127 | 127 | return exc_value |
|
128 | ||
|
129 |
def upload_file(self, dataset_id, |
|
|
128 | ||
|
129 | def upload_file(self, dataset_id, file_date, file_type, file_path=False, url_or_path=False, ignore_repetition=False, **kwargs): | |
|
130 | 130 | # Agregar si es interruptido por teclado |
|
131 | 131 | ''' |
|
132 | 132 | FINALIDAD: |
|
133 |
Funcion para |
|
|
133 | Funcion para crear un unico recurso (puede incluir un archivo asociado) al repositorio del ROJ. | |
|
134 | 134 | |
|
135 | 135 | PARAMETROS DISPONIBLES: |
|
136 | 136 | CONSULTAR: "GUIA DE SCRIPT.pdf" |
|
137 | 137 | |
|
138 | 138 | ESTRUCTURA: |
|
139 |
<access_name>.upload_file(dataset_id = <class 'str'>, file_date = <class 'str'>, file_ |
|
|
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 | 143 | for key1, value1 in kwargs.items(): |
|
143 | 144 | if not key1 in self.list: |
|
144 | 145 | self.dict[key1] = value1 |
@@ -151,9 +152,22 class JROAPI(): | |||
|
151 | 152 | self.dict['others'] = json.dumps(kwargs['others']) |
|
152 | 153 | #---------------------------# |
|
153 | 154 | |
|
154 | if not os.path.isfile(file_path): | |
|
155 | return 'File "%s" not exist' % (file_path) | |
|
156 | ||
|
155 | if isinstance(file_path, str) and isinstance(url_or_path, str): | |
|
156 | return 'ERROR:: Choose one: "file_path" or "url_or_path" parameters' | |
|
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 | 171 | #if not 'format' in self.dict: |
|
158 | 172 | # self.str = ''.join(pathlib.Path(file_path).suffixes) |
|
159 | 173 | # if len(self.str) > 0: |
@@ -171,12 +185,13 class JROAPI(): | |||
|
171 | 185 | for u in dataset_show: |
|
172 | 186 | resources_name.append(u['name'].lower()) |
|
173 | 187 | |
|
174 |
if |
|
|
175 | return 'ERROR:: "%s" file already exist in this dataset' % (os.path.basename(file_path)) | |
|
188 | if self.dict['name'].lower() in resources_name: | |
|
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 | 193 | try: |
|
179 |
return getattr(self.ckan.action, 'resource_create')(package_id=dataset_id, file_date=file_date, |
|
|
194 | return getattr(self.ckan.action, 'resource_create')(package_id=dataset_id, file_date=file_date, voc_file_type=file_type, **self.dict) | |
|
180 | 195 | except: |
|
181 | 196 | _, exc_value, _ = sys.exc_info() |
|
182 | 197 | return exc_value |
General Comments 0
You need to be logged in to leave comments.
Login now