How to use the lbuild.exception.LbuildException function in lbuild

To help you get started, we’ve selected a few lbuild examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github modm-io / lbuild / lbuild / exception.py View on Github external
.format(_hl(value), _hl(reason)))
        super().__init__(msg, option)

class LbuildOptionRequiredInputException(LbuildOptionException):
    def __init__(self, option):
        msg = " requires an input value!\n"
        super().__init__(msg, option)

class LbuildOptionRequiredInputsException(LbuildAggregateException):
    def __init__(self, options):
        exceptions = {LbuildOptionRequiredInputException(o) for o in options}
        super().__init__(exceptions, _dump(next(iter(options))))


# ============================== QUERY EXCEPTIONS =============================
class LbuildQueryException(LbuildException):
    def __init__(self, message, query):
        msg = "{}({}){}\n".format(query.class_name, _hl(_rel(query.name)), message)
        super().__init__(msg, query)

class LbuildQueryConstructionException(LbuildQueryException):
    def __init__(self, query, reason):
        msg = ": invalid construction!\n{}\n{}\n".format(_call_site(), _hl(reason))
        super().__init__(msg, query)


# ============================= PARSER EXCEPTIONS =============================
class LbuildParserDuplicateRepoException(LbuildDumpConfigException):
    def __init__(self, parser, repo, conflict):
        msg = ("Repository({}) conflicts with existing Repository!\n{}\n"
               "Hint: This Repository from '{}':\n\n"
               "    >>> {}\n\n"
github modm-io / lbuild / lbuild / exception.py View on Github external
pass

class LbuildAggregateException(LbuildException):
    """Collection of multiple exceptions."""
    def __init__(self, exceptions, suffix=None):
        msg = "\nERROR: ".join(str(exc) for exc in exceptions)
        if suffix is not None:
            msg += suffix
        super().__init__(msg)
        self.exceptions = exceptions

class LbuildDumpConfigException(LbuildException):
    def __init__(self, message, node=None):
        super().__init__(message.strip() + _dump(node), node)

class LbuildForwardException(LbuildException):
    def __init__(self, location, error):
        import traceback
        error_fmt = "".join(traceback.format_exception(type(error), error,
                                                       error.__traceback__, limit=-1))
        error_fmt = error_fmt.replace("lbuild.exception.Lbuild", "")
        msg = ("In '{}':\n\n{}"
               .format(_hl(location), _hl(error_fmt)))
        super().__init__(msg)
        self.module = location
        self.exception = error


# ========================== CONFIGURATION EXCEPTIONS =========================
class LbuildConfigException(LbuildException):
    def __init__(self, filename, message):
        message = "Configuration({}){}".format(_hl(_rel(filename)), message)
github modm-io / lbuild / lbuild / exception.py View on Github external
class LbuildValidateException(Exception):
    pass

class LbuildArgumentException(LbuildException):
    pass

class LbuildAggregateException(LbuildException):
    """Collection of multiple exceptions."""
    def __init__(self, exceptions, suffix=None):
        msg = "\nERROR: ".join(str(exc) for exc in exceptions)
        if suffix is not None:
            msg += suffix
        super().__init__(msg)
        self.exceptions = exceptions

class LbuildDumpConfigException(LbuildException):
    def __init__(self, message, node=None):
        super().__init__(message.strip() + _dump(node), node)

class LbuildForwardException(LbuildException):
    def __init__(self, location, error):
        import traceback
        error_fmt = "".join(traceback.format_exception(type(error), error,
                                                       error.__traceback__, limit=-1))
        error_fmt = error_fmt.replace("lbuild.exception.Lbuild", "")
        msg = ("In '{}':\n\n{}"
               .format(_hl(location), _hl(error_fmt)))
        super().__init__(msg)
        self.module = location
        self.exception = error
github modm-io / lbuild / lbuild / exception.py View on Github external
"class" if is_class else "function", _hl(name, plain),
            code_context[0])
    return msg


# ============================== BASE EXCEPTIONS ==============================
class LbuildException(Exception):
    """Base class for exception thrown by lbuild."""
    def __init__(self, message, node=None):
        super().__init__(message)
        self.node = node

class LbuildValidateException(Exception):
    pass

class LbuildArgumentException(LbuildException):
    pass

class LbuildAggregateException(LbuildException):
    """Collection of multiple exceptions."""
    def __init__(self, exceptions, suffix=None):
        msg = "\nERROR: ".join(str(exc) for exc in exceptions)
        if suffix is not None:
            msg += suffix
        super().__init__(msg)
        self.exceptions = exceptions

class LbuildDumpConfigException(LbuildException):
    def __init__(self, message, node=None):
        super().__init__(message.strip() + _dump(node), node)

class LbuildForwardException(LbuildException):
github modm-io / lbuild / lbuild / node.py View on Github external
def _update_attribute(self, attr):
        self_attr = getattr(self, attr, "unknown")
        parent_attr = getattr(self.parent, attr, "unknown")
        if self_attr == "unknown" or parent_attr == "unknown":
            raise le.LbuildException("Internal: Cannot update non-existant "
                                     "attribute '{}'!".format(attr))

        if isinstance(self_attr, list):
            self_attr = list(set(self_attr + parent_attr))
            return
        if isinstance(self_attr, dict):
            self_attr.update(parent_attr)
            return

        default = getattr(self, attr + "_default")
        if (parent_attr != default) and (self_attr == default):
            setattr(self, attr, parent_attr)
github modm-io / lbuild / lbuild / utils.py View on Github external
def with_forward_exception(module, function):
    """
    Run a function a store exceptions as forward exceptions.
    """
    try:
        return function()
    except le.LbuildException:
        raise
    except Exception as error:
        raise le.LbuildForwardException(module, error)
github modm-io / lbuild / lbuild / exception.py View on Github external
# ============================== BASE EXCEPTIONS ==============================
class LbuildException(Exception):
    """Base class for exception thrown by lbuild."""
    def __init__(self, message, node=None):
        super().__init__(message)
        self.node = node

class LbuildValidateException(Exception):
    pass

class LbuildArgumentException(LbuildException):
    pass

class LbuildAggregateException(LbuildException):
    """Collection of multiple exceptions."""
    def __init__(self, exceptions, suffix=None):
        msg = "\nERROR: ".join(str(exc) for exc in exceptions)
        if suffix is not None:
            msg += suffix
        super().__init__(msg)
        self.exceptions = exceptions

class LbuildDumpConfigException(LbuildException):
    def __init__(self, message, node=None):
        super().__init__(message.strip() + _dump(node), node)

class LbuildForwardException(LbuildException):
    def __init__(self, location, error):
        import traceback
        error_fmt = "".join(traceback.format_exception(type(error), error,
github modm-io / lbuild / lbuild / vcs / common.py View on Github external
def _parse_vcs(config: lbuild.config.ConfigNode,
               action):
    LOGGER.debug("Initialize VCS repositories")

    config = config.flatten()
    for vcs in config.vcs:
        for tag, repoconfig in vcs.items():
            if tag == "git":
                LOGGER.debug("Found Git repository")

                from . import git
                repo = git.Repository(config.cachefolder, repoconfig)
            else:
                raise LbuildException("Unsupported VCS type '{}'".format(tag))

            if action == Action.init:
                repo.initialize()
            elif action == Action.update:
                repo.update()