Skip to content

Commit

Permalink
B4 Tool: Update pattern search
Browse files Browse the repository at this point in the history
  • Loading branch information
adityagesh committed Nov 12, 2024
1 parent ea73202 commit 5029207
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lisa/tools/b4.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
from lisa.executable import Tool
from lisa.operating_system import Debian
from lisa.tools.python import Pip
from lisa.util import get_matched_str
from lisa.util import LisaException, find_group_in_lines


class B4(Tool):
_output_file_pattern = re.compile(r"[\w-]+\.mbx")
# Output log is of the form
# git am /mnt/code/linux/v2_20241029_xx_drivers_xx_xx_wait_for_offers_xx_xx_xxx_offers.mbx
_output_file_pattern = re.compile(
r"^.*git.*/(?P<filename>[\w-]+\.mbx).*$", re.MULTILINE
)

@property
def command(self) -> str:
Expand All @@ -26,9 +30,18 @@ def _install(self) -> bool:
pip.install_packages("b4", install_to_user=True)
return self._check_exists()

def am(self, message_id: str, output_dir: pathlib.PurePath) -> pathlib.PurePath:
def am(
self, message_id: str, output_dir: pathlib.PurePath, sudo: bool = False
) -> pathlib.PurePath:
result = self.run(
f"am -o '{output_dir}' '{message_id}'", force_run=True, expected_exit_code=0
f"am -o '{output_dir}' '{message_id}'",
force_run=True,
expected_exit_code=0,
sudo=sudo,
)
path_str = get_matched_str(result.stdout, self._output_file_pattern)
return pathlib.PurePath(output_dir, path_str)
filename = find_group_in_lines(
lines=result.stdout, pattern=self._output_file_pattern, single_line=False
).get("filename")
if not filename:
raise LisaException("Failed to get filename from b4 am output")
return pathlib.PurePath(output_dir, filename)

0 comments on commit 5029207

Please sign in to comment.