Skip to content
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

tool: add unzip #1780

Merged
merged 1 commit into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lisa/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
from .taskset import TaskSet
from .tcpdump import TcpDump
from .timedatectl import Timedatectl
from .unzip import Unzip
from .uptime import Uptime
from .who import Who
from .whoami import Whoami
Expand Down Expand Up @@ -149,6 +150,7 @@
"TaskSet",
"TcpDump",
"Timedatectl",
"Unzip",
"Uptime",
"Wget",
"Who",
Expand Down
40 changes: 40 additions & 0 deletions lisa/tools/unzip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.


from lisa.executable import Tool
from lisa.operating_system import Posix
from lisa.util import LisaException


class Unzip(Tool):
@property
def command(self) -> str:
return "unzip"

@property
def can_install(self) -> bool:
return True

def _install(self) -> bool:
assert isinstance(
self.node.os, Posix
), f"unzip: unsupported OS {self.node.os.name}"
self.node.os.install_packages(self.command)
return self._check_exists()

def extract(
self,
file: str,
dest_dir: str,
sudo: bool = False,
) -> None:
# create folder when it doesn't exist
self.node.execute(f"mkdir -p {dest_dir}", shell=True)
result = self.run(
f"{file} -d {dest_dir}", shell=True, force_run=True, sudo=sudo
)
if result.exit_code != 0:
raise LisaException(
f"Failed to extract file to {dest_dir}, {result.stderr}"
)