aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorCristian Maureira-Fredes <Cristian.Maureira-Fredes@qt.io>2021-03-24 22:33:35 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-03-26 20:33:58 +0000
commita1392626572cc661b21b2bf622c4b381ce698d06 (patch)
tree6f7bd0bf8b57cafcb83dcb89fe7d5c0900bed091 /tools
parent1972fd80fe358967f500c9fa9941a40638e00f85 (diff)
doc: enable snippets translate tool
Create snippets directories in case they don't exist. Add "-q" option as the examples directory to keep the "--quiet" option from the build. Something to consider with this patch: Removing all the previous old snippets, which include not only 'cpp' files, but also '.h', '.qdoc', '.qrc', '.png', and '.qml', which might be used in the snippets, but will need to be updated in the generation tool, to not translate, and copy them over. Change-Id: Icbef9e1c93a12b90dbcfa990ef055ca6f8868407 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 9a4fb2eb72040aeadf6124ec1cad083859ac0787) Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/snippets_translate/main.py79
1 files changed, 53 insertions, 26 deletions
diff --git a/tools/snippets_translate/main.py b/tools/snippets_translate/main.py
index f2e723e70..c1267d22c 100644
--- a/tools/snippets_translate/main.py
+++ b/tools/snippets_translate/main.py
@@ -69,12 +69,14 @@ except ModuleNotFoundError:
extra = {}
log = logging.getLogger("snippets_translate")
+opt_quiet = False
# Filter and paths configuration
SKIP_END = (".pro", ".pri", ".cmake", ".qdoc", ".yaml", ".frag", ".qsb", ".vert", "CMakeLists.txt")
SKIP_BEGIN = ("changes-", ".")
-OUT_SNIPPETS = Path("sources/pyside6/doc/codesnippets/doc/src/snippets/")
-OUT_EXAMPLES = Path("sources/pyside6/doc/codesnippets/examples/")
+OUT_MAIN = Path("sources/pyside6/doc/codesnippets/")
+OUT_SNIPPETS = OUT_MAIN / "doc/src/snippets/"
+OUT_EXAMPLES = OUT_MAIN / "doc/codesnippets/examples/"
class FileStatus(Enum):
@@ -110,6 +112,13 @@ def get_parser():
)
parser.add_argument(
+ "-q",
+ "--quiet",
+ action="store_true",
+ help="Quiet"
+ )
+
+ parser.add_argument(
"-v",
"--verbose",
action="store_true",
@@ -145,14 +154,16 @@ def check_arguments(options):
# Notify 'write' option
if options.write_files:
- log.warning(
- f"Files will be copied from '{options.qt_dir}':\n" f"\tto '{options.pyside_dir}'"
- )
+ if not opt_quiet:
+ log.warning(
+ f"Files will be copied from '{options.qt_dir}':\n" f"\tto '{options.pyside_dir}'"
+ )
else:
msg = "This is a listing only, files are not being copied"
if have_rich:
msg = f"[green]{msg}[/green]"
- log.info(msg, extra=extra)
+ if not opt_quiet:
+ log.info(msg, extra=extra)
# Check 'qt_dir' and 'pyside_dir'
if is_directory(options.qt_dir) and is_directory(options.pyside_dir):
@@ -254,10 +265,12 @@ def translate_file(file_path, final_path, verbose, write):
if have_rich:
table.add_row(line, translated_line)
else:
- print(line, translated_line)
+ if not opt_quiet:
+ print(line, translated_line)
if verbose and have_rich:
- console.print(table)
+ if not opt_quiet:
+ console.print(table)
file_snippets.append("\n".join(translated_lines))
@@ -273,9 +286,11 @@ def translate_file(file_path, final_path, verbose, write):
# Rename to .py
written_file = shutil.move(str(final_path), str(final_path.with_suffix(".py")))
- log.info(f"Written: {written_file}")
+ if not opt_quiet:
+ log.info(f"Written: {written_file}")
else:
- log.warning("No snippets were found")
+ if not opt_quiet:
+ log.warning("No snippets were found")
@@ -303,13 +318,15 @@ def copy_file(file_path, py_path, category, category_path, write=False, verbose=
status = FileStatus.New
if verbose:
- log.info(f"From {file_path} to")
- log.info(f"==> {final_path}")
+ if not opt_quiet:
+ log.info(f"From {file_path} to")
+ log.info(f"==> {final_path}")
- if have_rich:
- log.info(f"{status_msg} {final_path}", extra={"markup": True})
- else:
- log.info(f"{status_msg:10s} {final_path}")
+ if not opt_quiet:
+ if have_rich:
+ log.info(f"{status_msg} {final_path}", extra={"markup": True})
+ 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
@@ -339,6 +356,13 @@ def process(options):
# (new, exists)
valid_new, valid_exists = 0, 0
+ # Creating directories in case they don't exist
+ if not OUT_SNIPPETS.is_dir():
+ OUT_SNIPPETS.mkdir(parents=True)
+
+ if not OUT_EXAMPLES.is_dir():
+ OUT_EXAMPLES.mkdir(parents=True)
+
if options.single_snippet:
f = Path(options.single_snippet)
if is_valid_file(f):
@@ -382,7 +406,8 @@ def process(options):
# Filter only Qt modules
if not module_name.startswith("qt"):
continue
- log.info(f"Module {module_name}")
+ if not opt_quiet:
+ log.info(f"Module {module_name}")
# Iterating everything
for f in i.glob("**/*.*"):
@@ -416,21 +441,23 @@ def process(options):
elif status == FileStatus.Exists:
valid_exists += 1
- log.info(
- dedent(
- f"""\
- Summary:
- Total valid files: {valid_new + valid_exists}
- New files: {valid_new}
- Existing files: {valid_exists}
- """
+ if not opt_quiet:
+ log.info(
+ dedent(
+ f"""\
+ Summary:
+ Total valid files: {valid_new + valid_exists}
+ New files: {valid_new}
+ Existing files: {valid_exists}
+ """
+ )
)
- )
if __name__ == "__main__":
parser = get_parser()
options = parser.parse_args()
+ opt_quiet = options.quiet
if not check_arguments(options):
parser.print_help()