2022-07-31 22:06:19 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright (c) 2022, Felix Fontein (@felixfontein) <felix@fontein.de>
|
|
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
'''
|
|
|
|
Updates DOCUMENTATION of modules using module_utils._api_data with the correct list of supported paths.
|
|
|
|
'''
|
|
|
|
|
2023-09-01 22:27:18 +02:00
|
|
|
import sys
|
|
|
|
|
|
|
|
from ansible_collections.community.routeros.plugins.module_utils._api_data import (
|
2022-07-31 22:06:19 +02:00
|
|
|
PATHS,
|
|
|
|
join_path,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
MODULES = [
|
|
|
|
'plugins/modules/api_info.py',
|
|
|
|
'plugins/modules/api_modify.py',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2025-04-19 13:07:53 +02:00
|
|
|
def update_file(file: str, begin_line: str, end_line: str, choice_line: str, path_choices: list[str]) -> bool:
|
2022-07-31 22:06:19 +02:00
|
|
|
with open(file, 'r', encoding='utf-8') as f:
|
|
|
|
lines = f.read().splitlines()
|
|
|
|
begin_index = lines.index(begin_line)
|
|
|
|
end_index = lines.index(end_line, begin_index + 1)
|
|
|
|
new_lines = lines[:begin_index + 1] + [choice_line.format(choice=choice) for choice in path_choices] + lines[end_index:]
|
2025-04-19 13:07:53 +02:00
|
|
|
if lines == new_lines:
|
|
|
|
return False
|
|
|
|
print(f'{file} has been updated')
|
|
|
|
with open(file, 'w', encoding='utf-8') as f:
|
|
|
|
f.write('\n'.join(new_lines) + '\n')
|
|
|
|
return True
|
2022-07-31 22:06:19 +02:00
|
|
|
|
|
|
|
|
2025-04-19 13:07:53 +02:00
|
|
|
def main(args: list[str]) -> int:
|
2022-07-31 22:06:19 +02:00
|
|
|
path_choices = sorted([join_path(path) for path, path_info in PATHS.items() if path_info.fully_understood])
|
|
|
|
|
2025-04-19 13:07:53 +02:00
|
|
|
changes = False
|
2022-07-31 22:06:19 +02:00
|
|
|
for file in MODULES:
|
2025-04-19 13:07:53 +02:00
|
|
|
changes |= update_file(file, ' # BEGIN PATH LIST', ' # END PATH LIST', ' - {choice}', path_choices)
|
|
|
|
|
|
|
|
lint = "--lint" in args
|
|
|
|
if not lint or not changes:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
print("Run 'nox -Re update-docs'!")
|
|
|
|
return 1
|
2022-07-31 22:06:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2025-04-19 13:07:53 +02:00
|
|
|
sys.exit(main(sys.argv[1:]))
|