Skip to content

Commit

Permalink
made naming a bit clearer in Ros Class
Browse files Browse the repository at this point in the history
  • Loading branch information
debauer committed May 27, 2024
1 parent 33db626 commit 02f1e67
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/robenv/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ def _download_deb_file(url: str) -> Path:
filename = Path(url).name
_logger.info("Download %s from %s", filename, url)
download = requests.get(url, allow_redirects=True, timeout=60, stream=True)
total = int(download.headers.get('content-length', 0))
total = int(download.headers.get("content-length", 0))
path = Path(f"dist/{filename}")
path.parent.mkdir(exist_ok=True)
size = 0
kb = 1024
with path.open('wb') as file:
with path.open("wb") as file:
for data in download.iter_content(chunk_size=kb):
size: int = size + file.write(data)
size = size + file.write(data)
if not size % (kb * 1024) or size == total:
_logger.info("Download progress: %imb of %imb", ceil(size/kb/kb), ceil(total/kb/kb))
_logger.info("Download progress: %imb of %imb", ceil(size / kb / kb), ceil(total / kb / kb))
_logger.debug("saved %s at %s", filename, str(path))
return path

Expand Down
2 changes: 1 addition & 1 deletion src/robenv/ros/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
#
32 changes: 15 additions & 17 deletions src/robenv/ros/ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

import requests

from robenv.environment.distro import RosDistribution
from robenv.environment.distro import parse_distro
from robenv.environment.run_command import run_command

Expand All @@ -49,24 +48,23 @@


class ROS:
path: Path
distro: RosDistribution
_distro_path: Path
_archive_path: Path

def __init__(self, path: str) -> None:
def __init__(self, path_or_url: str) -> None:
cache_path = Path.home() / ".cache/robenv"
xdg_home = os.environ.get("XDG_CACHE_HOME")

self._archive_path = Path()
self._distro_path = Path()

if xdg_home is not None:
cache_path = Path(xdg_home) / "robenv"

if path.startswith("http") or path.endswith("tar.gz"):
if "ros2" not in path:
if path_or_url.startswith("http") or path_or_url.endswith("tar.gz"):
if "ros2" not in path_or_url:
msg = "possible no ros2 archive, get a possible link/file from https://github.com/ros2/ros2/releases"
raise ValueError(
msg,
)
file_name = path.split("/")[-1]
file_name = path_or_url.split("/")[-1]
# file_name is somthing like: ros2-humble-20231122-linux-jammy-amd64.tar.bz2
file_name_split = file_name.split("-")
distro_name = file_name_split[1]
Expand All @@ -75,20 +73,20 @@ def __init__(self, path: str) -> None:
self._archive_path = cache_path / file_name
self._distro_path = cache_path / file_name.split(".")[0]
cache_path.mkdir(parents=True, exist_ok=True)
if "http" in path:
self._download(path)
if "http" in path_or_url:
self._download(path_or_url)
else:
self._copy_to_cache(Path(path))
self._copy_to_cache(Path(path_or_url))
self._install()
self.path = self._find_path()
else:
_logger.info(" %s ", path)
self.distro = parse_distro(path.split("/")[3])
self.path = Path(path)
_logger.info(" %s ", path_or_url)
self.distro = parse_distro(path_or_url.split("/")[3])
self.path = Path(path_or_url)

def _find_path(self) -> Path:
search = self._distro_path.glob("**/setup.sh")
return next(iter(search)).parent
return next(search).parent

def _copy_to_cache(self, file_path: Path) -> None:
if file_path.exists() and not self._archive_path.exists():
Expand Down

0 comments on commit 02f1e67

Please sign in to comment.