Skip to content

Commit

Permalink
Move file:/ logic
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoferigo committed Feb 29, 2024
1 parent 5029c1c commit 21da473
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/resolve_robotics_uri_py/resolve_robotics_uri_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,30 @@ def resolve_robotics_uri(uri: str) -> pathlib.Path:
if not any(uri.startswith(scheme) for scheme in SupportedSchemes):
uri = f"file://{pathlib.Path(uri).resolve()}"


# ================================================
# Process file:/ separately from the other schemes
# ================================================

if uri.startswith("file:"):
# Strip the scheme from the URI
uri = uri.replace(f"file://", "")
uri = uri.replace(f"file:", "")

# Create the file path, resolving symlinks and '..'
uri_file_path = pathlib.Path(uri).resolve()

# Check that the file exists
if not uri_file_path.is_file():
msg = "resolve-robotics-uri-py: No file corresponding to URI '{}' found"
raise FileNotFoundError(msg.format(uri))

return uri_file_path.resolve()

# =========================
# Process the other schemes
# =========================

# Get scheme from URI
from urllib.parse import urlparse

Expand All @@ -115,23 +139,13 @@ def resolve_robotics_uri(uri: str) -> pathlib.Path:
raise FileNotFoundError(msg.format(uri, parsed_uri.scheme))

# Strip the scheme from the URI
uri_path = uri.replace(f"{parsed_uri.scheme}//", "")

# Process file:/ separately from the other schemes
if parsed_uri.scheme == "file":
# Create the file path, resolving symlinks and '..'
uri_file_path = pathlib.Path(uri_path).resolve()

# Check that the file exists
if not uri_file_path.is_file():
msg = "resolve-robotics-uri-py: No file corresponding to URI '{}' found"
raise FileNotFoundError(msg.format(uri))

return uri_file_path.resolve()
uri_path = uri
uri_path = uri_path.replace(f"{parsed_uri.scheme}://", "")

# List of matching resources found
model_filenames = []

# Search the resource in the path from the env variables
for folder in set(get_search_paths_from_envs(SupportedEnvVars)):

# Join the folder from environment variable and the URI path
Expand Down

0 comments on commit 21da473

Please sign in to comment.