[PATCH] scripts: use ':Original:' tag to locate the origin file

2 views
Skip to first unread message

Cheng Ziqiu

unread,
Sep 13, 2024, 4:16:45 AM9/13/24
to Alex Shi, Yanteng Si, Jonathan Corbet, Dongliang Mu, linu...@vger.kernel.org, linux-...@vger.kernel.org, hust-os-ker...@googlegroups.com, Cheng Ziqiu
Simply substitute path may cause file finding failed
if we have a different dir map for translation. The
':Original:' tag could be used to locate the origin
file if both the tag and file exist.

Signed-off-by: Cheng Ziqiu <cheng...@hust.edu.cn>
---
scripts/checktransupdate.py | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/scripts/checktransupdate.py b/scripts/checktransupdate.py
index 578c3fecfdfd..f28176691b03 100755
--- a/scripts/checktransupdate.py
+++ b/scripts/checktransupdate.py
@@ -25,6 +25,7 @@ commit 42fb9cfd5b18 ("Documentation: dev-tools: Add link to RV docs")

import os
import time
+import re
import logging
from argparse import ArgumentParser, ArgumentTypeError, BooleanOptionalAction
from datetime import datetime
@@ -32,6 +33,18 @@ from datetime import datetime

def get_origin_path(file_path):
"""Get the origin path from the translation path"""
+ with open(file_path, "r") as f:
+ content = f.read()
+ # find the origin path in the content
+ match = re.search(r":Original:\s*(?::ref:`|:doc:`)?([^\s`]+)", content)
+ if match:
+ f = match.group(1)
+ if os.path.exists(f):
+ logging.debug("Origin tag found: %s", f)
+ return f
+ else:
+ logging.warning("Origin tag found but file not exists: %s", f)
+
paths = file_path.split("/")
tidx = paths.index("translations")
opaths = paths[:tidx]
--
2.34.1

Dongliang Mu

unread,
Sep 13, 2024, 7:23:56 AM9/13/24
to Cheng Ziqiu, Alex Shi, YanTeng Si, Jonathan Corbet, Dongliang Mu, linu...@vger.kernel.org, linux-...@vger.kernel.org, hust-os-ker...@googlegroups.com
On Fri, Sep 13, 2024 at 4:17 PM Cheng Ziqiu <cheng...@hust.edu.cn> wrote:
>
> Simply substitute path may cause file finding failed
> if we have a different dir map for translation. The
> ':Original:' tag could be used to locate the origin
> file if both the tag and file exist.

+cc yanteng's new email

Jonathan Corbet

unread,
Sep 13, 2024, 10:38:29 AM9/13/24
to Cheng Ziqiu, Alex Shi, Yanteng Si, Dongliang Mu, linu...@vger.kernel.org, linux-...@vger.kernel.org, hust-os-ker...@googlegroups.com, Cheng Ziqiu
Cheng Ziqiu <cheng...@hust.edu.cn> writes:

> Simply substitute path may cause file finding failed
> if we have a different dir map for translation. The
> ':Original:' tag could be used to locate the origin
> file if both the tag and file exist.
>
> Signed-off-by: Cheng Ziqiu <cheng...@hust.edu.cn>
> ---
> scripts/checktransupdate.py | 13 +++++++++++++
> 1 file changed, 13 insertions(+)

Perhaps we need this, but I would really rather move any files that
don't conform to the English-language directory structure. Having them
be anything but the same can only lead to this sort of confusion.

Thanks,

jon

Akira Yokosawa

unread,
Sep 13, 2024, 11:47:42 PM9/13/24
to cor...@lwn.net, al...@kernel.org, cheng...@hust.edu.cn, dz...@hust.edu.cn, hust-os-ker...@googlegroups.com, linu...@vger.kernel.org, linux-...@vger.kernel.org, siya...@loongson.cn, Vegard Nossum, Akira Yokosawa
[+CC: Vegard]

Hi,
+1

Furthermore, the "translations" extension for htmldocs available since
v6.8 at:
Documentation/sphinx/translations.py
assumes the same structure as the English one.

It might be nice for this script to warn about translation docs
whose positions don't match the assumption.

Thanks, Akira

>
> Thanks,
>
> jon

Reply all
Reply to author
Forward
0 new messages