qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Cleber Rosa" <crosa@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"John Snow" <jsnow@redhat.com>
Subject: [RFC PATCH 5/9] scripts/get_maintainer.py: resolve the source path
Date: Thu, 11 Dec 2025 18:01:28 +0000	[thread overview]
Message-ID: <20251211180132.3186564-6-alex.bennee@linaro.org> (raw)
In-Reply-To: <20251211180132.3186564-1-alex.bennee@linaro.org>

We will need this to automagically find MAINTAINERS. Use the same
logic as the perl script by looking for expected files and
directories.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 scripts/get_maintainer.py | 77 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git a/scripts/get_maintainer.py b/scripts/get_maintainer.py
index 2b8fc7ae9ee..c713f290cc7 100755
--- a/scripts/get_maintainer.py
+++ b/scripts/get_maintainer.py
@@ -15,6 +15,59 @@
 from pathlib import Path
 
 
+#
+# Helper functions for dealing with the source path
+#
+
+def is_qemu_src_root(directory):
+    """
+    Checks if the given path appears to be the root of a QEMU source tree,
+    based on the presence of key files and directories.
+    """
+    if not path.isdir(directory):
+        return False
+
+    required_files = ['COPYING', 'MAINTAINERS', 'Makefile', 'VERSION']
+    required_dirs = ['docs', 'linux-user', 'system']
+
+    for f in required_files:
+        if not path.isfile(path.join(directory, f)):
+            return False
+    for d in required_dirs:
+        if not path.isdir(path.join(directory, d)):
+            return False
+    return True
+
+
+def find_src_root():
+    """
+    Walks up the directory tree from the script's location
+    to find the QEMU source root.
+    Returns the absolute path of the root directory if found, or None.
+    """
+    script_dir = path.dirname(path.abspath(__file__))
+    current_dir = script_dir
+
+    while True:
+        if is_qemu_src_root(current_dir):
+            return current_dir
+
+        # Move up to the parent directory
+        parent_dir = path.dirname(current_dir)
+
+        # If we reached the filesystem root and haven't found it, stop
+        if parent_dir == current_dir:
+            break
+
+        current_dir = parent_dir
+
+    return None
+
+#
+# Argument validation
+#
+
+
 def valid_file_path(arg):
     """
     Checks if arg exists and is a regular file or raises ArgumentTypeError.
@@ -26,7 +79,21 @@ def valid_file_path(arg):
     return Path(path.abspath(arg))
 
 
+def valid_src_root(arg):
+    """
+    Checks if arg is a valid QEMU source root or raise ArgumentTypeError.
+    """
+    abs_path = path.abspath(arg)
+    if not is_qemu_src_root(abs_path):
+        raise ArgumentTypeError(f"Path '{arg}' is not a valid QEMU source tree")
+    return abs_path
+
+
 def main():
+    """
+    Main entry point for the script.
+    """
+
     parser = ArgumentParser(description='Extract maintainer information. ')
 
     # We can either specify patches or an individual file
@@ -36,6 +103,16 @@ def main():
     group.add_argument('-f', '--file', type=valid_file_path,
                        help='path to source file')
 
+    # We need to know or be told where the root of the source tree is
+    src = find_src_root()
+
+    if src is None:
+        parser.add_argument('--src', type=valid_src_root, required=True,
+                            help='Root of QEMU source tree')
+    else:
+        parser.add_argument('--src', type=valid_src_root, default=src,
+                            help=f'Root of QEMU source tree (default: {src})')
+
     args = parser.parse_args()
 
 
-- 
2.47.3



  parent reply	other threads:[~2025-12-11 18:03 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-11 18:01 [RFC PATCH 0/9] for 11.0 conversion* of get_maintainers.pl to python Alex Bennée
2025-12-11 18:01 ` [RFC PATCH 1/9] MAINTAINERS: fix missing names Alex Bennée
2025-12-11 18:01 ` [RFC PATCH 2/9] MAINTAINERS: fix libvirt entry Alex Bennée
2025-12-12  6:45   ` Philippe Mathieu-Daudé
2025-12-12 11:00     ` Alex Bennée
2025-12-12 11:12       ` Ján Tomko
2025-12-11 18:01 ` [RFC PATCH 3/9] MAINTAINERS: regularise the status fields Alex Bennée
2025-12-12  6:43   ` Philippe Mathieu-Daudé
2025-12-11 18:01 ` [RFC PATCH 4/9] scripts/get_maintainer.py: minimal argument parsing Alex Bennée
2025-12-11 18:01 ` Alex Bennée [this message]
2025-12-11 18:01 ` [RFC PATCH 6/9] scripts/get_maintainer.py: initial parsing of MAINTAINERS Alex Bennée
2025-12-11 18:01 ` [RFC PATCH 7/9] scripts/get_maintainer.py: add support for -f Alex Bennée
2025-12-11 18:01 ` [RFC PATCH 8/9] scripts/get_maintainer.py: add support reading patch files Alex Bennée
2025-12-11 18:01 ` [RFC PATCH 9/9] gitlab: add a check-maintainers task Alex Bennée
2025-12-12  8:15 ` [RFC PATCH 0/9] for 11.0 conversion* of get_maintainers.pl to python Daniel P. Berrangé
2025-12-12 11:00   ` Alex Bennée
2025-12-12 11:25     ` Peter Maydell
2025-12-12 11:27 ` Peter Maydell
2025-12-12 14:38 ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251211180132.3186564-6-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=crosa@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).