From 00af175e0bb2fd5fd5707e57bade7fd4581b92b0 Mon Sep 17 00:00:00 2001 From: Florian Ludwig Date: Sat, 27 Mar 2021 14:00:16 +0100 Subject: [PATCH] code generator for transitioning module --- gen_transition_code.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 gen_transition_code.py diff --git a/gen_transition_code.py b/gen_transition_code.py new file mode 100644 index 0000000..f534047 --- /dev/null +++ b/gen_transition_code.py @@ -0,0 +1,32 @@ +import pathlib + + +template = """import warnings +from {module_name} import * + +warnings.warn("importing hbmqtt is deprecated. Please import amqtt", DeprecationWarning) +""" + + +def main(): + src = pathlib.Path("amqtt") + dst = pathlib.Path("hbmqtt") + + for py_file in src.glob("**/*.py"): + + file_path = py_file.parent.relative_to(src) + dst_file = dst / file_path / py_file.name + module_name = "amqtt" + sub_modue = str(file_path).replace("/", ".").strip(".") + if sub_modue: + module_name += "." + sub_modue + + if py_file.name != "__init__.py": + module_name += "." + py_file.name[:-3] + + dst_file.parent.mkdir(parents=True, exist_ok=True) + dst_file.write_text(template.format(module_name=module_name)) + + +if __name__ == "__main__": + main()