# Path: kotori/util/errors.py
# def last_error_and_traceback():
#     error_entry = traceback_get_exception(0)
#     error_last = traceback_get_exception(-1)
#     sep = '-' * 60
#     payload_location = "\n".join([sep, format_exception_location(error_entry, "Entry point:"), sep, format_exception_location(error_last, "Source of exception:")])
#     payload = ''.join(["ERROR: ", error_entry['message'], "\n", payload_location, "\n"])
# 
#     # add full traceback
#     buffer = StringIO()
#     traceback.print_exc(file=buffer)
#     buffer.seek(0)
#     payload += '\n' + buffer.read()
# 
#     return payload


import os
import re
import sys
import logging
import uuid
import arrow
from io import StringIO
from bunch import Bunch
from appdirs import user_cache_dir
from tempfile import NamedTemporaryFile
from contextlib import contextmanager
from pprint import pformat
from cornice.util import to_list
from git import Repo
from git import RemoteProgress
from plumbum import local
from plumbum.cmd import pwd, make, grep, ls
from kotori.util.errors import last_error_and_traceback
        return artefact

    @contextmanager
    def capture(self):
        """
        Capture output of the whole build process.
        Return stacktrace of Python driver and output of make command, if any.
        """

        # The result object containing build success flag and error outputs.
        # This gets bound to the context manager variable.
        result = Bunch()
        self.build_result['capture'] = result

        # A temporary file to redirect make output to
        self.stream = NamedTemporaryFile()
        try:
            # Pass execution flow to context manager body,
            # effectively running the main build process
            yield result

            # Signal success if build engine completed
            result.success = True

        except Exception as ex:

            # Signal failure
            result.success = False

            # Capture Python traceback

# Path: kotori/util/errors.py
# def last_error_and_traceback():
#     error_entry = traceback_get_exception(0)
#     error_last = traceback_get_exception(-1)
#     sep = '-' * 60
#     payload_location = "\n".join([sep, format_exception_location(error_entry, "Entry point:"), sep, format_exception_location(error_last, "Source of exception:")])
#     payload = ''.join(["ERROR: ", error_entry['message'], "\n", payload_location, "\n"])
# 
#     # add full traceback
#     buffer = StringIO()
#     traceback.print_exc(file=buffer)
#     buffer.seek(0)
#     payload += '\n' + buffer.read()
# 
#     return payload


# Path: kotori/firmware/builder.py
import os
import re
import sys
import logging
import uuid
import arrow
from io import StringIO
from bunch import Bunch
from appdirs import user_cache_dir
from tempfile import NamedTemporaryFile
from contextlib import contextmanager
from pprint import pformat
from cornice.util import to_list
from git import Repo
from git import RemoteProgress
from plumbum import local
from plumbum.cmd import pwd, make, grep, ls
from kotori.util.errors import last_error_and_traceback

        return artefact

    @contextmanager
    def capture(self):
        """
        Capture output of the whole build process.
        Return stacktrace of Python driver and output of make command, if any.
        """

        # The result object containing build success flag and error outputs.
        # This gets bound to the context manager variable.
        result = Bunch()
        self.build_result['capture'] = result

        # A temporary file to redirect make output to
        self.stream = NamedTemporaryFile()
        try:
            # Pass execution flow to context manager body,
            # effectively running the main build process
            yield result

            # Signal success if build engine completed
            result.success = True

        except Exception as ex:

            # Signal failure
            result.success = False

            # Capture Python traceback

            result.error = last_error_and_traceback()