Esempio n. 1
0
 def __str__(self):
     base = reflection.get_class_name(self, fully_qualified=False)
     if self.strategy is not None:
         strategy_name = self.strategy.name
     else:
         strategy_name = "???"
     return base + "(strategy=%s)" % (strategy_name)
Esempio n. 2
0
 def __repr__(self):
     repr_msg = "%s object at 0x%x calling into '%r'" % (
         reflection.get_class_name(
             self, fully_qualified=False), id(self), self._callback)
     if self._details_filter is not None:
         repr_msg += " using details filter '%r'" % self._details_filter
     return "<%s>" % repr_msg
Esempio n. 3
0
 def pformat(self, indent=2, indent_text=" ", show_root_class=False):
     """Pretty formats a taskflow exception + any connected causes."""
     if indent < 0:
         raise ValueError("Provided 'indent' must be greater than"
                          " or equal to zero instead of %s" % indent)
     buf = six.StringIO()
     if show_root_class:
         buf.write(reflection.get_class_name(self, fully_qualified=False))
         buf.write(": ")
     buf.write(self._get_message())
     active_indent = indent
     next_up = self.cause
     seen = []
     while next_up is not None and next_up not in seen:
         seen.append(next_up)
         buf.write(os.linesep)
         if isinstance(next_up, TaskFlowException):
             buf.write(indent_text * active_indent)
             buf.write(reflection.get_class_name(next_up,
                                                 fully_qualified=False))
             buf.write(": ")
             buf.write(next_up._get_message())
         else:
             lines = traceback.format_exception_only(type(next_up), next_up)
             for i, line in enumerate(lines):
                 buf.write(indent_text * active_indent)
                 if line.endswith("\n"):
                     # We'll add our own newlines on...
                     line = line[0:-1]
                 buf.write(line)
                 if i + 1 != len(lines):
                     buf.write(os.linesep)
         if not isinstance(next_up, TaskFlowException):
             # Don't go deeper into non-taskflow exceptions... as we
             # don't know if there exception 'cause' attributes are even
             # useable objects...
             break
         active_indent += indent
         next_up = getattr(next_up, 'cause', None)
     return buf.getvalue()
Esempio n. 4
0
    def check(self, *exc_classes):
        """Check if any of ``exc_classes`` caused the failure.

        Arguments of this method can be exception types or type
        names (stings). If captured exception is instance of
        exception of given type, the corresponding argument is
        returned. Else, None is returned.
        """
        for cls in exc_classes:
            if isinstance(cls, type):
                err = reflection.get_class_name(cls)
            else:
                err = cls
            if err in self._exc_type_names:
                return cls
        return None
Esempio n. 5
0
 def _atomdetail_by_name(self, atom_name, expected_type=None, clone=False):
     try:
         ad = self._flowdetail.find(self._atom_name_to_uuid[atom_name])
     except KeyError:
         exceptions.raise_with_cause(exceptions.NotFound,
                                     "Unknown atom name '%s'" % atom_name)
     else:
         # TODO(harlowja): we need to figure out how to get away from doing
         # these kinds of type checks in general (since they likely mean
         # we aren't doing something right).
         if expected_type and not isinstance(ad, expected_type):
             raise TypeError(
                 "Atom '%s' is not of the expected type: %s" %
                 (atom_name, reflection.get_class_name(expected_type)))
         if clone:
             return (ad, ad.copy())
         else:
             return (ad, ad)
Esempio n. 6
0
 def __init__(self,
              name=None,
              provides=None,
              requires=None,
              auto_extract=True,
              rebind=None,
              inject=None,
              ignore_list=None,
              revert_rebind=None,
              revert_requires=None):
     if name is None:
         name = reflection.get_class_name(self)
     super(Task, self).__init__(name,
                                provides=provides,
                                requires=requires,
                                auto_extract=auto_extract,
                                rebind=rebind,
                                inject=inject,
                                revert_rebind=revert_rebind,
                                revert_requires=revert_requires)
     self._notifier = notifier.RestrictedNotifier(self.TASK_EVENTS)
Esempio n. 7
0
 def __str__(self):
     cls_name = reflection.get_class_name(self)
     if cls_name.startswith(_CHOP_PAT):
         cls_name = cls_name[_CHOP_PAT_LEN:]
     return "%s: %s(len=%d)" % (cls_name, self.name, len(self))
Esempio n. 8
0
 def __repr__(self):
     return '<%s %s>' % (reflection.get_class_name(self), self)