Exemplo n.º 1
0
 def __init__(self, exc, middleware=None):
     self.middleware = middleware
     self.timestamp = TimeUtils.utc_now()
     self.exc = exc
     if isinstance(exc, RavelError) and exc.wrapped_traceback:
         self.trace = self.exc.wrapped_traceback.strip().split('\n')[1:]
         self.exc_message = self.trace[-1].split(': ', 1)[1]
     else:
         self.trace = traceback.format_exc().strip().split('\n')[1:]
         final_line = self.trace[-1]
         if ':' in final_line:
             self.exc_message = final_line.split(':', 1)[1]
         else:
             self.exc_message = None
Exemplo n.º 2
0
    def __init__(
        self,
        method: Text,
        args: Tuple = None,
        kwargs: Dict = None,
        result=None,
        exc: Exception = None,
    ):
        self.method = method
        self.args = list(args) if args else []
        self.kwargs = kwargs or {}
        self.result = result
        self.timestamp = TimeUtils.utc_now()
        self.exc = exc

        # fix up create and create_many args and kwargs.
        # see the doc string for _backfill_id_fields.
        if (exc is None) and (method in {'create', 'create_many'}):
            self._backfill_id_fields(result)
Exemplo n.º 3
0
    def process_message(self, level: Text, message: Text, data: Dict) -> Text:
        when = TimeUtils.utc_now().strftime('%m/%d/%Y %H:%M:%S')
        level = level.upper()[0]

        if data:
            data = json.decode(json.encode(data))
            if self._style == 'json':
                dumped_data = self._to_json(data)
            elif self._style == 'yaml':
                dumped_data = self._to_yaml(data)
            else:
                raise ValueError(f'unrecognized log style: {self.style}')
        else:
            dumped_data = None

        display_string = f'{when} ({level}) {self._name} - {message}'
        if dumped_data:
            display_string += f'\n\n{dumped_data}\n'
        return display_string
Exemplo n.º 4
0
    def __init__(
        self,
        embryo_name: str,
        destination: str,
        context: Dict = None,
        embryo: 'Embryo' = None,
    ):
        """
        Generate an embryo, along with any embryos nested therein. Returns a
        list of Renderer objects. The first instance is the embryo being
        generated, and the rest are the nested ones.

        # Args
        - `embryo_name`: The name of the embryo.
        - `destination`: Directory to hatch embryo into
        - `context`: Context data to merge into other sources.
        """
        self._embryo_class = None
        self._embryo_path = None
        self._embryo = None

        if embryo_name is None:
            # this should mean we're coming from the
            # from_embryo factory method
            return

        # ------
        # Add Embryo metadata to context
        context.update({
            'embryo': {
                'name': embryo_name,
                'destination':
                os.path.abspath(os.path.expanduser(destination)),
                'timestamp': TimeUtils.utc_now(),
                'action': 'hatch',
            }
        })

        embryo_name, embryo_path, embryo_class = get_embryo_resource(
            embryo_name)
        self._embryo = embryo_class(embryo_path, context)
Exemplo n.º 5
0
 def logout(self):
     if self.is_active:
         self.update(logged_out_at=TimeUtils.utc_now(), is_active=False)