aboutsummaryrefslogtreecommitdiffstats
path: root/python/fatcat_cleanup.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/fatcat_cleanup.py')
-rwxr-xr-xpython/fatcat_cleanup.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/python/fatcat_cleanup.py b/python/fatcat_cleanup.py
new file mode 100755
index 00000000..42887299
--- /dev/null
+++ b/python/fatcat_cleanup.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+
+import os, sys, argparse
+from fatcat_tools import authenticated_api
+from fatcat_tools.importers import JsonLinePusher
+from fatcat_tools.cleanups import *
+
+
+def run_files(args):
+ fmi = FileCleaner(args.api,
+ dry_run_mode=args.dry_run,
+ edit_batch_size=args.batch_size,
+ editgroup_description=args.editgroup_description_override)
+ JsonLinePusher(fmi, args.json_file).run()
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--host-url',
+ default="http://localhost:9411/v0",
+ help="connect to this host/port")
+ parser.add_argument('--batch-size',
+ help="size of batch to send",
+ default=50, type=int)
+ parser.add_argument('--editgroup-description-override',
+ help="editgroup description override",
+ default=None, type=str)
+ parser.add_argument('--dry-run',
+ help="dry-run mode (don't actually update)",
+ default=False, type=bool)
+ subparsers = parser.add_subparsers()
+
+ sub_files = subparsers.add_parser('files')
+ sub_files.set_defaults(
+ func=run_files,
+ auth_var="FATCAT_AUTH_WORKER_CLEANUP",
+ )
+ sub_files.add_argument('json_file',
+ help="files JSON file to import from",
+ default=sys.stdin, type=argparse.FileType('r'))
+
+ args = parser.parse_args()
+ if not args.__dict__.get("func"):
+ print("tell me what to do!")
+ sys.exit(-1)
+
+ # allow editgroup description override via env variable (but CLI arg takes
+ # precedence)
+ if not args.editgroup_description_override \
+ and os.environ.get('FATCAT_EDITGROUP_DESCRIPTION'):
+ args.editgroup_description_override = os.environ.get('FATCAT_EDITGROUP_DESCRIPTION')
+
+ args.api = authenticated_api(
+ args.host_url,
+ # token is an optional kwarg (can be empty string, None, etc)
+ token=os.environ.get(args.auth_var))
+ args.func(args)
+
+if __name__ == '__main__':
+ main()