Monty Taylor | c0df8b0 | 2012-07-29 12:54:27 -0500 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | # Copyright (C) 2011 OpenStack, LLC. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | # Make local repos reads a project config file called projects.yaml |
| 17 | # It should look like: |
| 18 | |
| 19 | # - project: PROJECT_NAME |
| 20 | # options: |
| 21 | # - close-pull |
| 22 | # remote: https://gerrit.googlesource.com/gerrit |
| 23 | |
| 24 | # TODO: add support for |
| 25 | # ssh -p 29418 localhost gerrit -name create-project PROJECT |
| 26 | |
| 27 | import logging |
| 28 | import os |
| 29 | import subprocess |
| 30 | import sys |
| 31 | import shlex |
| 32 | import yaml |
| 33 | |
| 34 | def run_command(cmd, status=False, env={}): |
| 35 | cmd_list = shlex.split(str(cmd)) |
| 36 | newenv = os.environ |
| 37 | newenv.update(env) |
| 38 | p = subprocess.Popen(cmd_list, stdout=subprocess.PIPE, |
| 39 | stderr=subprocess.STDOUT, env=newenv) |
| 40 | (out, nothing) = p.communicate() |
| 41 | if status: |
| 42 | return (p.returncode, out.strip()) |
| 43 | return out.strip() |
| 44 | |
| 45 | |
| 46 | def run_command_status(cmd, env={}): |
| 47 | return run_command(cmd, True, env) |
| 48 | |
| 49 | |
| 50 | logging.basicConfig(level=logging.ERROR) |
| 51 | |
| 52 | REPO_ROOT = sys.argv[1] |
| 53 | PROJECTS_YAML = os.environ.get('PROJECTS_YAML', |
| 54 | '/home/gerrit2/projects.yaml') |
| 55 | |
| 56 | config = yaml.load(open(PROJECTS_YAML)) |
| 57 | |
| 58 | for section in config: |
| 59 | project = section['project'] |
| 60 | |
| 61 | project_git = "%s.git" % project |
| 62 | project_dir = os.path.join(REPO_ROOT, project_git) |
| 63 | |
| 64 | if os.path.exists(project_dir): |
| 65 | continue |
| 66 | |
| 67 | run_command("git --bare init --shared=group %s" % project_dir) |