mirror of
https://github.com/sudoxnym/fdroiddata.git
synced 2026-04-14 19:46:54 +00:00
tools/rewrite-git-redirects.py: also handle srclibs
This commit is contained in:
parent
4e3860f278
commit
63f77186ce
1 changed files with 33 additions and 12 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue