Example #1
0
 def report(self, tracker):
     with open(self.logpath, 'a') as log:
         print('=' * 40, file=log)
         print('{}'.format(tracker.school.upper()), file=log)
         print('=={}=='.format(tracker.mode.upper()), file=log)
         if tracker.saw_error:
             print('FAILED:\n\n{}'.format(tracker.error), file=log)
         print('TIMESTAMP (UTC): {}'.format(tracker.timestamp), file=log)
         print('ELAPSED: {}'.format(
             str(
                 datetime.timedelta(seconds=int(tracker.end_time -
                                                tracker.start_time)))),
               file=log)
         if hasattr(tracker, 'cmd_options'):
             print('COMMAND OPTIONS:\n{}'.format(
                 pretty_json(tracker.cmd_options)),
                   file=log)
         statistics = {
             subject:
             {stat: value
              for stat, value in stats.items() if value != 0}
             for subject, stats in self.statuses.stats.items()
             if len(stats) > 0
         }
         print('STATS:\n{}'.format(pretty_json(statistics)), file=log)
         if hasattr(tracker, 'granularity'):
             print('calculated granularity: {}'.format(tracker.granularity),
                   file=log)
Example #2
0
def colored_json(j):
    lexer = lexers.JsonLexer()
    lexer.add_filter('whitespace')
    colorful_json = highlight(unicode(pretty_json(j), 'UTF-8'),
                              lexer,
                              formatters.TerminalFormatter())
    return colorful_json
Example #3
0
    def __init__(self, data, *args):
        """Construct PipelineError instance.

        Add data to args.

        Args:
            data: Prettified if possible.
            *args
        """
        if isinstance(data, dict):
            try:
                data = pretty_json(data)
            except TypeError:
                pass
        super(PipelineException, self).__init__(data, *args)
Example #4
0
    def __init__(self, data, *args):
        """Construct PipelineError instance.

        Add data to args.

        Args:
            data: Prettified if possible.
            *args
        """
        if isinstance(data, dict):
            try:
                data = pretty_json(data)
            except TypeError:
                pass
        super(PipelineException, self).__init__(data, *args)
Example #5
0
    def format(self, record):
        """Format record message.

        Args:
            record (logging.LogRecord): Description

        Returns:
            str: Prettified JSON string.
        """
        if isinstance(record.args, dict):
            try:
                prettified = pretty_json(record.args)
                record.msg += "\n" + prettified
            except TypeError:
                pass
        return super(JSONFormatter, self).format(record)
Example #6
0
    def format(self, record):
        """Format record message.

        Args:
            record (logging.LogRecord): Description

        Returns:
            str: Prettified JSON string.
        """
        if isinstance(record.args, dict):
            try:
                prettified = pretty_json(record.args)
                record.msg += '\n' + prettified
            except TypeError:
                pass
        return super(JSONFormatter, self).format(record)
Example #7
0
    def write_obj(self, obj):
        """Write obj as JSON to file.

        Args:
            obj (dict): Serializable obj to write to file.
        """
        if self.first:
            self.first = False
        else:
            print(',', file=self.file)

        tabbing = '  ' * (self.level + 1)
        print(tabbing + ('\n' + tabbing).join(pretty_json(obj).splitlines()),
              file=self.file,
              sep='\n',
              end='')
Example #8
0
    def write_obj(self, obj):
        """Write obj as JSON to file.

        Args:
            obj (dict): Serializable obj to write to file.
        """
        if self.first:
            self.first = False
        else:
            print(',', file=self.file)

        tabbing = '  ' * (self.level + 1)
        print(tabbing + ('\n' + tabbing).join(pretty_json(obj).splitlines()),
              file=self.file,
              sep='\n',
              end='')
Example #9
0
    def write_key_value(self, key, value=None, type_=list):
        """Write key, value pair as string to file.

        If value is not given, returns new list streamer.

        Args:
            key (str): Description
            value (str, dict, None, optional): Description
            type_ (str, optional): Description

        Returns:
            None if value is given, else new JSONStreamWriter
        """
        if self.first:
            self.first = False
        else:
            print(",", file=self.file)

        if value is None:
            print(
                "  " * (self.level + 1),
                '"{}":'.format(key),
                file=self.file,
                sep="",
                end="\n",
            )
            return JSONStreamWriter(self.file,
                                    type_=type_,
                                    level=self.level + 1)

        if isinstance(value, dict) or isinstance(value, list):
            tabbing = "\n" + "  " * (self.level + 1)
            value = tabbing.join(pretty_json(value).splitlines())
        elif isinstance(value, str):
            value = '"{}"'.format(value)

        tabbing = "  " * (self.level + 1)
        print(tabbing,
              '"{}": {}'.format(key, value),
              file=self.file,
              sep="",
              end="")
Example #10
0
    def write_key_value(self, key, value=None, type_=list):
        """Write key, value pair as string to file.

        If value is not given, returns new list streamer.

        Args:
            key (str): Description
            value (str, dict, None, optional): Description
            type_ (str, optional): Description

        Returns:
            None if value is given, else new JSONStreamWriter
        """
        if self.first:
            self.first = False
        else:
            print(',', file=self.file)

        if value is None:
            print('  ' * (self.level + 1), '"{}":'.format(key),
                  file=self.file,
                  sep='',
                  end='\n')
            return JSONStreamWriter(self.file,
                                    type_=type_,
                                    level=self.level + 1)

        if isinstance(value, dict) or isinstance(value, list):
            tabbing = '\n' + '  ' * (self.level + 1)
            value = tabbing.join(pretty_json(value).splitlines())
        elif isinstance(value, str):
            value = '"{}"'.format(value)

        tabbing = '  ' * (self.level + 1)
        print(tabbing, '"{}": {}'.format(key, value),
              file=self.file,
              sep='',
              end='')
Example #11
0
def colored_json(j):
    lexer = lexers.JsonLexer()
    lexer.add_filter("whitespace")
    colorful_json = highlight(str(pretty_json(j), "UTF-8"), lexer,
                              formatters.TerminalFormatter())
    return colorful_json
Example #12
0
def colored_json(j):
    lexer = lexers.JsonLexer()
    lexer.add_filter('whitespace')
    colorful_json = highlight(unicode(pretty_json(j), 'UTF-8'), lexer,
                              formatters.TerminalFormatter())
    return colorful_json