From 3c28f8b2ce8f129195b92d715f8855571563b51b Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Fri, 31 Aug 2012 14:53:14 +0800 Subject: [PATCH] Purge and run accept multiple instances as param --- moodle-purge.py | 32 ++++++++++++++++++++++++-------- moodle-run.py | 35 +++++++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/moodle-purge.py b/moodle-purge.py index da93498..27dfbf4 100755 --- a/moodle-purge.py +++ b/moodle-purge.py @@ -32,17 +32,33 @@ Wp = workplace.Workplace() # Arguments parser = argparse.ArgumentParser(description='Purge an instance cache') -parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance') +parser.add_argument('-a', '--all', action='store_true', help='runs the script on every instances', dest='all') +parser.add_argument('-i', '--integration', action='store_true', help='runs the script on the integration instances', dest='integration') +parser.add_argument('-s', '--stable', action='store_true', help='runs the script on the stable instances', dest='stable') +parser.add_argument('names', metavar='names', default=None, nargs='*', help='name of the instances') args = parser.parse_args() -M = Wp.resolve(args.name) -if not M: - debug('This is not a Moodle instance') +# Resolving instances +names = args.names +if args.all: + names = Wp.list() +elif args.integration or args.stable: + names = Wp.list(integration = args.integration, stable = args.stable) + +# Doing stuff +Mlist = Wp.resolveMultiple(names) +if len(Mlist) < 1: + debug('No instances to work on. Exiting...') sys.exit(1) -try: - M.cli('admin/cli/purge_caches.php', stderr=None, stdout=None) -except Exception as e: - debug(e) +for M in Mlist: + debug('Purging cache on %s' % (M.get('identifier'))) + try: + M.cli('admin/cli/purge_caches.php', stderr=None, stdout=None) + except Exception as e: + debug('Error while purging cache on %s' % M.get('identifier')) + debug(e) + else: + debug('') debug('Done.') diff --git a/moodle-run.py b/moodle-run.py index 1ede5df..5c98124 100755 --- a/moodle-run.py +++ b/moodle-run.py @@ -32,19 +32,34 @@ Wp = workplace.Workplace() # Arguments parser = argparse.ArgumentParser(description='Run a script on a Moodle instance') -parser.add_argument('script', metavar='script', help='the name of the script to run on the instance') -parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance') +parser.add_argument('-a', '--all', action='store_true', help='runs the script on every instances', dest='all') +parser.add_argument('-i', '--integration', action='store_true', help='runs the script on the integration instances', dest='integration') +parser.add_argument('-s', '--stable', action='store_true', help='runs the script on the stable instances', dest='stable') +parser.add_argument('script', metavar='script', help='the name of the script to run') +parser.add_argument('names', metavar='names', default=None, nargs='*', help='name of the instances') args = parser.parse_args() -M = Wp.resolve(args.name) -if not M: - debug('This is not a Moodle instance') +# Resolving instances +names = args.names +if args.all: + names = Wp.list() +elif args.integration or args.stable: + names = Wp.list(integration = args.integration, stable = args.stable) + +# Doing stuff +Mlist = Wp.resolveMultiple(names) +if len(Mlist) < 1: + debug('No instances to work on. Exiting...') sys.exit(1) -try: - debug('Running \'%s\' on \'%s\'' % (args.script, M.get('identifier'))) - M.runScript(args.script, stderr=None, stdout=None) -except Exception as e: - debug(e) +for M in Mlist: + debug('Running \'%s\' on \'%s\'' % (args.script, M.get('identifier'))) + try: + M.runScript(args.script, stderr=None, stdout=None) + except Exception as e: + debug('Error while running the script on %s' % M.get('identifier')) + debug(e) + else: + debug('') debug('Done.') -- 2.11.0