# Path: stestr/output.py
# def output_table(table, output=sys.stdout):
#     def show_row(row):
# def output_tests(tests, output=sys.stdout):
# def make_result(get_id, output=sys.stdout):
# def output_summary(successful, tests, tests_delta, time, time_delta, values,
#                    output=sys.stdout):
# def output_stream(stream, output=sys.stdout):
#     def __init__(self, process):
#     def _append_return_code_as_test(self):
#     def read(self, count=-1):
#     def readline(self):
#     def readlines(self):
# class ReturnCodeToSubunit:
# 
# Path: stestr/repository/abstract.py
# class AbstractRepositoryFactory:
# class AbstractRepository:
# class AbstractTestRun:
# class RepositoryNotFound(Exception):
#     def initialise(self, url):
#     def open(self, url):
#     def count(self):
#     def get_failing(self):
#     def get_run_ids(self):
#     def remove_run_id(self, run_id):
#     def get_inserter(self, partial=False, run_id=None, metadata=None):
#     def _get_inserter(self, partial=False, run_id=None, metadata=None):
#     def get_latest_run(self):
#     def get_test_run(self, run_id):
#     def get_test_times(self, test_ids):
#     def _get_test_times(self, test_ids):
#     def latest_id(self):
#     def get_test_ids(self, run_id):
#         def gather(test_dict):
#     def find_metadata(self, metadata):
#     def get_id(self):
#     def get_subunit_stream(self):
#     def get_test(self):
#     def get_metadata(self):
#     def __init__(self, url):
# 
# Path: stestr/repository/util.py
# def _get_default_repo_url(repo_type):
# def get_repo_open(repo_type, repo_url=None):
# def get_repo_initialise(repo_type, repo_url=None):
# 
# Path: stestr/results.py
# def wasSuccessful(summary):
#     def __init__(self):
#     def startTestRun(self):
#     def status(self, *args, **kwargs):
#     def get_num_failures(self):
#     def get_time_taken(self):
#     def __init__(self, byte_stream):
#     def status(self, test_id=None, test_status=None, test_tags=None,
#                runnable=True, file_name=None, file_bytes=None, eof=False,
#                mime_type=None, route_code=None, timestamp=None):
#     def __init__(self, get_id, stream, previous_run=None):
#     def _format_error(self, label, test, error_text, test_tags=None):
#     def status(self, **kwargs):
#     def _get_previous_summary(self):
#     def _output_summary(self, run_id):
#     def startTestRun(self):
#     def stopTestRun(self):
#     def get_summary(self):
# class SummarizingResult(testtools.StreamSummary):
# class CatFiles(testtools.StreamResult):
# class CLITestResult(testtools.StreamResult):
# 
# Path: stestr/subunit_trace.py
# DAY_SECONDS = 60 * 60 * 24
# FAILS = []
# RESULTS = {}
# def total_seconds(timedelta):
# def cleanup_test_name(name, strip_tags=True, strip_scenarios=False):
# def get_duration(timestamps):
# def find_worker(test):
# def print_attachments(stream, test, all_channels=False,
#                       show_binary_attachments=False):
# def find_test_run_time_diff(test_id, run_time):
# def show_outcome(stream, test, print_failures=False, failonly=False,
#                  enable_diff=False, threshold='0', abbreviate=False,
#                  enable_color=False, suppress_attachments=False,
#                  all_attachments=False, show_binary_attachments=True):
# def print_fails(stream):
# def count_tests(key, value):
# def get_stuck_in_progress():
# def run_time():
# def worker_stats(worker):
# def print_summary(stream, elapsed_time):
# def parse_args():
# def trace(stdin, stdout, print_failures=False, failonly=False,
#           enable_diff=False, abbreviate=False, color=False, post_fails=False,
#           no_summary=False, suppress_attachments=False, all_attachments=False,
#           show_binary_attachments=False):
# def main():
# 
# Path: stestr/user_config.py
# def get_user_config(path=None):
#     def __init__(self, path):
#     def run(self):
#     def failing(self):
#     def last(self):
#     def load(self):
#     def history_list(self):
#     def history_show(self):
# class UserConfig:


import sys
from cliff import command
from stestr import output
from stestr.repository import abstract
from stestr.repository import util
from stestr import results
from stestr import subunit_trace
from stestr import user_config
    :param pretty_out: Use the subunit-trace output filter.
    :param color: Enable colorized output with the subunit-trace output filter.
    :param bool subunit: Show output as a subunit stream.
    :param file stdout: The output file to write all output to. By default
         this is sys.stdout
    :param bool suppress_attachments: When set true attachments subunit_trace
        will not print attachments on successful test execution.
    :param bool all_attachments: When set true subunit_trace will print all
        text attachments on successful test execution.
    :param bool show_binary_attachments: When set to true, subunit_trace will
        print binary attachments in addition to text attachments.

    :return return_code: The exit code for the command. 0 for success and > 0
        for failures.
    :rtype: int
    """
    try:
        repo = util.get_repo_open(repo_type, repo_url)
    except abstract.RepositoryNotFound as e:
        stdout.write(str(e) + '\n')
        return 1

    try:
        latest_run = repo.get_latest_run()
    except KeyError as e:
        stdout.write(str(e) + '\n')
        return 1

    if subunit_out:
        stream = latest_run.get_subunit_stream()

# Path: stestr/output.py
# def output_table(table, output=sys.stdout):
#     def show_row(row):
# def output_tests(tests, output=sys.stdout):
# def make_result(get_id, output=sys.stdout):
# def output_summary(successful, tests, tests_delta, time, time_delta, values,
#                    output=sys.stdout):
# def output_stream(stream, output=sys.stdout):
#     def __init__(self, process):
#     def _append_return_code_as_test(self):
#     def read(self, count=-1):
#     def readline(self):
#     def readlines(self):
# class ReturnCodeToSubunit:
# 
# Path: stestr/repository/abstract.py
# class AbstractRepositoryFactory:
# class AbstractRepository:
# class AbstractTestRun:
# class RepositoryNotFound(Exception):
#     def initialise(self, url):
#     def open(self, url):
#     def count(self):
#     def get_failing(self):
#     def get_run_ids(self):
#     def remove_run_id(self, run_id):
#     def get_inserter(self, partial=False, run_id=None, metadata=None):
#     def _get_inserter(self, partial=False, run_id=None, metadata=None):
#     def get_latest_run(self):
#     def get_test_run(self, run_id):
#     def get_test_times(self, test_ids):
#     def _get_test_times(self, test_ids):
#     def latest_id(self):
#     def get_test_ids(self, run_id):
#         def gather(test_dict):
#     def find_metadata(self, metadata):
#     def get_id(self):
#     def get_subunit_stream(self):
#     def get_test(self):
#     def get_metadata(self):
#     def __init__(self, url):
# 
# Path: stestr/repository/util.py
# def _get_default_repo_url(repo_type):
# def get_repo_open(repo_type, repo_url=None):
# def get_repo_initialise(repo_type, repo_url=None):
# 
# Path: stestr/results.py
# def wasSuccessful(summary):
#     def __init__(self):
#     def startTestRun(self):
#     def status(self, *args, **kwargs):
#     def get_num_failures(self):
#     def get_time_taken(self):
#     def __init__(self, byte_stream):
#     def status(self, test_id=None, test_status=None, test_tags=None,
#                runnable=True, file_name=None, file_bytes=None, eof=False,
#                mime_type=None, route_code=None, timestamp=None):
#     def __init__(self, get_id, stream, previous_run=None):
#     def _format_error(self, label, test, error_text, test_tags=None):
#     def status(self, **kwargs):
#     def _get_previous_summary(self):
#     def _output_summary(self, run_id):
#     def startTestRun(self):
#     def stopTestRun(self):
#     def get_summary(self):
# class SummarizingResult(testtools.StreamSummary):
# class CatFiles(testtools.StreamResult):
# class CLITestResult(testtools.StreamResult):
# 
# Path: stestr/subunit_trace.py
# DAY_SECONDS = 60 * 60 * 24
# FAILS = []
# RESULTS = {}
# def total_seconds(timedelta):
# def cleanup_test_name(name, strip_tags=True, strip_scenarios=False):
# def get_duration(timestamps):
# def find_worker(test):
# def print_attachments(stream, test, all_channels=False,
#                       show_binary_attachments=False):
# def find_test_run_time_diff(test_id, run_time):
# def show_outcome(stream, test, print_failures=False, failonly=False,
#                  enable_diff=False, threshold='0', abbreviate=False,
#                  enable_color=False, suppress_attachments=False,
#                  all_attachments=False, show_binary_attachments=True):
# def print_fails(stream):
# def count_tests(key, value):
# def get_stuck_in_progress():
# def run_time():
# def worker_stats(worker):
# def print_summary(stream, elapsed_time):
# def parse_args():
# def trace(stdin, stdout, print_failures=False, failonly=False,
#           enable_diff=False, abbreviate=False, color=False, post_fails=False,
#           no_summary=False, suppress_attachments=False, all_attachments=False,
#           show_binary_attachments=False):
# def main():
# 
# Path: stestr/user_config.py
# def get_user_config(path=None):
#     def __init__(self, path):
#     def run(self):
#     def failing(self):
#     def last(self):
#     def load(self):
#     def history_list(self):
#     def history_show(self):
# class UserConfig:


# Path: stestr/commands/last.py
import sys
from cliff import command
from stestr import output
from stestr.repository import abstract
from stestr.repository import util
from stestr import results
from stestr import subunit_trace
from stestr import user_config

    :param pretty_out: Use the subunit-trace output filter.
    :param color: Enable colorized output with the subunit-trace output filter.
    :param bool subunit: Show output as a subunit stream.
    :param file stdout: The output file to write all output to. By default
         this is sys.stdout
    :param bool suppress_attachments: When set true attachments subunit_trace
        will not print attachments on successful test execution.
    :param bool all_attachments: When set true subunit_trace will print all
        text attachments on successful test execution.
    :param bool show_binary_attachments: When set to true, subunit_trace will
        print binary attachments in addition to text attachments.

    :return return_code: The exit code for the command. 0 for success and > 0
        for failures.
    :rtype: int
    """
    try:
        repo = util.get_repo_open(repo_type, repo_url)
    except abstract.RepositoryNotFound as e:
        stdout.write(str(e) + '\n')
        return 1

    try:
        latest_run = repo.get_latest_run()
    except KeyError as e:
        stdout.write(str(e) + '\n')
        return 1

    if subunit_out:
        stream = latest_run.get_subunit_stream()

        output.output_stream(stream, output=stdout)