From: Fred Date: Wed, 1 Aug 2012 15:01:27 +0000 (+0800) Subject: Moodle info supports list argument X-Git-Tag: v0.1~88 X-Git-Url: https://git.cameron1729.xyz/?a=commitdiff_plain;h=d1fcddcbaaf5e2db6133790d511757dc077e1f2b;p=mdk.git Moodle info supports list argument --- diff --git a/moodle-fix.py b/moodle-fix.py old mode 100644 new mode 100755 diff --git a/moodle-info.py b/moodle-info.py old mode 100644 new mode 100755 index 89eef93..648d39b --- a/moodle-info.py +++ b/moodle-info.py @@ -7,25 +7,40 @@ from lib import config, workplace, moodle, tools from lib.tools import debug C = config.Conf().get +Wp = workplace.Workplace() # Arguments -parser = argparse.ArgumentParser(description='Shows information about a Moodle instance') +parser = argparse.ArgumentParser(description='Display information about a Moodle instance') +parser.add_argument('-l', '--list', action='store_true', help='list the instances', dest='list') parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance') +parser.add_argument('var', metavar='var', default=None, nargs='?', help='variable to output') args = parser.parse_args() +# List the instances +if args.list: + l = Wp.list() + for i in l: + M = Wp.get(i) + print '{0:<25}'.format(i), M.get('release') + # Loading instance -try: - if args.name != None: - Wp = workplace.Workplace() - M = Wp.get(args.name) - else: - M = moodle.Moodle(os.getcwd()) - if not M: - raise Exception() -except Exception: - debug('This is not a Moodle instance') - sys.exit(1) +else: + try: + if args.name != None: + M = Wp.get(args.name) + else: + M = moodle.Moodle(os.getcwd()) + if not M: + raise Exception() + except Exception: + debug('This is not a Moodle instance') + sys.exit(1) -# Printing info -for key, info in M.info().items(): - print '%s: %s' % (key, info) + # Printing variable + if args.var != None: + print M.get(args.var) + + # Printing info + else: + for key, info in M.info().items(): + print '{0:<20}: {1}'.format(key, info) diff --git a/moodle-phpunit.py b/moodle-phpunit.py old mode 100644 new mode 100755 diff --git a/moodle-remove.py b/moodle-remove.py old mode 100644 new mode 100755