X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-dev.git/blobdiff_plain/4c34fc71dcfc20862723de8b62573ec2f8fbaf32..3e4e36646abc246c52b6001b2a04ab70c31060b5:/invirt-add-repo 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())