|
1 | 1 | # Standard library imports |
2 | 2 | import os |
3 | | -import time |
4 | | -import threading |
5 | | -import uuid |
6 | | -import zipfile |
7 | 3 |
|
8 | 4 | # Third party imports |
9 | 5 | import flask |
10 | 6 | import opengeode_geosciences as og_gs |
11 | 7 | import opengeode as og |
12 | | -import pkg_resources |
13 | | -from jsonschema import validate |
14 | | -from jsonschema.exceptions import ValidationError |
15 | 8 |
|
16 | 9 | # Local application imports |
17 | 10 | from .geode_objects import geode_objects_dict |
@@ -200,75 +193,6 @@ def get_inspector_children(obj): |
200 | 193 | return new_object |
201 | 194 |
|
202 | 195 |
|
203 | | -def versions(list_packages: list): |
204 | | - list_with_versions = [] |
205 | | - for package in list_packages: |
206 | | - list_with_versions.append( |
207 | | - { |
208 | | - "package": package, |
209 | | - "version": pkg_resources.get_distribution(package).version, |
210 | | - } |
211 | | - ) |
212 | | - return list_with_versions |
213 | | - |
214 | | - |
215 | | -def create_lock_file( |
216 | | - folder_absolute_path, |
217 | | -): |
218 | | - if not os.path.exists(folder_absolute_path): |
219 | | - os.mkdir(folder_absolute_path) |
220 | | - id = uuid.uuid4() |
221 | | - file_absolute_path = f"{folder_absolute_path}/{str(id)}.txt" |
222 | | - f = open(file_absolute_path, "a") |
223 | | - f.close() |
224 | | - flask.g.UUID = id |
225 | | - |
226 | | - |
227 | | -def create_time_file(folder_absolute_path): |
228 | | - if not os.path.exists(folder_absolute_path): |
229 | | - os.mkdir(folder_absolute_path) |
230 | | - file_path = f"{folder_absolute_path}/time.txt" |
231 | | - if not os.path.isfile(file_path): |
232 | | - f = open(file_path, "w") |
233 | | - f.close() |
234 | | - |
235 | | - f = open(folder_absolute_path + "/time.txt", "w") |
236 | | - f.write(str(time.time())) |
237 | | - f.close() |
238 | | - |
239 | | - |
240 | | -def remove_lock_file(folder_absolute_path): |
241 | | - id = flask.g.UUID |
242 | | - os.remove(f"{folder_absolute_path}/{str(id)}.txt") |
243 | | - |
244 | | - |
245 | | -def set_interval(func, sec): |
246 | | - def func_wrapper(): |
247 | | - set_interval(func, sec) |
248 | | - func() |
249 | | - |
250 | | - t = threading.Timer(sec, func_wrapper) |
251 | | - t.daemon = True |
252 | | - t.start() |
253 | | - return t |
254 | | - |
255 | | - |
256 | | -def extension_from_filename(filename): |
257 | | - return os.path.splitext(filename)[1][1:] |
258 | | - |
259 | | - |
260 | | -def validate_request(request, schema): |
261 | | - json_data = request.get_json(force=True, silent=True) |
262 | | - |
263 | | - if json_data is None: |
264 | | - json_data = {} |
265 | | - |
266 | | - try: |
267 | | - validate(instance=json_data, schema=schema) |
268 | | - except ValidationError as e: |
269 | | - flask.abort(400, f"Validation error: {e.message}") |
270 | | - |
271 | | - |
272 | 196 | def geographic_coordinate_systems(geode_object: str): |
273 | 197 | if is_3D(geode_object): |
274 | 198 | return og_gs.GeographicCoordinateSystem3D.geographic_coordinate_systems() |
@@ -329,41 +253,3 @@ def create_coordinate_system( |
329 | 253 | create_crs( |
330 | 254 | geode_object, data, name, input_coordiante_system, output_coordiante_system |
331 | 255 | ) |
332 | | - |
333 | | - |
334 | | -def send_file(upload_folder, saved_files, new_file_name): |
335 | | - if len(saved_files) == 1: |
336 | | - mimetype = "application/octet-binary" |
337 | | - else: |
338 | | - mimetype = "application/zip" |
339 | | - new_file_name = os.path.splitext(new_file_name)[0] + ".zip" |
340 | | - with zipfile.ZipFile(os.path.join(upload_folder, new_file_name), "w") as zipObj: |
341 | | - for saved_file_path in saved_files: |
342 | | - zipObj.write( |
343 | | - saved_file_path, |
344 | | - os.path.basename(saved_file_path), |
345 | | - ) |
346 | | - |
347 | | - response = flask.send_from_directory( |
348 | | - directory=upload_folder, |
349 | | - path=new_file_name, |
350 | | - as_attachment=True, |
351 | | - mimetype=mimetype, |
352 | | - ) |
353 | | - response.headers["new-file-name"] = new_file_name |
354 | | - response.headers["Access-Control-Expose-Headers"] = "new-file-name" |
355 | | - |
356 | | - return response |
357 | | - |
358 | | - |
359 | | -def handle_exception(e): |
360 | | - response = e.get_response() |
361 | | - response.data = flask.json.dumps( |
362 | | - { |
363 | | - "code": e.code, |
364 | | - "name": e.name, |
365 | | - "description": e.description, |
366 | | - } |
367 | | - ) |
368 | | - response.content_type = "application/json" |
369 | | - return response |
0 commit comments