diff options
Diffstat (limited to 'gitosis/run_hook.py')
-rw-r--r-- | gitosis/run_hook.py | 63 |
1 files changed, 41 insertions, 22 deletions
diff --git a/gitosis/run_hook.py b/gitosis/run_hook.py index e535e6a..ef12310 100644 --- a/gitosis/run_hook.py +++ b/gitosis/run_hook.py @@ -2,11 +2,9 @@ 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 @@ -15,15 +13,39 @@ from gitosis import gitdaemon from gitosis import app from gitosis import util -def post_update(cfg, git_dir): +def build_reposistory_data(config): + """ + Using the ``config`` data, perform all actions that affect files in the .git + repositories, such as the description, owner, and export marker. Also + update the projects.list file as needed to list relevant repositories. + + :type config: RawConfigParser + """ + gitweb.set_descriptions( + config=config, + ) + generated = util.getGeneratedFilesDir(config=config) + gitweb.generate_project_list( + config=config, + path=os.path.join(generated, 'projects.list'), + ) + gitdaemon.set_export_ok( + config=config, + ) + +def post_update(cfg, git_dir): #pragma: no cover + """ + post-update hook for the Gitosis admin directory. + + 1. Make an export of the admin repo to a clean directory. + 2. Move the gitosis.conf file to it's destination. + 3. Update the repository descriptions. + 4. Update the projects.list file. + 5. Update the repository export markers. + 6. Update the Gitosis SSH keys. + """ export = os.path.join(git_dir, 'gitosis-export') - try: - shutil.rmtree(export) - except OSError, e: - if e.errno == errno.ENOENT: - pass - else: - raise + util.rmtree(export) repository.export(git_dir=git_dir, path=export) os.rename( os.path.join(export, 'gitosis.conf'), @@ -31,17 +53,7 @@ def post_update(cfg, git_dir): ) # re-read config to get up-to-date settings cfg.read(os.path.join(export, '..', 'gitosis.conf')) - gitweb.set_descriptions( - config=cfg, - ) - generated = util.getGeneratedFilesDir(config=cfg) - gitweb.generate_project_list( - config=cfg, - path=os.path.join(generated, 'projects.list'), - ) - gitdaemon.set_export_ok( - config=cfg, - ) + build_reposistory_data(cfg) authorized_keys = util.getSSHAuthorizedKeysPath(config=cfg) ssh.writeAuthorizedKeys( path=authorized_keys, @@ -49,14 +61,21 @@ def post_update(cfg, git_dir): ) class Main(app.App): + """gitosis-run-hook program.""" + # W0613 - They also might ignore arguments here, where the descendant + # methods won't. + # pylint: disable-msg=W0613 + def create_parser(self): + """Declare the input for this program.""" 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): + def handle_args(self, parser, cfg, options, args): #pragma: no cover + """Parse the input for this program.""" try: (hook,) = args except ValueError: |