From e8d897d329f6def7c231d48cebf4079ea0d4bfb4 Mon Sep 17 00:00:00 2001 From: Elizabeth Krumbach Date: Fri, 5 Jul 2013 11:35:08 -0700 Subject: [PATCH] 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 Approved: Clark Boylan Reviewed-by: Clark Boylan Tested-by: Jenkins --- jeepyb/cmd/create_cgitrepos.py | 58 ++++++++++++++++++++++++++++++++++ setup.cfg | 1 + 2 files changed, 59 insertions(+) create mode 100644 jeepyb/cmd/create_cgitrepos.py diff --git a/jeepyb/cmd/create_cgitrepos.py b/jeepyb/cmd/create_cgitrepos.py new file mode 100644 index 0000000..d8da88b --- /dev/null +++ b/jeepyb/cmd/create_cgitrepos.py @@ -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() diff --git a/setup.cfg b/setup.cfg index ef88ce8..4673363 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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