Changes to instance naming:
[mdk.git] / mdk / moodle.py
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"""