11# Standard library imports
22import base64
33import os
4+ import time
45import uuid
56
67# Third party imports
1415from .geode_objects import objects_list
1516
1617
17- def list_objects_input_extensions (
18- is_viewable : bool = True ,
19- geode_object : str = "" ,
20- ):
18+ def list_all_input_extensions (crs = False ):
2119 """
2220 Purpose:
2321 Function that returns a list of all input extensions
22+ Args:
23+ crs -- Tells the function if we want the geode_objects that have a crs
2424 Returns:
2525 An ordered list of input file extensions
2626 """
27- return_list = []
28- objects_list = geode_objects .objects_list ()
29-
30- for object_ in objects_list .values ():
31- if object_ ["is_viewable" ] == is_viewable or geode_object == object_ :
32- values = object_ ["input" ]
33- for value in values :
34- list_creators = value .list_creators ()
35- for creator in list_creators :
36- if creator not in return_list :
37- return_list .append (creator )
38- return_list .sort ()
39- return return_list
27+ List = []
28+ geode_object_dict = objects_list ()
29+
30+ for geode_object in geode_object_dict .values ():
31+ values = geode_object ["input" ]
32+
33+ # if crs == True:
34+ # if "crs" not in geode_object:
35+ # continue
36+ for value in values :
37+ list_creators = value .list_creators ()
38+ for creator in list_creators :
39+ if creator not in List :
40+ List .append (creator )
41+ List .sort ()
42+ return List
4043
4144
4245def list_objects (extension : str , is_viewable : bool = True ):
@@ -49,15 +52,15 @@ def list_objects(extension: str, is_viewable: bool = True):
4952 An ordered list of object's names
5053 """
5154 return_list = []
52- objects_list = geode_objects . objects_list ()
53-
54- for object_ , values in objects_list .items ():
55- if values ["is_viewable" ] == is_viewable :
56- list_values = values ["input" ]
57- for value in list_values :
58- if value .has_creator (extension ):
59- if object_ not in return_list :
60- return_list .append (object_ )
55+ geode_object_dict = objects_list ()
56+
57+ for object_ , values in geode_object_dict .items ():
58+ # if values["is_viewable"] == is_viewable:
59+ list_values = values ["input" ]
60+ for value in list_values :
61+ if value .has_creator (extension ):
62+ if object_ not in return_list :
63+ return_list .append (object_ )
6164 return_list .sort ()
6265 return return_list
6366
@@ -72,9 +75,9 @@ def list_output_file_extensions(object: str):
7275 An ordered list of file extensions
7376 """
7477 List = []
75- objects_list = geode_objects . objects_list ()
78+ geode_object_dict = objects_list ()
7679
77- values = objects_list [object ]["output" ]
80+ values = geode_object_dict [object ]["output" ]
7881 for value in values :
7982 list_creators = value .list_creators ()
8083 for creator in list_creators :
@@ -107,22 +110,39 @@ def upload_file(file: str, file_name: str, upload_folder: str, file_size: int):
107110 f .close ()
108111
109112 final_size = os .path .getsize (file_path )
110- return int (file_size ) == int (final_size )
113+ uploaded_file = int (file_size ) == int (final_size )
114+ if not uploaded_file :
115+ flask .abort (500 , "File not uploaded" )
116+
117+
118+ def create_lock_file (
119+ folder_absolute_path ,
120+ ):
121+ if not os .path .exists (folder_absolute_path ):
122+ os .mkdir (folder_absolute_path )
123+ id = uuid .uuid4 ()
124+ file_absolute_path = f"{ folder_absolute_path } /{ str (id )} .txt"
125+ f = open (file_absolute_path , "a" )
126+ f .close ()
127+ flask .g .UUID = id
128+
111129
130+ def create_time_file (folder_absolute_path ):
131+ if not os .path .exists (folder_absolute_path ):
132+ os .mkdir (folder_absolute_path )
133+ file_path = f"{ folder_absolute_path } /time.txt"
134+ if not os .path .isfile (file_path ):
135+ f = open (file_path , "w" )
136+ f .close ()
112137
113- def create_lock_file ():
114- LOCK_FOLDER = flask .current_app .config ["LOCK_FOLDER" ]
115- if not os .path .exists (LOCK_FOLDER ):
116- os .mkdir (LOCK_FOLDER )
117- flask .g .UUID = uuid .uuid4 ()
118- file_path = f"{ LOCK_FOLDER } /{ str (flask .g .UUID )} .txt"
119- f = open (file_path , "a" )
138+ f = open (folder_absolute_path + "/time.txt" , "w" )
139+ f .write (str (time .time ()))
120140 f .close ()
121141
122142
123- def remove_lock_file ():
124- LOCK_FOLDER = flask .current_app . config [ "LOCK_FOLDER" ]
125- os .remove (f"{ LOCK_FOLDER } /{ str (flask . g . UUID )} .txt" )
143+ def remove_lock_file (folder_absolute_path ):
144+ id = flask .g . UUID
145+ os .remove (f"{ folder_absolute_path } /{ str (id )} .txt" )
126146
127147
128148def set_interval (func , sec ):
@@ -137,30 +157,30 @@ def func_wrapper():
137157
138158
139159def is_model (geode_object ):
140- return geode_objects . objects_list ()[geode_object ]["is_model" ]
160+ return objects_list ()[geode_object ]["is_model" ]
141161
142162
143163def is_3D (geode_object ):
144- return geode_objects . objects_list ()[geode_object ]["is_3D" ]
164+ return objects_list ()[geode_object ]["is_3D" ]
145165
146166
147167def get_builder (geode_object , data ):
148- return geode_objects . objects_list ()[geode_object ]["builder" ](data )
168+ return objects_list ()[geode_object ]["builder" ](data )
149169
150170
151- def load (file_path ):
152- return geode_objects . objects_list ()[geode_object ]["load" ](file_path )
171+ def load (geode_object , file_absolute_path ):
172+ return objects_list ()[geode_object ]["load" ](file_absolute_path )
153173
154174
155- def save (data , geode_object , folder , filename ):
156- geode_objects . objects_list ()[geode_object ]["save" ](
157- data , os .path .join (folder , filename )
175+ def save (data , geode_object , folder_absolute_path , filename ):
176+ objects_list ()[geode_object ]["save" ](
177+ data , os .path .join (folder_absolute_path , filename )
158178 )
159179
160180
161- def save_viewable (data , geode_object , folder , id ):
162- geode_objects . objects_list ()[geode_object ]["save_viewable" ](
163- data , os .path .join (folder , id )
181+ def save_viewable (data , geode_object , folder_absolute_path , id ):
182+ objects_list ()[geode_object ]["save_viewable" ](
183+ data , os .path .join (folder_absolute_path , id )
164184 )
165185
166186
@@ -220,15 +240,15 @@ def get_coordinate_system(geode_object, coordinate_system):
220240def assign_geographic_coordinate_system_info (geode_object , data , input_crs ):
221241 builder = get_builder (geode_object , data )
222242 info = get_geographic_coordinate_systems_info (geode_object , input_crs )
223- geode_objects . objects_list ()[geode_object ]["crs" ]["assign" ](
243+ objects_list ()[geode_object ]["crs" ]["assign" ](
224244 data , builder , input_crs ["name" ], info
225245 )
226246
227247
228248def convert_geographic_coordinate_system_info (geode_object , data , output_crs ):
229249 builder = get_builder (geode_object , data )
230250 info = get_geographic_coordinate_systems_info (geode_object , output_crs )
231- geode_objects . objects_list ()[geode_object ]["crs" ]["convert" ](
251+ objects_list ()[geode_object ]["crs" ]["convert" ](
232252 data , builder , output_crs ["name" ], info
233253 )
234254
@@ -244,6 +264,6 @@ def create_coordinate_system(
244264 output_coordiante_system = get_coordinate_system (
245265 geode_object , output_coordinate_points
246266 )
247- geode_objects . objects_list ()[geode_object ]["crs" ]["create" ](
267+ objects_list ()[geode_object ]["crs" ]["create" ](
248268 data , builder , name , input_coordiante_system , output_coordiante_system
249269 )
0 commit comments