1f3924e2cb
This avoids complexity where failing to read the config file in gitosis-run-hook is non-fatal, but only on the first run. gitosis-init will take care of config file reading and just pass a RawConfigParser instance to run_hook.post_update.
67 lines
1.7 KiB
Python
67 lines
1.7 KiB
Python
"""
|
|
Perform gitosis actions for a git hook.
|
|
"""
|
|
|
|
import errno
|
|
import logging
|
|
import os
|
|
import sys
|
|
import shutil
|
|
|
|
from gitosis import repository
|
|
from gitosis import ssh
|
|
from gitosis import gitweb
|
|
from gitosis import app
|
|
|
|
def post_update(cfg, git_dir):
|
|
export = os.path.join(git_dir, 'gitosis-export')
|
|
try:
|
|
shutil.rmtree(export)
|
|
except OSError, e:
|
|
if e.errno == errno.ENOENT:
|
|
pass
|
|
else:
|
|
raise
|
|
repository.export(git_dir=git_dir, path=export)
|
|
os.rename(
|
|
os.path.join(export, 'gitosis.conf'),
|
|
os.path.join(export, '..', 'gitosis.conf'),
|
|
)
|
|
gitweb.generate(
|
|
config=cfg,
|
|
path=os.path.join(git_dir, 'projects.list'),
|
|
)
|
|
ssh.writeAuthorizedKeys(
|
|
path=os.path.expanduser('~/.ssh/authorized_keys'),
|
|
keydir=os.path.join(export, 'keydir'),
|
|
)
|
|
|
|
class Main(app.App):
|
|
def create_parser(self):
|
|
parser = super(Main, self).create_parser()
|
|
parser.set_usage('%prog [OPTS] HOOK')
|
|
parser.set_description(
|
|
'Perform gitosis actions for a git hook')
|
|
return parser
|
|
|
|
def handle_args(self, parser, cfg, options, args):
|
|
try:
|
|
(hook,) = args
|
|
except ValueError:
|
|
parser.error('Missing argument HOOK.')
|
|
|
|
log = logging.getLogger('gitosis.run_hook')
|
|
os.umask(0022)
|
|
|
|
git_dir = os.environ.get('GIT_DIR')
|
|
if git_dir is None:
|
|
log.error('Must have GIT_DIR set in enviroment')
|
|
sys.exit(1)
|
|
|
|
if hook == 'post-update':
|
|
log.info('Running hook %s', hook)
|
|
post_update(cfg, git_dir)
|
|
log.info('Done.')
|
|
else:
|
|
log.warning('Ignoring unknown hook: %r', hook)
|