aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-26 17:52:32 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-11-27 09:05:31 +0000
commit1b6ce6a3645a75732d31d3ddd070e21b19b7b24e (patch)
tree9710d863771af58ff67825eb914999aefe4d7a28 /tools
parent84120c6fb9e791fb2d1f6149e88bb3b27adb353c (diff)
snippets_translate: Streamline writing files
The code created all example directories first and extracted the snippets to .cpp files which were later moved to .py files to overwrite the snippets in the repository (back then). Write to the Python file directly and create the directory only when needed. This removes a lot of empty directories. Task-number: PYSIDE-1721 Change-Id: I38e695db4aae386be18cd3b85708f684bfa228d5 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> (cherry picked from commit 742a39962f1ba9c0e42f387394768c13793144c0) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/snippets_translate/main.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/tools/snippets_translate/main.py b/tools/snippets_translate/main.py
index d687ef6d5..792328933 100644
--- a/tools/snippets_translate/main.py
+++ b/tools/snippets_translate/main.py
@@ -277,7 +277,18 @@ def translate_file(file_path, final_path, debug, write):
if write:
# Open the final file
- with open(str(final_path), "w") as out_f:
+ target_file = final_path.with_suffix(".py")
+
+ # Directory where the file will be placed, if it does not exists
+ # we create it. The option 'parents=True' will create the parents
+ # directories if they don't exist, and if some of them exists,
+ # the option 'exist_ok=True' will ignore them.
+ if not target_file.parent.is_dir():
+ if not opt_quiet:
+ log.info(f"Creating directories for {target_file.parent}")
+ target_file.parent.mkdir(parents=True, exist_ok=True)
+
+ with target_file.open("w") as out_f:
out_f.write(license_header)
out_f.write("\n\n")
@@ -285,8 +296,6 @@ def translate_file(file_path, final_path, debug, write):
out_f.write(s)
out_f.write("\n")
- # Rename to .py
- written_file = shutil.move(str(final_path), str(final_path.with_suffix(".py")))
if not opt_quiet:
log.info(f"Written: {written_file}")
else:
@@ -329,15 +338,6 @@ def copy_file(file_path, py_path, category, category_path, write=False, debug=Fa
else:
log.info(f"{status_msg:10s} {final_path}")
- # Directory where the file will be placed, if it does not exists
- # we create it. The option 'parents=True' will create the parents
- # directories if they don't exist, and if some of them exists,
- # the option 'exist_ok=True' will ignore them.
- if write and not final_path.parent.is_dir():
- if not opt_quiet:
- log.info(f"Creating directories for {final_path.parent}")
- final_path.parent.mkdir(parents=True, exist_ok=True)
-
# Change .cpp to .py
# TODO:
# - What do we do with .h in case both .cpp and .h exists with