Skip to content

Commit

Permalink
fs: add sed support
Browse files Browse the repository at this point in the history
Add sed functionality to new test framework
  • Loading branch information
aborah-sudo authored and pbrezina committed Jun 28, 2024
1 parent 25935f8 commit e1f5016
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pytest_mh/utils/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,3 +738,22 @@ def chown(
mode = f"{user}" if user else ""
mode += f":{group}" if group else ""
return self.host.ssh.exec(["chown", mode, *path.split(), *args], log_level=SSHLog.Error)

def sed(self, command: str, path: str, args: list[str] | None = None) -> SSHProcessResult:
"""
SED command in UNIX stands for stream editor and it can perform lots of
functions on file like searching, find and replace, insertion or deletion.
:param command: Sed command
:type command: str
:param path: File where changes will happen
:type path: str
:param args: Additional options, defaults to None
:type args: list[str] | None, optional
:return: Result of process
:rtype: SSHProcessResult
"""
self.backup(path)
self.logger.info(f"Running sed {command} on {path}")
args = args if args else []
return self.host.ssh.exec(["sed", *args, command, path], log_level=SSHLog.Error)

0 comments on commit e1f5016

Please sign in to comment.