openstack/generate-gitmodules.py
Andreas Jaeger 1d4a0daf51 Update for OpenDev change
Use new opendev URLs for generate-gitmodules.py.

Change-Id: I8bd2bc8aaf4c97dbcbdea69d115e825979b34366
2019-04-21 07:46:46 +02:00

69 lines
2.0 KiB
Python
Executable File

#!/usr/bin/python
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import requests
import yaml
TEMPLATE = """[submodule "%s"]
\tpath = %s
\turl = ../../%s.git
\tbranch = .
"""
# only return projects starting with openstack
CONFIG = ("https://opendev.org/openstack/governance/raw/reference/projects.yaml")
def find_integrated_gate_repos():
r = requests.get(CONFIG)
projects = yaml.safe_load(r.text)
repos = []
for project in projects.values():
for deliverable in project.get('deliverables', {}).values():
for repo in deliverable['repos']:
repos.append(repo)
return repos
def gen_gitmodules(projects):
path_template = "https://opendev.org/{project}"
short_projects = []
for project in projects:
short = os.path.basename(project)
short_projects.append(short)
path = path_template.format(project=project)
if not os.path.isdir(short):
os.system('git submodule add {path}'.format(path=path))
for existing in os.listdir('.'):
if not os.path.isdir(existing) or existing.startswith('.'):
continue
if existing not in short_projects:
os.system('git rm {existing}'.format(existing=existing))
projects = sorted(projects)
with open(".gitmodules", 'w') as f:
for p in projects:
ns, name = p.split('/')
f.write(TEMPLATE % (name, name, p))
def main():
repos = find_integrated_gate_repos()
gen_gitmodules(repos)
if __name__ == '__main__':
main()