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()