aboutsummaryrefslogtreecommitdiff
path: root/gitosis/run_hook.py
diff options
context:
space:
mode:
authorTommi Virtanen <tv@eagain.net>2007-09-03 17:04:41 -0700
committerTommi Virtanen <tv@eagain.net>2007-09-03 17:09:12 -0700
commit8a0654abe2db919b04683d40100b469e8c3adc4b (patch)
tree57903f32603cc57bd894c62ec2a0fa87d0985e15 /gitosis/run_hook.py
parentMake setuptools include templates in the egg. (diff)
downloadgitosis-dakkar-8a0654abe2db919b04683d40100b469e8c3adc4b.tar.gz
gitosis-dakkar-8a0654abe2db919b04683d40100b469e8c3adc4b.tar.bz2
gitosis-dakkar-8a0654abe2db919b04683d40100b469e8c3adc4b.zip
Refactor command line utilities to share setup.
Hide internal gitosis-ssh and gitosis-gitweb, it's all in gitosis-run-hook.
Diffstat (limited to 'gitosis/run_hook.py')
-rw-r--r--gitosis/run_hook.py90
1 files changed, 29 insertions, 61 deletions
diff --git a/gitosis/run_hook.py b/gitosis/run_hook.py
index 2bc4aaa..de5076e 100644
--- a/gitosis/run_hook.py
+++ b/gitosis/run_hook.py
@@ -4,36 +4,14 @@ Perform gitosis actions for a git hook.
import errno
import logging
-import optparse
import os
import sys
import shutil
-from ConfigParser import RawConfigParser
-
from gitosis import repository
from gitosis import ssh
from gitosis import gitweb
-
-log = logging.getLogger('gitosis.run_hook')
-
-def die(msg):
- log.error(msg)
- sys.exit(1)
-
-def getParser():
- parser = optparse.OptionParser(
- usage='%prog HOOK',
- description='Perform gitosis actions for a git hook',
- )
- parser.set_defaults(
- config=os.path.expanduser('~/.gitosis.conf'),
- )
- parser.add_option('--config',
- metavar='FILE',
- help='read config from FILE',
- )
- return parser
+from gitosis import app
def post_update(cfg):
try:
@@ -51,43 +29,33 @@ def post_update(cfg):
keydir='gitosis-export/keydir',
)
-def main():
- logging.basicConfig(level=logging.INFO)
- os.umask(0022)
-
- parser = getParser()
- (options, args) = parser.parse_args()
- try:
- (hook,) = args
- except ValueError:
- parser.error('Missing argument HOOK.')
+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
- cfg = RawConfigParser()
- try:
- conffile = file(options.config)
- except (IOError, OSError), e:
- if e.errno == errno.ENOENT:
- # not existing is ok
- pass
- else:
- # I trust the exception has the path.
- die("Unable to read config file: %s." % e)
- else:
+ def handle_args(self, parser, cfg, options, args):
try:
- cfg.readfp(conffile)
- finally:
- conffile.close()
-
- git_dir = os.environ.get('GIT_DIR')
- if git_dir is None:
- die('Must have GIT_DIR set in enviroment.')
- os.chdir(git_dir)
- os.environ['GIT_DIR'] = '.'
-
- if hook == 'post-update':
- log.info('Running hook %s', hook)
- post_update(cfg)
- log.info('Done.')
- else:
- log.warning('Ignoring unknown hook: %r', hook)
- return 0
+ (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)
+ os.chdir(git_dir)
+ os.environ['GIT_DIR'] = '.'
+
+ if hook == 'post-update':
+ log.info('Running hook %s', hook)
+ post_update(cfg)
+ log.info('Done.')
+ else:
+ log.warning('Ignoring unknown hook: %r', hook)