linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scripts: use ':Original:' tag to locate the origin file
@ 2024-09-13  8:16 Cheng Ziqiu
  2024-09-13 11:23 ` Dongliang Mu
  2024-09-13 14:38 ` Jonathan Corbet
  0 siblings, 2 replies; 4+ messages in thread
From: Cheng Ziqiu @ 2024-09-13  8:16 UTC (permalink / raw)
  To: Alex Shi, Yanteng Si, Jonathan Corbet
  Cc: Dongliang Mu, linux-doc, linux-kernel, hust-os-kernel-patches,
	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 <chengziqiu@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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] scripts: use ':Original:' tag to locate the origin file
  2024-09-13  8:16 [PATCH] scripts: use ':Original:' tag to locate the origin file Cheng Ziqiu
@ 2024-09-13 11:23 ` Dongliang Mu
  2024-09-13 14:38 ` Jonathan Corbet
  1 sibling, 0 replies; 4+ messages in thread
From: Dongliang Mu @ 2024-09-13 11:23 UTC (permalink / raw)
  To: Cheng Ziqiu
  Cc: Alex Shi, YanTeng Si, Jonathan Corbet, Dongliang Mu, linux-doc,
	linux-kernel, hust-os-kernel-patches

On Fri, Sep 13, 2024 at 4:17 PM Cheng Ziqiu <chengziqiu@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

>
> Signed-off-by: Cheng Ziqiu <chengziqiu@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
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scripts: use ':Original:' tag to locate the origin file
  2024-09-13  8:16 [PATCH] scripts: use ':Original:' tag to locate the origin file Cheng Ziqiu
  2024-09-13 11:23 ` Dongliang Mu
@ 2024-09-13 14:38 ` Jonathan Corbet
  2024-09-14  3:47   ` Akira Yokosawa
  1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Corbet @ 2024-09-13 14:38 UTC (permalink / raw)
  To: Cheng Ziqiu, Alex Shi, Yanteng Si
  Cc: Dongliang Mu, linux-doc, linux-kernel, hust-os-kernel-patches,
	Cheng Ziqiu

Cheng Ziqiu <chengziqiu@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 <chengziqiu@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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scripts: use ':Original:' tag to locate the origin file
  2024-09-13 14:38 ` Jonathan Corbet
@ 2024-09-14  3:47   ` Akira Yokosawa
  0 siblings, 0 replies; 4+ messages in thread
From: Akira Yokosawa @ 2024-09-14  3:47 UTC (permalink / raw)
  To: corbet
  Cc: alexs, chengziqiu, dzm91, hust-os-kernel-patches, linux-doc,
	linux-kernel, siyanteng, Vegard Nossum, Akira Yokosawa

[+CC: Vegard]

Hi,

On Fri, 13 Sep 2024 08:38:24 -0600, Jonathan Corbet wrote:
> Cheng Ziqiu <chengziqiu@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 <chengziqiu@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.

+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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-09-14  3:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-13  8:16 [PATCH] scripts: use ':Original:' tag to locate the origin file Cheng Ziqiu
2024-09-13 11:23 ` Dongliang Mu
2024-09-13 14:38 ` Jonathan Corbet
2024-09-14  3:47   ` Akira Yokosawa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).