diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2021-07-19 16:16:53 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2021-07-19 16:16:53 -0400 |
commit | 0cebec3a7f5fb640c3a71556fd0e7d7c4d6aeb71 (patch) | |
tree | a4d6775c73c3a59d5ff00b5ba293193b638fdf45 | |
parent | 07745fc8bfa2293dbb876a1458c73f5ac3cfda09 (diff) | |
download | grokmirror-0cebec3a7f5fb640c3a71556fd0e7d7c4d6aeb71.tar.gz |
Support reindexing and setting description
We may want to trigger a reindex without needing to run manual
public-inbox commands.
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r-- | grokmirror/pi_indexer.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/grokmirror/pi_indexer.py b/grokmirror/pi_indexer.py index 5d8e869..a543905 100644 --- a/grokmirror/pi_indexer.py +++ b/grokmirror/pi_indexer.py @@ -7,6 +7,7 @@ import logging import os import sys import re +import shutil import grokmirror @@ -88,6 +89,7 @@ def init_pi_inbox(inboxdir: str, opts) -> bool: ('url', local_url), ('indexlevel', opts.indexlevel), ] + description = None addresses = list() for line in origins.split('\n'): line = line.strip() @@ -100,6 +102,9 @@ def init_pi_inbox(inboxdir: str, opts) -> bool: if opt == 'address': addresses.append(val) continue + if opt == 'description': + description = val + continue if opt not in {'infourl', 'contact', 'listid', 'newsgroup'}: continue addopts.append((opt, val)) @@ -112,6 +117,8 @@ def init_pi_inbox(inboxdir: str, opts) -> bool: if not addresses: addresses = [f'{inboxname}@localhost'] + if not description: + description = f'{inboxname} mirror' if success: for opt, val in addopts: @@ -133,6 +140,10 @@ def init_pi_inbox(inboxdir: str, opts) -> bool: logger.critical('Unable to init public-inbox repo %s: %s', inboxdir, ex) success = False + if success: + with open(os.path.join(inboxdir, 'description', 'w')) as fh: + fh.write(description) + # Unlock all members for subrepo in pi_repos: grokmirror.unlock_repo(subrepo) @@ -174,6 +185,8 @@ def command(): help='URL of the origin toplevel serving config files') op.add_argument('--indexlevel', default='full', help='Indexlevel to use with public-inbox-init (full, medium, basic)') + op.add_argument('--force-init', dest='forceinit', action='store_true', default=False, + help='Force (re-)initialization of the repo passed as argument') op.add_argument('repo', nargs='?', help='Full path to foo/git/N.git public-inbox repository') @@ -190,7 +203,11 @@ def command(): # If we have a positional argument, then this is a post-update hook. We only # run the indexer if the inboxdir has already been initialized mode = 'update' - inboxdirs = get_inboxdirs([opts.repo]) + if not opts.repo.endswith('.git'): + # Assume we're working with toplevel inboxdir + inboxdirs = [opts.repo] + else: + inboxdirs = get_inboxdirs([opts.repo]) elif not sys.stdin.isatty(): # This looks like a post_clone_complete_hook invocation mode = 'clone' @@ -217,6 +234,17 @@ def command(): if not init_pi_inbox(inboxdir, opts): logger.critical('Could not init %s', inboxdir) continue + elif opts.forceinit and mode == 'update': + # Delete msgmap and xap15 if present and reinitialize + if os.path.exists(msgmapdbf): + logger.critical('Reinitializing %s', inboxdir) + os.unlink(msgmapdbf) + if os.path.exists(os.path.join(inboxdir, 'xap15')): + shutil.rmtree(os.path.join(inboxdir, 'xap15')) + if not init_pi_inbox(inboxdir, opts): + logger.critical('Could not init %s', inboxdir) + continue + logger.info('Indexing %s', inboxdir) if not index_pi_inbox(inboxdir, opts): logger.critical('Unable to index %s', inboxdir) |