1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#!/usr/bin/env python
from xml.etree.cElementTree import (
ElementTree,
tostring,
)
import sys
rewrite_urls = {
# 'git://git.linaro.org': 'http://git.linaro.org/git-ro',
# 'git://git.linaro.org/': 'http://git.linaro.org/git-ro/',
# 'git://android.git.linaro.org': 'http://android.git.linaro.org/git-ro',
# 'git://android.git.linaro.org/': 'http://android.git.linaro.org/git-ro/',
'git://git.linaro.org': 'http://git.linaro.org/git',
'git://git.linaro.org/': 'http://git.linaro.org/git/',
'git://android.git.linaro.org': 'http://android.git.linaro.org/git',
'git://android.git.linaro.org/': 'http://android.git.linaro.org/git/',
}
def rewrite_git_urls(root):
"""Rewrites all android.git.linaro.org and git.linaro.org URLs.
Makes them use /git-ro and appends '.git' to repo names if they
do not already have it.
"""
remotes_to_handle = set([])
default_remote = root.find('default').get('remote', None)
for remote in root.findall("remote"):
if default_remote is None:
default_remote = remote.get('name')
remote_url = remote.get('fetch')
if remote_url in rewrite_urls:
remote.set('fetch', rewrite_urls[remote_url])
remotes_to_handle.add(remote.get('name'))
if default_remote in remotes_to_handle:
remotes_to_handle.remove(default_remote)
for project in root.findall("project"):
if (project.get('remote') in remotes_to_handle or
project.get('remote') is None and
default_remote in remotes_to_handle):
if not project.get('name').endswith('.git'):
project.set('name', project.get('name') + '.git')
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(
description=(
'Switch Linaro git URLs to scalable git URLs in repo manifest '
'files and print the result manifest on stdout.'))
parser.add_argument('manifest', type=str,
help='manifest file to process')
args = parser.parse_args()
# Parse the manifest file.
et = ElementTree()
doc = open(args.manifest)
root = et.parse(doc)
rewrite_git_urls(root)
print tostring(root, 'UTF-8').decode('utf-8')
|