8 from invirt import builder, common
9 from invirt.config import structs as config
11 REPO_BASE = '/srv/git/invirt'
12 HOOK_BASE = '/usr/share/invirt-dev/git-hooks'
15 parser = optparse.OptionParser('%prog repo <category> <name>')
16 opts, args = parser.parse_args()
24 principal = os.environ['REMOTE_USER']
25 repo_path = os.path.join(REPO_BASE, category, '%s.git' % name)
27 if os.path.exists(repo_path):
28 print >>sys.stderr, '%s already exists!' % repo_path
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)
41 os.symlink(os.path.join(HOOK_BASE, 'other'), hooks_dir)
43 builder.runHook('post-add-repo', [category, name, principal])
45 if __name__ == '__main__':