Skip to content

Commit

Permalink
Prefer autocommand to argparse.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Apr 25, 2024
1 parent bc238ee commit c186a1d
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions jaraco/mongodb/repair-gridfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
- Removing files with missing chunks.
"""

import argparse
import logging
import sys

import autocommand
import gridfs
from more_itertools.recipes import consume

Expand All @@ -19,12 +19,6 @@
log = logging.getLogger()


def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('db', type=helper.connect_gridfs)
return parser.parse_args()


class FileRepair:
def __init__(self, gfs):
self.gfs = gfs
Expand Down Expand Up @@ -61,15 +55,11 @@ def handle_trap(self, trap):
self.gfs.delete(spec)


def run():
@autocommand.autocommand(__name__)
def run(db: helper.connect_gridfs): # type: ignore
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
args = get_args()

repair = FileRepair(args.db)
repair = FileRepair(db)
counter = repair.run()

log.info("Removed %s corrupt files.", counter.count)


if __name__ == '__main__':
run()

0 comments on commit c186a1d

Please sign in to comment.