diff --git a/tools/rewrite-git-redirects.py b/tools/rewrite-git-redirects.py index de0d06d73b..ff623c1318 100755 --- a/tools/rewrite-git-redirects.py +++ b/tools/rewrite-git-redirects.py @@ -13,6 +13,9 @@ import sys import yaml +REPO_PATTERN = re.compile(r'Repo: .*') + + def is_git_redirect(url): """Check if git is served a redirect""" host = url.split('/')[2] @@ -33,15 +36,7 @@ def is_git_redirect(url): return p.returncode != 0 -os.chdir(os.path.dirname(__file__) + '/../') - -if len(sys.argv) > 1: - files = ['metadata/%s.yml' % f for f in sys.argv[1:]] -else: - files = sorted(glob.glob('metadata/*.yml')) - -pattern = re.compile(r'Repo: .*') -for f in files: +def scan_app_file(f, include_srclibs=True): with open(f) as fp: data = yaml.safe_load(fp) repo_url = data.get('Repo', '').strip() @@ -50,10 +45,19 @@ for f in files: or data.get('RepoType') != 'git' or data.get('ArchivePolicy') == '0 versions' ): - continue + return + + if include_srclibs: + srclibs_to_scan = set() + for build in data.get('Builds', []): + for srclib in build.get('srclibs', []): + srclibf = 'srclibs/%s.yml' % srclib.split('@')[0] + srclibs_to_scan.add(srclibf) + for srclib in srclibs_to_scan: + scan_app_file(srclib) if not is_git_redirect(repo_url): - continue + return new_url = None for url in [ @@ -69,4 +73,21 @@ for f in files: with open(f) as fp: raw = fp.read() with open(f, 'w') as fp: - fp.write(pattern.sub('Repo: ' + new_url, raw)) + fp.write(REPO_PATTERN.sub('Repo: ' + new_url, raw)) + + +def main(): + os.chdir(os.path.dirname(__file__) + '/../') + + if len(sys.argv) > 1: + files = ['metadata/%s.yml' % f for f in sys.argv[1:]] + include_srclibs = True + else: + files = sorted(glob.glob('metadata/*.yml') + glob.glob('srclibs/*.yml')) + include_srclibs = False + + for f in files: + scan_app_file(f, include_srclibs) + +if __name__ == "__main__": + main()