Skip to content
Snippets Groups Projects
Commit c9a619fc authored by Riccardo Boero's avatar Riccardo Boero :innocent:
Browse files

Reverted directory routing logic

parent a6ea57fa
No related branches found
No related tags found
No related merge requests found
Pipeline #2009 failed
...@@ -50,40 +50,15 @@ class GeoTIFFService: ...@@ -50,40 +50,15 @@ class GeoTIFFService:
""" """
Sets up the Flask routes for the service. It creates a default route for the root directory Sets up the Flask routes for the service. It creates a default route for the root directory
and additional routes for each subdirectory within the GeoTIFF tiles directory. and additional routes for each subdirectory within the GeoTIFF tiles directory.
Each route corresponds to a POST endpoint for submitting geospatial queries. Each route corresponds to a POST endpoint for submitting geospatial queries.
If the directory doesn't exist or contains no subdirectories, it logs a message.
This method ensures the directory exists and handles missing or empty subdirectories gracefully.
The root directory ('/') will always have a route created, while additional routes
are created dynamically based on the presence of subdirectories in the specified GeoTIFF directory.
Raises:
ValueError: If the main directory does not exist.
""" """
# Create a route for the root directory (default route) # Create a route for the root directory (default route)
self.create_route('/', self.directory) self.create_route('/', self.directory)
# Ensure the directory exists before attempting to find subdirectories # Discover and create routes for subdirectories
if not os.path.exists(self.directory): for subdir in next(os.walk(self.directory))[1]:
raise ValueError(f"Directory {self.directory} does not exist.") subdir_path = os.path.join(self.directory, subdir)
self.create_route(f'/{subdir}', subdir_path)
# Discover and create routes for subdirectories (if any exist)
try:
subdirs = next(os.walk(self.directory))[1] # Extract subdirectories from the directory
except StopIteration:
subdirs = []
# If no subdirectories are found, log a message (useful for debugging)
if not subdirs:
print(f"No subdirectories found in {self.directory}")
else:
for subdir in subdirs:
subdir_path = os.path.join(self.directory, subdir)
self.create_route(f'/{subdir}', subdir_path)
def create_route(self, route_suffix, directory): def create_route(self, route_suffix, directory):
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment