You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.3 KiB

# Copyright (c) 2020 Red Hat, Inc.
# All Rights Reserved.
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import absolute_import
import math
import typing # noqa
import tobiko
from import sh
from import ssh
class FilesNotFound(tobiko.TobikoException):
message = ("Files not found (path={path}, name={name}, login={login}, "
NameType = typing.Union[None, str, typing.List[str]]
PathType = typing.Union[str, typing.Iterable[str]]
def find_files(path: sh.ShellCommandType,
name: NameType = None,
command: sh.ShellCommandType = 'find',
ssh_client: ssh.SSHClientFixture = None,
modified_since: tobiko.Seconds = None,
**execute_params) -> typing.List[str]:
if not path:
raise ValueError("Path can't be empty")
command_line = sh.shell_command(command) + path
if name is not None:
command_line += f"-name '{name}'"
if modified_since is not None:
# round seconds to the next minute
minutes = math.ceil(modified_since / 60.)
command_line += f"-mmin {minutes}"
result = sh.execute(command_line,
if result.exit_status == 0:
output_lines: typing.List[str] = [
for line in result.stdout.splitlines()
if line.strip()]
if output_lines:
return output_lines
raise FilesNotFound(path=path,
login=ssh_client and ssh_client.login or None,