From: Greg Brockman Date: Tue, 6 Jul 2010 04:28:10 +0000 (-0400) Subject: Added script for creating new repositories X-Git-Tag: 0.1.5~12 X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-dev.git/commitdiff_plain/3e4e36646abc246c52b6001b2a04ab70c31060b5 Added script for creating new repositories svn path=/trunk/packages/invirt-dev/; revision=3040 --- diff --git a/build-hooks/post-add-repo b/build-hooks/post-add-repo new file mode 100755 index 0000000..d86bb20 --- /dev/null +++ b/build-hooks/post-add-repo @@ -0,0 +1,26 @@ +#!/bin/sh + +set -e +set -u + +escape() { + echo "$1" | sed -e 's/@/@@/g' +} + +category=$(escape "$1") +name=$(escape "$2") +principal=$(escape "$3") + +base=build.hooks.post_add_repo.zephyr +class=$(invirt-getconf "$base.class" 2>/dev/null || :) +instance=$(invirt-getconf "$base.instance" 2>/dev/null || :) +zsig=$(invirt-getconf "$base.zsig" 2>/dev/null || :) + +if [ -z "$class" ]; then + echo "I don't know where to send a commit zephyr!" >&2 + echo "Please provide a value for $base.class in" >&2 + echo "your invirt config file." >&2 + exit 1 +fi + +(echo "$principal just created a new repository, $category/$name.git") | zwrite -c "$class" -i "${instance:-add-repo}" -s "${zsig:-Make a new repo}" -d diff --git a/invirt-add-repo b/invirt-add-repo new file mode 100755 index 0000000..bb48b49 --- /dev/null +++ b/invirt-add-repo @@ -0,0 +1,46 @@ +#!/usr/bin/env python + +import optparse +import os +import shutil +import sys + +from invirt import builder, common +from invirt.config import structs as config + +REPO_BASE = '/srv/git/invirt' +HOOK_BASE = '/usr/share/invirt-dev/git-hooks' + +def main(): + parser = optparse.OptionParser('%prog repo ') + opts, args = parser.parse_args() + + if len(args) != 3: + parser.print_help() + return 1 + + category = args[1] + name = args[2] + principal = os.environ['REMOTE_USER'] + repo_path = os.path.join(REPO_BASE, category, '%s.git' % name) + + if os.path.exists(repo_path): + print >>sys.stderr, '%s already exists!' % repo_path + return 1 + + print 'Creating new repo at %s' % repo_path + os.makedirs(repo_path) + common.captureOutput(['git', 'init', '--bare'], cwd=repo_path) + print 'Replacing hooks directory with a symlink' + hooks_dir = os.path.join(repo_path, 'hooks') + shutil.rmtree(hooks_dir) + common.captureOutput(['chown', '-R', 'git:', repo_path]) + if category == 'packages': + os.symlink(os.path.join(HOOK_BASE, 'sub'), hooks_dir) + else: + os.symlink(os.path.join(HOOK_BASE, 'other'), hooks_dir) + + builder.runHook('post-add-repo', [category, name, principal]) + +if __name__ == '__main__': + sys.exit(main()) diff --git a/invirt-build-conf b/invirt-build-conf index 2966427..1acbc9d 100755 --- a/invirt-build-conf +++ b/invirt-build-conf @@ -53,11 +53,12 @@ def main(): for pocket in config.build.pockets: print >>f, 'build %s %s %s' % (pocket, build_handler, acl_path(pocket)) - os.rename(conf_name, '/etc/remctl/conf.d/build') + with atomic_write('/etc/remctl/acl/repo_admin') as f: + acl = authz.expandAdmin(config.build.repo_admin, None) + print >>f, '\n'.join(userToPrinc(a) for a in acl) - k5login_fd, k5login_name = tempfile.mkstemp() - k5login = os.fdopen(k5login_fd, 'r+') - print >>k5login, '\n'.join(all_devs) + with atomic_write('/etc/remctl/conf.d/repo_admin') as f: + print >>f, 'create repo /usr/bin/invirt-add-repo /etc/remctl/acl/repo_admin' with atomic_write(os.path.join(builder._REPO_DIR, '.k5login')) as f: print >>f, '\n'.join(all_devs) diff --git a/setup.py b/setup.py index 67d9d3e..ebdc435 100755 --- a/setup.py +++ b/setup.py @@ -21,5 +21,5 @@ setup( py_modules = ['invirt.builder'], package_dir = {'': 'python'}, - scripts = ['invirtibuilder', 'invirt-build-conf', 'invirt-submit-build'] + scripts = ['invirtibuilder', 'invirt-build-conf', 'invirt-submit-build', 'invirt-add-repo'] )