Skip to content

Commit a86a117

Browse files
committed
rmv geode_functions
adapt generate_file for additional files
1 parent 1da5e31 commit a86a117

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/opengeodeweb_back/geode_functions.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,12 @@ def create_coordinate_system(
293293
)
294294

295295

296-
def file_exists_in_upload(filename: str) -> bool:
297-
"""Vérifie si un fichier existe dans le dossier d'upload."""
298-
file_path = upload_file_path(filename)
299-
return os.path.exists(file_path)
300-
301-
def file_exists_in_data(data_id: str, filename: str) -> bool:
302-
"""Vérifie si un fichier existe dans le dossier de données."""
303-
file_path = data_file_path(data_id, filename)
304-
return os.path.exists(file_path)
296+
# def file_exists_in_upload(filename: str) -> bool:
297+
# """Vérifie si un fichier existe dans le dossier d'upload."""
298+
# file_path = upload_file_path(filename)
299+
# return os.path.exists(file_path)
300+
301+
# def file_exists_in_data(data_id: str, filename: str) -> bool:
302+
# """Vérifie si un fichier existe dans le dossier de données."""
303+
# file_path = data_file_path(data_id, filename)
304+
# return os.path.exists(file_path)

src/opengeodeweb_back/utils_functions.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,21 @@ def generate_native_viewable_and_light_viewable(geode_object, data, original_fil
151151
name = data.name()
152152
object_type = geode_functions.get_object_type(geode_object)
153153

154-
os.makedirs(data_path, exist_ok=True)
154+
if not os.path.isdir(data_path):
155+
os.makedirs(data_path)
155156

156157
additional_files_copied = []
157158
if original_filename:
158159
original_file_path = geode_functions.upload_file_path(original_filename)
159160
additional = geode_functions.additional_files(geode_object, original_file_path)
160-
161+
161162
for additional_file in additional.mandatory_files + additional.optional_files:
162-
if not additional_file.is_missing and geode_functions.file_exists_in_upload(additional_file.filename):
163+
if not additional_file.is_missing:
163164
source_path = geode_functions.upload_file_path(additional_file.filename)
164-
dest_path = os.path.join(data_path, additional_file.filename)
165-
shutil.copy2(source_path, dest_path)
166-
additional_files_copied.append(additional_file.filename)
165+
if os.path.exists(source_path):
166+
dest_path = os.path.join(data_path, additional_file.filename)
167+
shutil.copy2(source_path, dest_path)
168+
additional_files_copied.append(additional_file.filename)
167169

168170
saved_native_file_path = geode_functions.save(
169171
geode_object,
@@ -178,21 +180,20 @@ def generate_native_viewable_and_light_viewable(geode_object, data, original_fil
178180
saved_light_viewable_file_path = geode_functions.save_light_viewable(
179181
geode_object, data, data_path, "light_viewable"
180182
)
181-
f = open(saved_light_viewable_file_path, "rb")
182-
binary_light_viewable = f.read()
183-
f.close()
183+
with open(saved_light_viewable_file_path, "rb") as f:
184+
binary_light_viewable = f.read()
184185

185186
result = {
186187
"name": name,
187188
"native_file_name": os.path.basename(saved_native_file_path[0]),
188189
"viewable_file_name": viewable_file_name,
189190
"id": generated_id,
190191
"object_type": object_type,
191-
"binary_light_viewable": str(binary_light_viewable, "utf-8"),
192+
"binary_light_viewable": binary_light_viewable.decode("utf-8"),
192193
"geode_object": geode_object,
193194
}
194-
195+
195196
if additional_files_copied:
196197
result["additional_files"] = additional_files_copied
197-
198+
198199
return result

0 commit comments

Comments
 (0)