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

29 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 

4from __future__ import annotations 

5 

6import operator 

7from typing import TYPE_CHECKING 

8 

9from weblate.trans.file_format_params import FILE_FORMATS_PARAMS 

10from weblate.utils.management.base import BaseCommand 

11from weblate.utils.rst import format_rst_string, format_table 

12 

13if TYPE_CHECKING: 

14 from collections.abc import Sequence 

15 

16 

17class Command(BaseCommand): 

18 help = "List file format parameters" 

19 

20 def format_file_formats(self, file_formats: Sequence[str]) -> str: 

21 return "\n".join(f"* ``{f}``" for f in file_formats) 

22 

23 def get_help_text(self, param) -> str: 

24 result = [] 

25 if param.help_text: 

26 result.append(format_rst_string(param.help_text)) 

27 if param.choices: 

28 if result: 

29 result.append("") 

30 result.append("Available choices:") 

31 for value, description in param.choices: 

32 result.extend( 

33 ( 

34 "", 

35 f"``{value}``".replace("\\", "\\\\"), 

36 f" {format_rst_string(description)}".replace("\\", "\\\\"), 

37 ) 

38 ) 

39 return "\n".join(result) 

40 

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

42 """List file format parameters.""" 

43 self.stdout.write(""".. 

44 Partly generated using ./manage.py list_file_format_params\n 

45""") 

46 header = [ 

47 "Parameter name", 

48 "File formats", 

49 "Label", 

50 "Help text", 

51 ] 

52 table = sorted( 

53 [ 

54 [ 

55 param.name, 

56 self.format_file_formats(param.file_formats), 

57 str(param.label), 

58 self.get_help_text(param), 

59 ] 

60 for param in FILE_FORMATS_PARAMS 

61 ], 

62 key=operator.itemgetter(0), 

63 ) 

64 for table_row in format_table(table, header): 

65 self.stdout.write(table_row)