From c4aba82aeadb17183f09a1415a2dbaead7a9d8a0 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Tue, 15 Jun 2021 12:35:13 +0200 Subject: Add API Change Review wrapper script This is a wrapper script that parses .gitmodules of a qt5 checkout and figures out which version it should be compared to. It then generates a change review for each module and asks if it should be uploaded. It acts as a replacement for all-api-modules which also handles the steps of checking out repos and the otherwise manual git steps. Change-Id: If2035fe70159d33fad7f5f6375f5ef1ca5e6a8ea Reviewed-by: Edward Welbourne --- scripts/api-review/fullrun/gitfunctions.py | 82 ++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 scripts/api-review/fullrun/gitfunctions.py (limited to 'scripts/api-review/fullrun/gitfunctions.py') diff --git a/scripts/api-review/fullrun/gitfunctions.py b/scripts/api-review/fullrun/gitfunctions.py new file mode 100644 index 0000000..73adfb2 --- /dev/null +++ b/scripts/api-review/fullrun/gitfunctions.py @@ -0,0 +1,82 @@ +############################################################################# +## +## Copyright (C) 2021 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## + +import os +import subprocess + +# get the current branch of git repo +def get_branch(git_repo : str = '.') -> str: + cwd = os.getcwd() + + os.chdir(git_repo) + + cmd = 'git rev-parse --abbrev-ref HEAD'.split(' ') + completed_process = subprocess.run(cmd, capture_output=True) + output = completed_process.stdout.decode('utf-8').strip() + + #print(output) + + os.chdir(cwd) + + return output + +# Gets a list of submodules from given git repo path and optionally, branch +# Where each module is represented by a dict +def get_submodules(git_repo : str = '.', branch : str = 'current') -> {}: + cwd = os.getcwd() + + os.chdir(git_repo) + current_branch = get_branch() + + if branch != 'current': + os.system(f'git checkout {branch}') + + modules = {} + + modules_path = '.gitmodules' + + if not os.path.exists(modules_path): + print(f'Error: {modules_path} not found') + return modules + + modules_file = open(modules_path, 'r') + + read_state = 0 + current_module = {} + + for line in modules_file: + if line.startswith('[submodule'): + if 'name' in current_module: + modules[current_module['name']] = current_module + + read_state = 1 + module_name = line.split(' ')[1].replace('"', '').replace(']', '').strip() + + current_module = {'name': module_name} + elif read_state == 1: + if '=' in line: + elements = line.split('=') + key = elements[0].strip() + value = elements[1].strip() + + current_module[key] = value + + if branch != 'current': + os.system(f'git checkout {current_branch}') + + os.chdir(cwd) + + return modules + +# Returns a list of active submodules for the given repo and branch +def get_active_submodules(git_repo : str = '.', branch : str = 'current') -> []: + modules = [] + + for module_name, module in get_submodules(git_repo, branch).items(): + if module['status'] != 'ignore': + modules.append(module_name) + + return modules -- cgit v1.2.1