Add .noupgrade to skip upgrade of an instance
authorFrederic Massart <fred@moodle.com>
Wed, 20 Nov 2013 03:24:37 +0000 (11:24 +0800)
committerFrederic Massart <fred@moodle.com>
Wed, 20 Nov 2013 03:24:37 +0000 (11:24 +0800)
lib/commands/update.py
lib/commands/upgrade.py
lib/exceptions.py
lib/moodle.py

index 2e44755..7462633 100644 (file)
@@ -25,6 +25,7 @@ http://github.com/FMCorz/mdk
 import sys
 import logging
 from lib.command import Command
+from lib.exceptions import UpgradeNotAllowed
 
 
 class UpdateCommand(Command):
@@ -114,6 +115,9 @@ class UpdateCommand(Command):
                 if args.upgrade:
                     try:
                         M.upgrade()
+                    except UpgradeNotAllowed as e:
+                        logging.info('Skipping upgrade of %s (not allowed)' % (M.get('identifier')))
+                        logging.debug(e)
                     except Exception as e:
                         errors.append(M)
                         logging.warning('Error during the upgrade of %s' % M.get('identifier'))
index f3af29d..4684dae 100644 (file)
@@ -25,7 +25,7 @@ http://github.com/FMCorz/mdk
 import sys
 import logging
 from lib.command import Command
-
+from lib.exceptions import UpgradeNotAllowed
 
 class UpgradeCommand(Command):
 
@@ -115,6 +115,9 @@ class UpgradeCommand(Command):
 
             try:
                 M.upgrade(args.nocheckout)
+            except UpgradeNotAllowed as e:
+                logging.info('Skipping upgrade of %s (not allowed)' % (M.get('identifier')))
+                logging.debug(e)
             except Exception as e:
                 errors.append(M)
                 logging.warning('Error during the upgrade of %s' % M.get('identifier'))
index 997b86b..91cdeaa 100644 (file)
@@ -69,3 +69,7 @@ class ScriptNotFound(Exception):
 
 class UnsupportedScript(Exception):
     pass
+
+
+class UpgradeNotAllowed(Exception):
+    pass
index 2d8c8db..30a6bf0 100644 (file)
@@ -31,7 +31,7 @@ from tools import getMDLFromCommitMessage, mkdir, process, parseBranch
 from db import DB
 from config import Conf
 from git import Git, GitException
-from exceptions import InstallException
+from exceptions import InstallException, UpgradeNotAllowed
 from jira import Jira
 from scripts import Scripts
 
@@ -715,6 +715,8 @@ class Moodle(object):
             raise Exception('Cannot upgrade an instance which is not installed.')
         elif not self.branch_compare(20):
             raise Exception('Upgrade command line tool not supported by this version.')
+        elif os.path.isfile(os.path.join(self.get('path'), '.noupgrade')):
+            raise UpgradeNotAllowed('Upgrade not allowed, found .noupgrade.')
 
         # Checkout stable
         if not nocheckout: