Ejemplo n.º 1
0
    def handle(self, *args, **options):
        """List installed checks."""
        ignores = []
        lines = []
        for check in sorted(CHECKS.values(), key=sorter):
            is_format = isinstance(check, BaseFormatCheck)
            if not is_format and lines:
                self.flush_lines(lines)
            # Output immediately
            self.stdout.write(f".. _{check.doc_id}:\n")
            if not lines:
                lines.append("\n")
            lines.append(str(check.name))
            if is_format:
                lines.append("*" * len(check.name))
            else:
                lines.append("~" * len(check.name))
            lines.append("\n")
            lines.append("\n".join(wrap(f"*{check.description}*", 79)))
            lines.append("\n")

            if not is_format:
                self.flush_lines(lines)

            ignores.append(f"``{check.ignore_string}``")
            ignores.append(f'    Skip the "{check.name}" quality check.')

        self.stdout.write("\n")
        self.stdout.writelines(ignores)
Ejemplo n.º 2
0
    def handle(self, *args, **options):
        """List installed checks."""
        ignores = []
        enables = []
        lines = []
        for check in sorted(CHECKS.values(), key=sorter):
            check_class = check.__class__
            is_format = isinstance(check, BaseFormatCheck)
            # Output immediately
            self.stdout.write(f".. _{check.doc_id}:\n")
            if not lines:
                lines.append("\n")
            name = escape(check.name)
            lines.append(name)
            if is_format:
                lines.append("*" * len(name))
            else:
                lines.append("~" * len(name))
            lines.append("\n")
            lines.append(f":Summary: {escape(check.description)}")
            if check.target:
                if check.ignore_untranslated:
                    lines.append(":Scope: translated strings")
                else:
                    lines.append(":Scope: all strings")
            if check.source:
                lines.append(":Scope: source strings")
            lines.append(
                f":Check class: ``{check_class.__module__}.{check_class.__qualname__}``"
            )
            if check.default_disabled:
                lines.append(f":Flag to enable: ``{check.enable_string}``")
            lines.append(f":Flag to ignore: ``{check.ignore_string}``")
            lines.append("\n")

            self.flush_lines(lines)

            ignores.append(f"``{check.ignore_string}``")
            ignores.append(
                f"    Skip the :ref:`{check.doc_id}` quality check.")
            if check.default_disabled:
                enables.append(f"``{check.enable_string}``")
                enables.append(
                    f"    Enable the :ref:`{check.doc_id}` quality check.")

        self.stdout.write("\n")
        self.stdout.writelines(enables)
        self.stdout.writelines(ignores)
Ejemplo n.º 3
0
    def handle(self, *args, **options):
        """List installed checks."""
        lines = []
        for check in sorted(CHECKS.values(), key=sorter):
            is_format = isinstance(check, BaseFormatCheck)
            if not is_format and lines:
                self.flush_lines(lines)
            # Output immediatelly
            self.stdout.write(".. _{}:\n".format(check.doc_id))
            if not lines:
                lines.append("\n")
            lines.append(str(check.name))
            if is_format:
                lines.append("*" * len(check.name))
            else:
                lines.append("~" * len(check.name))
            lines.append("\n")
            lines.append("\n".join(wrap("*{}*".format(check.description), 79)))
            lines.append("\n")

            if not is_format:
                self.flush_lines(lines)
Ejemplo n.º 4
0
 def prefetch_checks(self):
     """Prefetch check stats."""
     allchecks = {check.url_id for check in CHECKS.values()}
     stats = (self._object.unit_set.filter(
         check__dismissed=False).values("check__check").annotate(
             strings=Count("pk"),
             words=Sum("num_words"),
             chars=Sum(Length("source"))))
     for stat in stats:
         check = stat["check__check"]
         # Filtering here is way more effective than in SQL
         if check is None:
             continue
         check = "check:{}".format(check)
         self.store(check, stat["strings"])
         self.store(check + "_words", stat["words"])
         self.store(check + "_chars", stat["chars"])
         allchecks.discard(check)
     for check in allchecks:
         self.store(check, 0)
         self.store(check + "_words", 0)
         self.store(check + "_chars", 0)