source: trunk/packages/invirt-dev/invirt-add-repo @ 3047

Last change on this file since 3047 was 3040, checked in by gdb, 14 years ago

Added script for creating new repositories

  • Property svn:executable set to *
File size: 1.3 KB
Line 
1#!/usr/bin/env python
2
3import optparse
4import os
5import shutil
6import sys
7
8from invirt import builder, common
9from invirt.config import structs as config
10
11REPO_BASE = '/srv/git/invirt'
12HOOK_BASE = '/usr/share/invirt-dev/git-hooks'
13
14def main():
15    parser = optparse.OptionParser('%prog repo <category> <name>')
16    opts, args = parser.parse_args()
17   
18    if len(args) != 3:
19        parser.print_help()
20        return 1
21
22    category = args[1]
23    name = args[2]
24    principal = os.environ['REMOTE_USER']
25    repo_path = os.path.join(REPO_BASE, category, '%s.git' % name)
26
27    if os.path.exists(repo_path):
28        print >>sys.stderr, '%s already exists!' % repo_path
29        return 1
30
31    print 'Creating new repo at %s' % repo_path
32    os.makedirs(repo_path)
33    common.captureOutput(['git', 'init', '--bare'], cwd=repo_path)
34    print 'Replacing hooks directory with a symlink'
35    hooks_dir = os.path.join(repo_path, 'hooks')
36    shutil.rmtree(hooks_dir)
37    common.captureOutput(['chown', '-R', 'git:', repo_path])
38    if category == 'packages':
39        os.symlink(os.path.join(HOOK_BASE, 'sub'), hooks_dir)
40    else:
41        os.symlink(os.path.join(HOOK_BASE, 'other'), hooks_dir)
42   
43    builder.runHook('post-add-repo', [category, name, principal])
44
45if __name__ == '__main__':
46    sys.exit(main())
Note: See TracBrowser for help on using the repository browser.