Changes to instance naming: master
authorCameron Ball <cameron@moodle.com>
Wed, 24 Aug 2016 05:24:41 +0000 (13:24 +0800)
committerCameron Ball <cameron@moodle.com>
Wed, 24 Aug 2016 05:39:03 +0000 (13:39 +0800)
* Engine is now appended to instance name (wording.appendEngine)
* Parts of the instance name can be used in forcedCfg. For example
on an instance called stable-master-pgsql %instancename:1% is replaced
with 'master'
* New flag 'purpose' replaces 'integration'. Purpose can be 'integration',
'stable' or 'review'. Instance names reflect this.
* A type of instance can be specified to `mdk backport` (i.e., 'integration',
'review' or 'stable'. If none is given the type of the current instance is
used.

mdk/commands/backport.py
mdk/commands/create.py
mdk/moodle.py
mdk/workplace.py

index e3b36b0..010dca3 100644 (file)
@@ -51,10 +51,13 @@ class BackportCommand(Command):
                 }
             ),
             (
-                ['-i', '--integration'],
+                ['--backport-to'],
                 {
-                    'action': 'store_true',
-                    'help': 'backport to integration instances'
+                    'action': 'store',
+                    'choices': ['integration', 'review', 'stable'],
+                    'default': 'stable',
+                    'help': 'which instances to backport to',
+                    'metavar': 'instances'
                 }
             ),
             (
@@ -115,7 +118,7 @@ class BackportCommand(Command):
         M = None
         branch = args.branch
         versions = args.versions
-        integration = args.integration
+        backportto = args.backport_to
 
         # If we don't have a branch, we need an instance
         M = self.Wp.resolve(args.name)
@@ -147,7 +150,14 @@ class BackportCommand(Command):
 
         # Integration?
         if M:
-            integration = M.isIntegration()
+            if M.isIntegration():
+                backportto = 'integration'
+
+            if M.isStable():
+                backportto = 'stable'
+
+            if M.isReview():
+                backportto = 'review'
 
         def stashPop(stash):
             """Small helper to pop the stash has we have to do it in some different places"""
@@ -162,7 +172,7 @@ class BackportCommand(Command):
         for v in versions:
 
             # Gets the instance to cherry-pick to
-            name = self.Wp.generateInstanceName(v, integration=integration)
+            name = self.Wp.generateInstanceName(v, purpose=backportto)
             if not self.Wp.isMoodle(name):
                 logging.warning('Could not find instance %s for version %s' % (name, v))
                 continue
index f89ccda..076afb9 100644 (file)
@@ -57,10 +57,13 @@ class CreateCommand(Command):
                 }
             ),
             (
-                ['-t', '--integration'],
+                ['-p', '--purpose'],
                 {
-                    'action': 'store_true',
-                    'help': 'create an instance from integration'
+                    'action': 'store',
+                    'choices': ['integration', 'review', 'stable'],
+                    'default': 'stable',
+                    'help': 'specify what this instance is for',
+                    'metavar': 'purpose'
                 }
             ),
             (
@@ -125,7 +128,7 @@ class CreateCommand(Command):
                     'version': version,
                     'suffix': suffix,
                     'engine': engine,
-                    'integration': args.integration,
+                    'purpose': args.purpose,
                     'identifier': args.identifier,
                     'install': install,
                     'run': args.run
@@ -145,7 +148,7 @@ class CreateCommand(Command):
 
         engine = args.engine
         version = args.version
-        name = self.Wp.generateInstanceName(version, integration=args.integration, suffix=args.suffix, identifier=args.identifier)
+        name = self.Wp.generateInstanceName(version, engine=engine, purpose=args.purpose, suffix=args.suffix, identifier=args.identifier)
 
         # Wording version
         versionNice = version
@@ -153,11 +156,15 @@ class CreateCommand(Command):
             versionNice = self.C.get('wording.master')
 
         # Generating names
-        if args.integration:
+        if args.purpose == 'integration':
             fullname = self.C.get('wording.integration') + ' ' + versionNice + ' ' + self.C.get('wording.%s' % engine)
-        else:
+
+        if args.purpose == 'stable':
             fullname = self.C.get('wording.stable') + ' ' + versionNice + ' ' + self.C.get('wording.%s' % engine)
 
+        if args.purpose == 'review':
+            fullname = self.C.get('wording.review') + ' ' + versionNice + ' ' + self.C.get('wording.%s' % engine)
+
         # Append the suffix
         if args.suffix:
             fullname += ' ' + args.suffix.replace('-', ' ').replace('_', ' ').title()
@@ -167,7 +174,8 @@ class CreateCommand(Command):
         kwargs = {
             'name': name,
             'version': version,
-            'integration': args.integration
+            'purpose': args.purpose,
+            'engine': engine
         }
         try:
             M = self.Wp.create(**kwargs)
index e9a3227..578f4fe 100644 (file)
@@ -86,7 +86,11 @@ class Moodle(object):
         if type(value) == bool:
             value = 'true' if value else 'false'
         elif type(value) != int:
-            value = "'" + str(value).replace('%instancename%', self.identifier) + "'"
+            value = str(value).replace('%instancename%', self.identifier)
+            value = re.sub(r'%instancename:(\d*)%',
+                           lambda m: self.identifier.split(C.get('wording.prefixSeparator'))[int(m.group(1))],
+                           value)
+            value = "'" + value + "'"
         value = str(value)
 
         try:
@@ -428,6 +432,9 @@ class Moodle(object):
                 try:
                     if isinstance(cfgValue, basestring):
                         cfgValue = cfgValue.replace('%instancename%', self.identifier)
+                        cfgValue = re.sub(r'%instancename:(\d*)%',
+                                          lambda m: self.identifier.split(C.get('wording.prefixSeparator'))[int(m.group(1))],
+                                          cfgValue)
 
                     logging.info('Setting up forced $CFG->%s to \'%s\' in config.php', cfgKey, cfgValue)
                     self.addConfig(cfgKey, cfgValue)
@@ -473,8 +480,14 @@ class Moodle(object):
         return False
 
     def isStable(self):
-        """Assume an instance is stable if not integration"""
-        return not self.isIntegration()
+        """Returns whether an instance is a stable one or not"""
+        name = self.identifier.split(C.get('wording.prefixSeparator'))[0]
+        return name == C.get('wording.prefixStable')
+
+    def isReview(self):
+        """Returns whether an instance is a review one or not"""
+        name = self.identifier.split(C.get('wording.prefixSeparator'))[0]
+        return name == C.get('wording.prefixReview')
 
     def _load(self):
         """Loads the information"""
index b357d6d..0a42b9d 100644 (file)
@@ -114,16 +114,21 @@ class Workplace(object):
                 logging.info('Have a break, this operation is slow...')
                 process('%s clone --mirror %s %s' % (C.get('git'), C.get('remotes.integration'), cacheIntegration))
 
-    def create(self, name=None, version='master', integration=False, useCacheAsRemote=False):
+    def create(self, name=None, version='master', purpose='stable', engine=C.get('defaultEngine'), useCacheAsRemote=False):
         """Creates a new instance of Moodle.
         The parameter useCacheAsRemote has been deprecated.
         """
+        integration = False
+
         if name == None:
-            name = self.generateInstanceName(version, integration=integration)
+            name = self.generateInstanceName(version, purpose=purpose)
 
         if name == self.mdkDir:
             raise Exception('A Moodle instance cannot be called \'%s\', this is a reserved word.' % self.mdkDir)
 
+        if purpose == 'integration':
+            integration = True
+
         installDir = self.getPath(name)
         wwwDir = self.getPath(name, 'www')
         dataDir = self.getPath(name, 'data')
@@ -230,7 +235,7 @@ class Workplace(object):
         if DB and dbname and DB.dbexists(dbname):
             DB.dropdb(dbname)
 
-    def generateInstanceName(self, version, integration=False, suffix='', identifier=None):
+    def generateInstanceName(self, version, engine=C.get('defaultEngine'), purpose='stable', suffix='', identifier=None):
         """Creates a name (identifier) from arguments"""
 
         if identifier != None:
@@ -245,10 +250,18 @@ class Workplace(object):
                 prefixVersion = version
 
             # Generating name
-            if integration:
-                name = C.get('wording.prefixIntegration') + prefixVersion
-            else:
-                name = C.get('wording.prefixStable') + prefixVersion
+            sep = C.get('wording.prefixSeparator');
+            if purpose == 'integration':
+                name = C.get('wording.prefixIntegration') + sep + prefixVersion
+
+            if purpose == 'review':
+                name = C.get('wording.prefixReview') + sep + prefixVersion
+
+            if purpose == 'stable':
+                name = C.get('wording.prefixStable') + sep + prefixVersion
+
+            if C.get('wording.appendEngine'):
+                name += sep + engine
 
         # Append the suffix
         if suffix != None and suffix != '':