diff options
author | Tommi Virtanen <tv@eagain.net> | 2007-09-03 17:04:41 -0700 |
---|---|---|
committer | Tommi Virtanen <tv@eagain.net> | 2007-09-03 17:09:12 -0700 |
commit | 8a0654abe2db919b04683d40100b469e8c3adc4b (patch) | |
tree | 57903f32603cc57bd894c62ec2a0fa87d0985e15 /gitosis/serve.py | |
parent | Make setuptools include templates in the egg. (diff) | |
download | gitosis-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/serve.py')
-rw-r--r-- | gitosis/serve.py | 109 |
1 files changed, 44 insertions, 65 deletions
diff --git a/gitosis/serve.py b/gitosis/serve.py index f47fe23..4b7c6a7 100644 --- a/gitosis/serve.py +++ b/gitosis/serve.py @@ -6,29 +6,11 @@ prefix. Repository names are forced to match ALLOW_RE. import logging -import sys, os, optparse, re -from ConfigParser import RawConfigParser +import sys, os, re from gitosis import access from gitosis import repository - -def die(msg): - print >>sys.stderr, '%s: %s' % (sys.argv[0], msg) - sys.exit(1) - -def getParser(): - parser = optparse.OptionParser( - usage='%prog [--config=FILE] USER', - description='Allow restricted git operations under DIR', - ) - 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 ALLOW_RE = re.compile("^'(?P<path>[a-zA-Z0-9][a-zA-Z0-9@._-]*(/[a-zA-Z0-9][a-zA-Z0-9@._-]*)*)'$") @@ -124,48 +106,45 @@ def serve( ) return newcmd -def main(): - logging.basicConfig(level=logging.DEBUG) - log = logging.getLogger('gitosis.serve.main') - os.umask(0022) - - parser = getParser() - (options, args) = parser.parse_args() - try: - (user,) = args - except ValueError: - parser.error('Missing argument USER.') - - cmd = os.environ.get('SSH_ORIGINAL_COMMAND', None) - if cmd is None: - die("Need SSH_ORIGINAL_COMMAND in environment.") - - log.debug('Got command %(cmd)r' % dict( - cmd=cmd, - )) - - cfg = RawConfigParser() - try: - conffile = file(options.config) - except (IOError, OSError), e: - # I trust the exception has the path. - die("Unable to read config file: %s." % e) - try: - cfg.readfp(conffile) - finally: - conffile.close() - - os.chdir(os.path.expanduser('~')) - - try: - newcmd = serve( - cfg=cfg, - user=user, - command=cmd, - ) - except ServingError, e: - die(str(e)) - - log.debug('Serving %s', newcmd) - os.execvpe('git-shell', ['git-shell', '-c', newcmd], {}) - die("Cannot execute git-shell.") +class Main(app.App): + def create_parser(self): + parser = super(Main, self).create_parser() + parser.set_usage('%prog [OPTS] USER') + parser.set_description( + 'Allow restricted git operations under DIR') + return parser + + def handle_args(self, parser, cfg, options, args): + try: + (user,) = args + except ValueError: + parser.error('Missing argument USER.') + + log = logging.getLogger('gitosis.serve.main') + os.umask(0022) + + cmd = os.environ.get('SSH_ORIGINAL_COMMAND', None) + if cmd is None: + log.error('Need SSH_ORIGINAL_COMMAND in environment.') + sys.exit(1) + + log.debug('Got command %(cmd)r' % dict( + cmd=cmd, + )) + + os.chdir(os.path.expanduser('~')) + + try: + newcmd = serve( + cfg=cfg, + user=user, + command=cmd, + ) + except ServingError, e: + log.error('%s', e) + sys.exit(1) + + log.debug('Serving %s', newcmd) + os.execvpe('git-shell', ['git-shell', '-c', newcmd], {}) + log.error('Cannot execute git-shell.') + sys.exit(1) |