From: Fred Date: Mon, 4 Mar 2013 04:11:41 +0000 (+0800) Subject: Update Command Object X-Git-Tag: v0.4~55 X-Git-Url: https://git.cameron1729.xyz/?a=commitdiff_plain;h=8550a5ec867c7c8d6f9c8e858123c2b156be611e;p=mdk.git Update Command Object --- diff --git a/lib/commands/__init__.py b/lib/commands/__init__.py index fc3c3df..92c4adb 100644 --- a/lib/commands/__init__.py +++ b/lib/commands/__init__.py @@ -39,3 +39,4 @@ from push import PushCommand from rebase import RebaseCommand from remove import RemoveCommand from run import RunCommand +from update import UpdateCommand diff --git a/lib/commands/update.py b/lib/commands/update.py new file mode 100644 index 0000000..4c174b3 --- /dev/null +++ b/lib/commands/update.py @@ -0,0 +1,142 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Moodle Development Kit + +Copyright (c) 2013 Frédéric Massart - FMCorz.net + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +http://github.com/FMCorz/mdk +""" + +import sys +from lib.command import Command +from lib.tools import debug + + +class UpdateCommand(Command): + + _arguments = [ + ( + ['-a', '--all'], + { + 'action': 'store_true', + 'dest': 'all', + 'help': 'update each instance' + } + ), + ( + ['-i', '--integration'], + { + 'action': 'store_true', + 'dest': 'integration', + 'help': 'update integration instances' + } + ), + ( + ['-s', '--stable'], + { + 'action': 'store_true', + 'dest': 'stable', + 'help': 'update stable instances' + } + ), + ( + ['-u', '--upgrade'], + { + 'action': 'store_true', + 'dest': 'upgrade', + 'help': 'upgrade the instance after successful update' + } + ), + ( + ['-c', '--update-cache'], + { + 'action': 'store_true', + 'dest': 'updatecache', + 'help': 'update the cached remotes. Useful when useCacheAsRemote is enabled.' + } + ), + ( + ['-p', '--proceed'], + { + 'action': 'store_true', + 'dest': 'process', + 'help': 'do not exit the process after updating the cache' + } + ), + ( + ['names'], + { + 'default': None, + 'help': 'name of the instances', + 'metavar': 'names', + 'nargs': '*' + } + ) + ] + _description = 'Update the instance from remote' + + def run(self, args): + + # Updating cache only + if args.updatecache: + debug('Updating cached remote') + self.Wp.updateCachedClones() + debug('Done.') + if not args.process: + return + debug('') + + # Updating instances + names = args.names + if args.all: + names = self.Wp.list() + elif args.integration or args.stable: + names = self.Wp.list(integration=args.integration, stable=args.stable) + + Mlist = self.Wp.resolveMultiple(names) + if len(Mlist) < 1: + raise Exception('No instances to work on. Exiting...') + + errors = [] + + for M in Mlist: + debug('Updating %s...' % M.get('identifier')) + try: + M.update() + except Exception as e: + errors.append(M) + debug('Error during the update of %s' % M.get('identifier')) + debug(e) + else: + if args.upgrade: + try: + M.upgrade() + except Exception as e: + errors.append(M) + debug('Error during the upgrade of %s' % M.get('identifier')) + pass + debug('') + debug('Done.') + + if errors and len(Mlist) > 1: + debug('') + debug('/!\ Some errors occurred on the following instances:') + for M in errors: + debug('- %s' % M.get('identifier')) + # Remove sys.exit and handle error code + sys.exit(1)