Coverage for src/pyTRLCConverter/dump_converter.py: 100%
27 statements
« prev ^ index » next coverage.py v7.10.3, created at 2025-08-14 10:59 +0000
« prev ^ index » next coverage.py v7.10.3, created at 2025-08-14 10:59 +0000
1""" Converter base class which does nothing (besides printing call names in verbose mode.)
3 Author: Norbert Schulz (norbert.schulz@newtec.de)
4"""
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/>.
22# Imports **********************************************************************
23from typing import Optional
24from pyTRLCConverter.base_converter import BaseConverter
25from pyTRLCConverter.ret import Ret
26from pyTRLCConverter.trlc_helper import Record_Object
28# Variables ********************************************************************
30# Classes **********************************************************************
32class DumpConverter(BaseConverter):
33 # lobster-trace: SwRequirements.sw_req_no_prj_spec
34 # lobster-trace: SwRequirements.sw_req_ascii_conversion
35 """Simple converter implementation that just dumps all items.
36 """
38 @staticmethod
39 def get_subcommand() -> str:
40 """ Return subcommand token for this converter.
42 Returns:
43 str: Parser subcommand token
44 """
45 return "dump"
47 @staticmethod
48 def get_description() -> str:
49 """ Return converter description.
51 Returns:
52 str: Converter description
53 """
54 return "Dump TRCL item list to console."
56 def enter_file(self, file_name: str) -> Ret:
57 """Enter a file.
59 Args:
60 file_name (str): File name
62 Returns:
63 Ret: Status
64 """
65 print(f"Entering file: {file_name}")
66 return Ret.OK
68 def leave_file(self, file_name: str) -> Ret:
69 """Leave a file.
71 Args:
72 file_name (str): File name
74 Returns:
75 Ret: Status
76 """
77 print(f"Leaving file: {file_name}")
78 return Ret.OK
80 def convert_section(self, section: str, level: int) -> Ret:
81 """Process the given section item.
83 Args:
84 section (str): The section name
85 level (int): The section indentation level
87 Returns:
88 Ret: Status
89 """
90 print(f"{' ' * level}Section: {section} at level: {level}")
91 return Ret.OK
93 def convert_record_object_generic(self, record: Record_Object, level: int, translation: Optional[dict]) -> Ret:
94 """
95 Process the given record object in a generic way.
97 The handler is called by the base converter if no specific handler is
98 defined for the record type.
100 Args:
101 record (Record_Object): The record object.
102 level (int): The record level.
103 _translation (Optional[dict]): Translation dictionary for the record object.
104 If None, no translation is applied.
106 Returns:
107 Ret: Status
108 """
110 print(f"{' ' * level}Record {record.name}, Level: {level}")
111 print(f"{record.dump(indent=level+1)}")
112 return Ret.OK
114 def finish(self)-> Ret:
115 """Finish the conversion process.
117 Returns:
118 Ret: Status
119 """
120 print("Finishing conversion process.")
121 return Ret.OK