From f11b29dea326af9cf5e0e77272c05be64057a600 Mon Sep 17 00:00:00 2001 From: James Turk Date: Tue, 21 Feb 2012 19:24:58 -0500 Subject: [PATCH] scripts dir --- oyster/scripts/__init__.py | 0 oyster/scripts/signal.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 oyster/scripts/__init__.py create mode 100644 oyster/scripts/signal.py diff --git a/oyster/scripts/__init__.py b/oyster/scripts/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/oyster/scripts/signal.py b/oyster/scripts/signal.py new file mode 100644 index 0000000..7e0b1af --- /dev/null +++ b/oyster/scripts/signal.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +import argparse + +from oyster.core import kernel + +def main(): + parser = argparse.ArgumentParser( + description='do a task for all documents in a doc_class', + ) + + parser.add_argument('function', type=str, help='path to function to apply') + parser.add_argument('doc_class', type=str, + help='doc_class to apply function to') + + args = parser.parse_args() + + docs = kernel.db.tracked.find({'doc_class':args.doc_class}) + print '%s docs in %s' % (docs.count(), args.doc_class) + + path, func = args.function.rsplit('.',1) + mod = __import__(path, fromlist=[func]) + func = getattr(mod, func) + + for doc in docs: + func(doc, kernel.get_last_version(doc)) + # optionally save doc? + +if __name__ == '__main__': + main()