Coverage for app/venv/lib/python3.14/site-packages/weblate/machinery/management/commands/list_machinery.py: 0%

51 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 07:15 +0000

1# Copyright © Michal Čihař <michal@weblate.org> 

2# 

3# SPDX-License-Identifier: GPL-3.0-or-later 

4 

5from __future__ import annotations 

6 

7from weblate.machinery.models import MACHINERY 

8from weblate.utils.management.base import BaseCommand 

9from weblate.utils.rst import format_table 

10 

11 

12class Command(BaseCommand): 

13 help = "List installed machineries" 

14 

15 @staticmethod 

16 def get_help_text(field) -> str: 

17 result = [] 

18 if field.help_text: 

19 result.append(str(field.help_text)) 

20 choices = getattr(field, "choices", None) 

21 if choices: 

22 if result: 

23 result.append("") 

24 result.append("Available choices:") 

25 for value, description in choices: 

26 result.extend( 

27 ("", f"``{value}`` -- {description}".replace("\\", "\\\\")) 

28 ) 

29 return "\n".join(result) 

30 

31 def handle(self, *args, **options) -> None: 

32 """List installed add-ons.""" 

33 self.stdout.write(""".. 

34 Partly generated using ./manage.py list_machinery 

35""") 

36 for _unused, obj in sorted(MACHINERY.items()): 

37 self.stdout.write(f".. _mt-{obj.get_identifier()}:") 

38 self.stdout.write("\n") 

39 self.stdout.write(obj.name) 

40 self.stdout.write("-" * len(obj.name)) 

41 self.stdout.write("\n") 

42 self.stdout.write(f":Service ID: ``{obj.get_identifier()}``") 

43 self.stdout.write(f":Maximal score: {obj.max_score}") 

44 features = [] 

45 if obj.highlight_syntax: 

46 features.append(":ref:`placeables-mt`") 

47 if obj.glossary_support: 

48 features.append(":ref:`glossary-mt`") 

49 if features: 

50 prefix = ":Advanced features: " 

51 for feature in features: 

52 self.stdout.write(f"{prefix}* {feature}") 

53 if not prefix.isspace(): 

54 prefix = " " * len(prefix) 

55 

56 if obj.settings_form: 

57 form = obj.settings_form(obj) 

58 table: list[list[str | list[list[str]]]] = [ 

59 [f"``{name}``", str(field.label), self.get_help_text(field)] 

60 for name, field in form.fields.items() 

61 ] 

62 prefix = ":Configuration: " 

63 for table_row in format_table(table, None): 

64 self.stdout.write(f"{prefix}{table_row}") 

65 if not prefix.isspace(): 

66 prefix = " " * len(prefix) 

67 else: 

68 self.stdout.write( 

69 ":Configuration: `This service has no configuration.`" 

70 ) 

71 self.stdout.write("\n") 

72 self.stdout.write("\n")