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

32 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2025-11-21 12:06 +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 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) -> None: 

56 """Enter a file. 

57 

58 Args: 

59 file_name (str): File name 

60 """ 

61 raise NotImplementedError 

62 

63 @abstractmethod 

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

65 """Leave a file. 

66 

67 Args: 

68 file_name (str): File name 

69 """ 

70 raise NotImplementedError 

71 

72 @abstractmethod 

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

74 """ Process the given section item. 

75 

76 Args: 

77 section (str): The section name 

78 level (int): The section indentation level 

79  

80 Returns: 

81 Ret: Status 

82 """ 

83 raise NotImplementedError 

84 

85 @abstractmethod 

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

87 """ Process the given record object 

88  

89 Args: 

90 record (Record_Object): The record object 

91 level (int): The record indentation level 

92 

93 Returns: 

94 Ret: Status 

95 """ 

96 raise NotImplementedError 

97 

98 @abstractmethod 

99 def finish(self) -> Ret: 

100 """ Finish the conversion process. 

101 

102 Returns: 

103 Ret: Status 

104 """ 

105 raise NotImplementedError 

106 

107 @staticmethod 

108 def get_subcommand() -> str: 

109 """ Return subcommand token for this converter. 

110 

111 Returns: 

112 str: subcomand argument token 

113 """ 

114 raise NotImplementedError 

115 

116 @staticmethod 

117 def get_description() -> str: 

118 """ Return converter description.  

119  

120 Returns: 

121 str: Converter description 

122 """ 

123 raise NotImplementedError