-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add resolve_filepath for url scheme such that package://, model:// #2
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,12 @@ | ||||||||||
"""Utilities for URDF parsing. | ||||||||||
""" | ||||||||||
import os | ||||||||||
try: | ||||||||||
# for python3 | ||||||||||
from urllib.parse import urlparse | ||||||||||
except ImportError: | ||||||||||
# for python2 | ||||||||||
from urlparse import urlparse | ||||||||||
|
||||||||||
from lxml import etree as ET | ||||||||||
import numpy as np | ||||||||||
|
@@ -180,6 +186,19 @@ def unparse_origin(matrix): | |||||||||
return node | ||||||||||
|
||||||||||
|
||||||||||
def resolve_filepath(base_path, file_path): | ||||||||||
parsed_url = urlparse(file_path) | ||||||||||
dirname = base_path | ||||||||||
file_path = parsed_url.netloc + parsed_url.path | ||||||||||
while not dirname == '/': | ||||||||||
resolved_filepath = os.path.join(dirname, file_path) | ||||||||||
print(resolved_filepath) | ||||||||||
if os.path.exists(resolved_filepath): | ||||||||||
return resolved_filepath | ||||||||||
dirname = os.path.dirname(dirname) | ||||||||||
return False | ||||||||||
|
||||||||||
|
||||||||||
def get_filename(base_path, file_path, makedirs=False): | ||||||||||
"""Formats a file path correctly for URDF loading. | ||||||||||
|
||||||||||
|
@@ -199,6 +218,7 @@ def get_filename(base_path, file_path, makedirs=False): | |||||||||
The resolved filepath -- just the normal ``file_path`` if it was an | ||||||||||
absolute path, otherwise that path joined to ``base_path``. | ||||||||||
""" | ||||||||||
file_path = resolve_filepath(base_path, file_path) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with comment above, I think you need a check to see if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
fn = file_path | ||||||||||
if not os.path.isabs(file_path): | ||||||||||
fn = os.path.join(base_path, file_path) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when given a relative path, this gives the wrong path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the tests, this will return false, then in
get_filename
,os.path.isabs
fails because it's trying to evaluateFalse