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

32 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-02 12:20 +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 - 2026 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 typing import Any 

25from pyTRLCConverter.ret import Ret 

26from pyTRLCConverter.trlc_helper import Record_Object 

27 

28# Variables ******************************************************************** 

29 

30# Classes ********************************************************************** 

31 

32class AbstractConverter(ABC): 

33 # lobster-trace: SwRequirements.sw_req_prj_spec_interface 

34 """Abstract converter interface. 

35 """ 

36 @classmethod 

37 def register(cls, args_parser: Any) -> None: 

38 """Register converter specific argument parser. 

39 

40 Args: 

41 args_parser (Any): Argument parser 

42 """ 

43 raise NotImplementedError 

44 

45 @abstractmethod 

46 def begin(self) -> Ret: 

47 """ Begin the conversion process. 

48 

49 Returns: 

50 Ret: Status 

51 """ 

52 raise NotImplementedError 

53 

54 @abstractmethod 

55 def enter_file(self, file_name : str) -> Ret: 

56 """Enter a file. 

57 

58 Args: 

59 file_name (str): File name 

60  

61 Returns: 

62 Ret: Status 

63 """ 

64 raise NotImplementedError 

65 

66 @abstractmethod 

67 def leave_file(self, file_name : str) -> Ret: 

68 """Leave a file. 

69 

70 Args: 

71 file_name (str): File name 

72 

73 Returns: 

74 Ret: Status 

75 """ 

76 raise NotImplementedError 

77 

78 @abstractmethod 

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

80 """ Process the given section item. 

81 

82 Args: 

83 section (str): The section name 

84 level (int): The section indentation level 

85  

86 Returns: 

87 Ret: Status 

88 """ 

89 raise NotImplementedError 

90 

91 @abstractmethod 

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

93 """ Process the given record object 

94  

95 Args: 

96 record (Record_Object): The record object 

97 level (int): The record indentation level 

98 

99 Returns: 

100 Ret: Status 

101 """ 

102 raise NotImplementedError 

103 

104 @abstractmethod 

105 def finish(self) -> Ret: 

106 """ Finish the conversion process. 

107 

108 Returns: 

109 Ret: Status 

110 """ 

111 raise NotImplementedError 

112 

113 @staticmethod 

114 def get_subcommand() -> str: 

115 """ Return subcommand token for this converter. 

116 

117 Returns: 

118 str: subcomand argument token 

119 """ 

120 raise NotImplementedError 

121 

122 @staticmethod 

123 def get_description() -> str: 

124 """ Return converter description.  

125  

126 Returns: 

127 str: Converter description 

128 """ 

129 raise NotImplementedError