Coverage for src/pyTRLCConverter/abstract_converter.py: 71%

31 statements  

« prev     ^ index     » next       coverage.py v7.10.3, created at 2025-08-14 10:59 +0000

1"""Abstract converter interface which all implementations must fullfill. 

2 

3Author: Norbert Schulz (norbert.schulz@newtec.de) 

4""" 

5 

6# pyTRLCConverter - A tool to convert TRLC files to specific formats. 

7# Copyright (c) 2024 - 2025 NewTec GmbH 

8# 

9# This file is part of pyTRLCConverter program. 

10# 

11# The pyTRLCConverter program is free software: you can redistribute it and/or modify it under 

12# the terms of the GNU General Public License as published by the Free Software Foundation, 

13# either version 3 of the License, or (at your option) any later version. 

14# 

15# The pyTRLCConverter program is distributed in the hope that it will be useful, but 

16# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 

17# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License along with pyTRLCConverter. 

20# If not, see <https://www.gnu.org/licenses/>. 

21 

22# Imports ********************************************************************** 

23from abc import ABC, abstractmethod 

24from pyTRLCConverter.ret import Ret 

25from pyTRLCConverter.trlc_helper import Record_Object 

26 

27# Variables ******************************************************************** 

28 

29# Classes ********************************************************************** 

30 

31class AbstractConverter(ABC): 

32 # lobster-trace: SwRequirements.sw_req_prj_spec_interface 

33 """Abstract converter interface. 

34 """ 

35 @classmethod 

36 def register(cls, args_parser: any) -> None: 

37 """Register converter specific argument parser. 

38 

39 Args: 

40 args_parser (any): Argument parser 

41 """ 

42 raise NotImplementedError 

43 

44 @abstractmethod 

45 def begin(self) -> Ret: 

46 """ Begin the conversion process. 

47 

48 Returns: 

49 Ret: Status 

50 """ 

51 raise NotImplementedError 

52 

53 @abstractmethod 

54 def enter_file(self, file_name : str) -> None: 

55 """Enter a file. 

56 

57 Args: 

58 file_name (str): File name 

59 """ 

60 raise NotImplementedError 

61 

62 @abstractmethod 

63 def leave_file(self, file_name : str) -> None: 

64 """Leave a file. 

65 

66 Args: 

67 file_name (str): File name 

68 """ 

69 raise NotImplementedError 

70 

71 @abstractmethod 

72 def convert_section(self, section: str, level: int) -> Ret: 

73 """ Process the given section item. 

74 

75 Args: 

76 section (str): The section name 

77 level (int): The section indentation level 

78  

79 Returns: 

80 Ret: Status 

81 """ 

82 raise NotImplementedError 

83 

84 @abstractmethod 

85 def convert_record_object(self, record : Record_Object, level: int) -> Ret: 

86 """ Process the given record object 

87  

88 Args: 

89 record (Record_Object): The record object 

90 level (int): The record indentation level 

91 

92 Returns: 

93 Ret: Status 

94 """ 

95 raise NotImplementedError 

96 

97 @abstractmethod 

98 def finish(self) -> Ret: 

99 """ Finish the conversion process. 

100 

101 Returns: 

102 Ret: Status 

103 """ 

104 raise NotImplementedError 

105 

106 @staticmethod 

107 def get_subcommand() -> str: 

108 """ Return subcommand token for this converter. 

109 

110 Returns: 

111 str: subcomand argument token 

112 """ 

113 raise NotImplementedError 

114 

115 @staticmethod 

116 def get_description() -> str: 

117 """ Return converter description.  

118  

119 Returns: 

120 str: Converter description 

121 """ 

122 raise NotImplementedError