Ejemplo n.º 1
0
def cat_target(target):
    """
    Prints the contents of the target file into the file-like object out.
    The caller should ensure that the target is a file.
    """
    rest_util.check_target_has_read_permission(target)
    with closing(local.download_manager.stream_file(target[0], target[1], gzipped=False)) as fileobj:
        return fileobj.read()
Ejemplo n.º 2
0
def cat_target(target):
    """
    Prints the contents of the target file into the file-like object out.
    The caller should ensure that the target is a file.
    """
    rest_util.check_target_has_read_permission(target)
    with closing(
        local.download_manager.stream_file(target[0], target[1], gzipped=False)
    ) as fileobj:
        return fileobj.read()
Ejemplo n.º 3
0
def head_target(target, max_num_lines):
    """
    Return the first max_num_lines of target as a list of strings.

    The caller should ensure that the target is a file.

    :param target: A worker.download_util.BundleTarget with bundle_uuid and subpath
    :param max_num_lines: max number of lines to fetch
    """
    rest_util.check_target_has_read_permission(target)
    # Note: summarize_file returns bytes, but should be decodable to a string.
    lines = (local.download_manager.summarize_file(
        target, max_num_lines, 0, MAX_BYTES_PER_LINE, None,
        gzipped=False).decode().splitlines(True))

    return lines
Ejemplo n.º 4
0
def head_target(target, max_num_lines, replace_non_unicode=False):
    """
    Return the first max_num_lines of target as a list of strings.

    The caller should ensure that the target is a file.

    :param target: (bundle_uuid, subpath)
    :param max_num_lines: max number of lines to fetch
    :param replace_non_unicode: replace non-unicode characters with something printable
    """
    rest_util.check_target_has_read_permission(target)
    lines = local.download_manager.summarize_file(
        target[0], target[1], max_num_lines, 0, MAX_BYTES_PER_LINE, None, gzipped=False
    ).splitlines(True)

    if replace_non_unicode:
        lines = map(formatting.verbose_contents_str, lines)

    return lines
Ejemplo n.º 5
0
def head_target(target, max_num_lines, replace_non_unicode=False):
    """
    Return the first max_num_lines of target as a list of strings.

    The caller should ensure that the target is a file.

    :param target: (bundle_uuid, subpath)
    :param max_num_lines: max number of lines to fetch
    :param replace_non_unicode: replace non-unicode characters with something printable
    """
    rest_util.check_target_has_read_permission(target)
    lines = local.download_manager.summarize_file(
        target[0], target[1], max_num_lines, 0, MAX_BYTES_PER_LINE, None, gzipped=False
    ).splitlines(True)

    if replace_non_unicode:
        lines = map(formatting.verbose_contents_str, lines)

    return lines