23 @brief This class should be used to parse and store a doxygen configuration file
32 @brief Parse a Doxygen configuration file
33 @param doxyfile : doxyfile: Path to the Doxygen configuration file
34 @return A dict with all doxygen configuration
37 if not os.path.exists(doxyfile):
38 logging.error(
"Impossible to access to %s", doxyfile)
39 raise FileNotFoundError(doxyfile)
41 configuration: dict[str, str | list[str]] = {}
43 with open(doxyfile,
'r', encoding=
'utf-8')
as file:
45 in_multiline_option =
False
46 current_multiline_option_name =
None
48 for line
in file.readlines():
56 if in_multiline_option:
57 if not line.endswith(
'\\'):
58 in_multiline_option =
False
59 option_value = line.rstrip(
'\\').strip()
60 if current_multiline_option_name
is not None:
61 configuration[current_multiline_option_name].append(option_value)
65 configuration[current_multiline_option_name] = [option_value]
66 in_multiline_option =
True
70 configuration[option_name] = option_value
76 @brief Store the doxygen configuration to the disk
77 @param config : The doxygen configuration you want to write on disk
78 @param doxyfile : The output path where configuration will be written. If the file exist, it will be truncated
81 logging.debug(
"Store configuration in %s", doxyfile)
84 for option_name, option_value
in config.items():
85 if isinstance(option_value, list):
87 lines.append(f
"{option_name} = {self.__add_double_quote_if_required(option_value[0], force_double_quote=True)} \\")
88 lines.extend([f
"\t{self.__add_double_quote_if_required(value, force_double_quote=True)} \\" for value
in option_value[1:-1]])
89 lines.append(f
"\t{self.__add_double_quote_if_required(option_value[-1], force_double_quote=True)}")
90 elif isinstance(option_value, str):
91 lines.append(f
"{option_name} = {self.__add_double_quote_if_required(option_value)}")
93 with open(doxyfile,
'w', encoding=
'utf-8')
as file:
94 file.write(
"\n".join(lines))
96 def __extract_multiline_option_name_and_first_value(self, line: str) -> tuple[str, str]:
98 @brief Extract the option name and the first value of multi line option
99 @param line : The line you want to parse
100 @return the option name and the option first value
104 if matches
is None or len(matches.groups()) != 2:
105 logging.error(
"Impossible to extract first value off multi line option from: %s", line)
106 raise ParseException(f
"Impossible to extract first value off multi line option from: {line}")
110 def __extract_single_line_option_name_and_value(self, line: str) -> tuple[str, str]:
112 @brief Extract the option name and the value of single line option
113 @param line : The line you want to parse
114 @return the option name and the option value
119 if matches
is None or len(matches.groups()) != 2:
120 logging.error(
"Impossible to extract option name and value from: %s", line)
121 raise ParseException(f
"Impossible to extract option name and value from: {line}")
125 def __is_single_line_option(self, line: str) -> bool:
127 @brief Match single line option
128 @param line : The line you want to parse
129 @return single line option status
133 def __is_comment_line(self, line: str) -> bool:
135 @brief Match comment line
136 @param line : The line you want to parse
137 @return comment line option status
139 return line.startswith(
"#")
141 def __is_first_line_of_multiline_option(self, line: str) -> bool:
143 @brief Match first line option
144 @param line : The line you want to parse
145 @return first line option status
150 def __remove_double_quote_if_required(option_value: str) -> str:
152 @brief Remove the double quote around string in option value.
153 Will be replaced when rewrite the configuration
154 @param option_value : The value you want to work on
155 @return The option value proper
157 if option_value.startswith(
'"')
and option_value.endswith(
'"'):
158 option_value_formatted = option_value[1:-1]
159 logging.debug(
"Remove quote from %s to %s", option_value, option_value_formatted)
160 return option_value_formatted
165 def __add_double_quote_if_required(option_value: str, force_double_quote: bool =
False) -> str:
167 @brief Add the double quote around string in option value if its required
168 @param option_value : The value you want to work on
169 @param force_double_quote : force double quote
170 @return The option value proper
172 if (
" " in option_value)
or force_double_quote:
173 option_value_formatted = f
'"{option_value}"'
174 logging.debug(
"Add quote from %s to %s", option_value, option_value_formatted)
175 return option_value_formatted