Пример #1
0
    def invoke(self, broker):
        dep_value = broker[self.requires[0]]
        exception = False

        if not isinstance(dep_value, list):
            try:
                return self.component(dep_value)
            except ContentException as ce:
                log.debug(ce)
                broker.add_exception(self.component, ce,
                                     traceback.format_exc())
                exception = True
            except CalledProcessError as cpe:
                log.debug(cpe)
                broker.add_exception(self.component, cpe,
                                     traceback.format_exc())
                exception = True

        if exception:
            raise dr.SkipComponent()

        results = []
        for d in dep_value:
            try:
                r = self.component(d)
                if r is not None:
                    results.append(r)
            except dr.SkipComponent:
                pass
            except ContentException as ce:
                log.debug(ce)
                broker.add_exception(self.component, ce,
                                     traceback.format_exc())
                if not self.continue_on_error:
                    exception = True
                    break
            except CalledProcessError as cpe:
                log.debug(cpe)
                broker.add_exception(self.component, cpe,
                                     traceback.format_exc())
                if not self.continue_on_error:
                    exception = True
                    break
            except Exception as ex:
                tb = traceback.format_exc()
                log.warn(tb)
                broker.add_exception(self.component, ex, tb)
                if not self.continue_on_error:
                    exception = True
                    break

        if exception:
            raise dr.SkipComponent()

        if not results:
            log.debug("All failed: %s" % dr.get_name(self.component))
            raise dr.SkipComponent()

        return results
Пример #2
0
 def invoke(self, broker):
     try:
         return self.component(broker)
     except ContentException as ce:
         log.debug(ce)
         broker.add_exception(self.component, ce, traceback.format_exc())
         raise dr.SkipComponent()
     except CalledProcessError as cpe:
         log.debug(cpe)
         broker.add_exception(self.component, cpe, traceback.format_exc())
         raise dr.SkipComponent()
Пример #3
0
 def process(self, broker):
     """
     Ensures dependencies have been met before delegating to `self.invoke`.
     """
     if any(i in broker for i in dr.IGNORE.get(self.component, [])):
         raise dr.SkipComponent()
     missing = self.get_missing_dependencies(broker)
     if missing:
         return _make_skip(dr.get_name(self.component), missing)
     r = self.invoke(broker)
     if r is None:
         raise dr.SkipComponent()
     if not isinstance(r, Response):
         raise Exception("rules must return Response objects.")
     return r
Пример #4
0
    def invoke(self, broker):
        dependency = self.requires[0]
        if dependency not in broker:
            raise dr.MissingRequirements(([dependency], []))

        dep_value = broker[dependency]
        if not isinstance(dep_value, list):
            return self.component(dep_value)

        results = []
        for d in dep_value:
            try:
                r = self.component(d)
                if r is not None:
                    results.append(r)
            except dr.SkipComponent:
                pass
            except Exception as ex:
                tb = traceback.format_exc()
                log.warn(tb)
                broker.add_exception(self.component, ex, tb)

        if not results:
            log.debug("All failed: %s" % dr.get_name(self.component))
            raise dr.SkipComponent()
        return results
Пример #5
0
def parser_executor(component, broker, requires, optional):
    dependency = requires[0]
    if dependency not in broker:
        raise dr.MissingRequirements(([dependency], []))

    dep_value = broker[dependency]
    if not isinstance(dep_value, list):
        return component(dep_value)

    results = []
    for d in dep_value:
        try:
            r = component(d)
            if r is not None:
                results.append(r)
        except dr.SkipComponent:
            pass
        except Exception as ex:
            log.exception(ex)
            broker.add_exception(component, ex, traceback.format_exc())

    if not results:
        log.debug("All failed: %s" % dr.get_name(component))
        raise dr.SkipComponent()

    return results
Пример #6
0
    def validate(self):
        if not blacklist.allow_command(self.cmd):
            log.warning("WARNING: Skipping command %s", self.cmd)
            raise dr.SkipComponent()

        if not which(shlex.split(self.cmd)[0], env=self.create_env()):
            raise ContentException("Couldn't execute: %s" % self.cmd)
Пример #7
0
def datasource_executor(component, broker, requires, optional):
    try:
        return dr.broker_executor(component, broker, requires, optional)
    except ContentException as ce:
        log.debug(ce)
        broker.add_exception(component, ce, traceback.format_exc())
        raise dr.SkipComponent()
Пример #8
0
 def process(self, broker):
     """
     Ensures dependencies have been met before delegating to `self.invoke`.
     """
     if any(i in broker for i in dr.IGNORE.get(self.component, [])):
         raise dr.SkipComponent()
     missing = self.get_missing_dependencies(broker)
     if missing:
         details = dr.stringify_requirements(missing)
         return _make_skip(dr.get_name(self.component),
                           reason="MISSING_REQUIREMENTS",
                           details=details)
     r = self.invoke(broker)
     if r is None:
         raise dr.SkipComponent()
     if not isinstance(r, Response):
         raise Exception("rules must return Response objects.")
     return r
Пример #9
0
    def validate(self):
        if not blacklist.allow_file("/" + self.relative_path):
            raise dr.SkipComponent()

        if not os.path.exists(self.path):
            raise ContentException("%s does not exist." % self.path)

        if not os.access(self.path, os.R_OK):
            raise ContentException("Cannot access %s" % self.path)
Пример #10
0
 def invoke(self, broker):
     try:
         r = super(rule, self).invoke(broker)
         if r is None:
             raise dr.SkipComponent()
     except dr.MissingRequirements as mr:
         details = dr.stringify_requirements(mr.requirements)
         r = _make_skip(dr.get_name(self.component),
                        reason="MISSING_REQUIREMENTS",
                        details=details)
     if not isinstance(r, Response):
         raise Exception("rules must return Response objects.")
     return r
Пример #11
0
def rule_executor(component, broker, requires, optional, executor=dr.default_executor):
    try:
        r = executor(component, broker, requires, optional)
        if r is None:
            name = dr.get_name(component)
            log.debug("Rule %s returned None" % name)
            raise dr.SkipComponent()
    except dr.MissingRequirements as mr:
        details = dr.stringify_requirements(mr.requirements)
        r = make_skip(dr.get_name(component),
                reason="MISSING_REQUIREMENTS", details=details)
    validate_response(r)
    return r
Пример #12
0
    def validate(self):
        if not blacklist.allow_file("/" + self.relative_path):
            raise dr.SkipComponent()

        if not os.path.exists(self.path):
            raise ContentException("%s does not exist." % self.path)

        resolved = os.path.realpath(self.path)
        if not resolved.startswith(os.path.realpath(self.root)):
            msg = "Relative path points outside the root: %s -> %s."
            raise Exception(msg % (self.path, resolved))

        if not os.access(self.path, os.R_OK):
            raise ContentException("Cannot access %s" % self.path)
Пример #13
0
 def __call__(self, ds):
     # /usr/bin/grep level filtering is applied behind .content or
     # .stream(), but we still need to ensure we get only what *this* find
     # instance wants. This can be inefficient on files where many lines
     # match.
     results = {}
     ds = ds if isinstance(ds, list) else [ds]
     for d in ds:
         if d.relative_path:
             origin = os.path.join("/", d.relative_path.lstrip("/"))
         elif d.cmd:
             origin = d.cmd
         else:
             origin = dr.get_name(self.spec)
         stream = d.content if d.loaded else d.stream()
         lines = []
         for line in stream:
             if any(p in line for p in self.pattern):
                 lines.append(line)
         if lines:
             results[origin] = lines
     if not results:
         raise dr.SkipComponent()
     return dict(results)
Пример #14
0
 def inner(lst):
     c = lst[dep]
     if lst:
         return c[0]
     raise dr.SkipComponent()
Пример #15
0
    def validate(self):
        if not blacklist.allow_command(self.cmd):
            raise dr.SkipComponent()

        if not which(shlex.split(self.cmd)[0]):
            raise ContentException("Couldn't execute: %s" % self.cmd)
Пример #16
0
 def inner(broker):
     for c in reversed(dr.get_added_dependencies(inner)):
         if c in broker:
             return broker[c]
     raise dr.SkipComponent()
Пример #17
0
 def validate(self):
     if not blacklist.allow_command(self.cmd):
         raise dr.SkipComponent()
Пример #18
0
 def __call__(self, broker):
     for c in reversed(dr.get_delegate(self).deps):
         if c in broker:
             return broker[c]
     raise dr.SkipComponent()
Пример #19
0
 def __call__(self, lst):
     c = lst[self.dep]
     if lst:
         return c[0]
     raise dr.SkipComponent()