Add create_cgitrepos.py file

The create_cgitrepos.py is used to generate a cgitrepos config file
from projects.yaml for cgit to use.

Change-Id: I54e09634f1cbb7595d7db629ce7e16a883c5f5b6
Reviewed-on: https://review.openstack.org/35856
Reviewed-by: James E. Blair <corvus@inaugust.com>
Approved: Clark Boylan <clark.boylan@gmail.com>
Reviewed-by: Clark Boylan <clark.boylan@gmail.com>
Tested-by: Jenkins
This commit is contained in:
Elizabeth Krumbach 2013-07-05 11:35:08 -07:00 committed by Jenkins
parent 66b6cc63a4
commit e8d897d329
2 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,58 @@
#! /usr/bin/env python
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
#
# 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.
#
# create_cgitrepos.py reads the project config file called projects.yaml
# and generates a cgitrepos configuration file which is then copied to
# the cgit server.
import os
import yaml
PROJECTS_YAML = os.environ.get('PROJECTS_YAML',
'/home/cgit/projects.yaml')
CGIT_REPOS = os.environ.get('CGIT_REPOS',
'/etc/cgitrepos')
REPO_PATH = os.environ.get('REPO_PATH',
'/var/lib/git')
def main():
(defaults, config) = tuple(yaml.safe_load_all(open(PROJECTS_YAML)))
gitorgs = {}
names = set()
for entry in config:
(org, name) = entry['project'].split('/')
description = entry.get('description', name)
assert name not in names
names.add(name)
gitorgs.setdefault(org, []).append((name, description))
with open(CGIT_REPOS, 'w') as cgit_file:
cgit_file.write('# Autogenerated by create_cgitrepos.py\n')
for org in sorted(gitorgs):
cgit_file.write('\n')
cgit_file.write('section=%s\n' % (org))
projects = gitorgs[org]
projects.sort()
for (name, description) in projects:
cgit_file.write('\n')
cgit_file.write('repo.url=%s/%s\n' % (org, name))
cgit_file.write('repo.path=%s/%s/%s.git/\n' % (REPO_PATH,
org, name))
cgit_file.write('repo.desc=%s\n' % (description))
if __name__ == "__main__":
main()

View File

@ -23,6 +23,7 @@ setup-hooks =
[entry_points]
console_scripts =
close-pull-requests = jeepyb.cmd.close_pull_requests:main
create-cgitrepos = jeepyb.cmd.create_cgitrepos:main
expire-old-reviews = jeepyb.cmd.expire_old_reviews:main
fetch-remotes = jeepyb.cmd.fetch_remotes:main
manage-projects = jeepyb.cmd.manage_projects:main