},
"remotes": {
- "stable": "git://github.com/moodle/moodle.git",
- "integration": "git://github.com/moodle/integration.git",
+ // In any case, the integration branch MUST end with integration.git
+ "stable": "git://git.moodle.org/moodle.git",
+ "integration": "git://git.moodle.org/integration.git",
"mine": "git@github.com/FMCorz/moodle.git"
},
cmd = 'fetch %s %s' % (remote, ref)
return self.execute(cmd)
+ def getConfig(self, name):
+ cmd = 'config --get %s' % name
+ result = self.execute(cmd)
+ if result[0] == 0:
+ return result[1].strip()
+ else:
+ return None
+
def hasBranch(self, branch, remote = ''):
if remote != '':
cmd = 'show-ref --verify --quiet "refs/remotes/%s/%s"' % (remote, branch)
try:
self.addConfig('sessioncookiepath', '/%s/' % self.identifier)
except Exception as e:
- print e
debug('Could not append $CFG->sessioncookiepath to config.php')
self.reload()
return True
+ def isIntegration(self):
+ """Returns whether an instance is an integration one or not"""
+ remote = self.git().getConfig('remote.origin.url')
+ if remote != None and remote.endswith('integration.git'):
+ return True
+ return False
+
+ def isStable(self):
+ """Assume an instance is stable if not integration"""
+ return not self.isIntegration()
+
def _load(self):
"""Loads the information"""
if not self.isInstance(self.path):
else:
self.version['stablebranch'] = 'MOODLE_%s_STABLE' % self.version['branch']
+ # Integration or stable?
+ self.version['integration'] = self.isIntegration()
+
f.close()
else:
# Should never happen
"""Reloads the information"""
self._loaded = False
return self._load()
+
+ def update(self):
+ """Update the instance from the remote"""
+ pass
+
+ def upgrade(self):
+ """Calls the upgrade script"""
+ cli = '/admin/cli/upgrade.php'
+ args = '--non-interactive --allow-unstable'
+ result = self.cli(cli, args, stdout = None, stderr = None)
+ return result[0] == 0
return True
- def list(self):
+ def list(self, integration = None, stable = None):
"""Return the list of Moodle instances"""
dirs = os.listdir(self.path)
names = []
if d == '.' or d == '..': continue
if not os.path.isdir(os.path.join(self.path, d)): continue
if not self.isMoodle(d): continue
+ if integration != None or stable != None:
+ M = self.get(d)
+ if integration == False and M.isIntegration(): continue
+ if stable == False and M.isStable(): continue
names.append(d)
return names
return False
+ def resolveMultiple(self, names = []):
+ """Return multiple instances"""
+ if type(names) != list:
+ if type(names) == str:
+ names = list(names)
+ else:
+ raise Exception('Unexpected variable type')
+
+ # Nothing has been passed, we use resolve()
+ if len(names) < 1:
+ M = self.resolve()
+ if M:
+ return [ M ]
+ else:
+ return [ ]
+
+ # Try to resolve each instance
+ result = []
+ for name in names:
+ M = self.resolve(name = name)
+ if M:
+ result.append(M)
+ else:
+ debug('Could not find instance called %s' % name)
+ return result
+
def updateCachedClones(self, integration = True, stable = True):
"""Update the cached clone of the repositories"""
pass
--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+import argparse
+from lib import config, workplace, moodle, tools
+from lib.tools import debug
+
+C = config.Conf().get
+Wp = workplace.Workplace()
+
+# Arguments
+parser = argparse.ArgumentParser(description='Runs the Moodle upgrade script')
+parser.add_argument('-a', '--all', action='store_true', help='runs the script on every instances', dest='all')
+parser.add_argument('-i', '--integration', action='store_true', help='runs the script on the integration instances', dest='integration')
+parser.add_argument('-s', '--stable', action='store_true', help='runs the script on the stable instances', dest='stable')
+parser.add_argument('-u', '--update', action='store_true', help='update the instance before running the upgrade script', dest='update')
+parser.add_argument('names', metavar='names', default=None, nargs='*', help='name of the instances')
+args = parser.parse_args()
+
+names = args.names
+if args.all:
+ names = Wp.list()
+elif args.integration or args.stable:
+ names = Wp.list(integration = args.integration, stable = args.stable)
+
+Mlist = Wp.resolveMultiple(names)
+if len(Mlist) < 1:
+ debug('No instances to work on. Exiting...')
+ sys.exit(1)
+
+for M in Mlist:
+ if args.update:
+ debug('Updating %s...' % M.get('identifier'))
+ M.update()
+ debug('Upgrading %s...' % M.get('identifier'))
+ if M.upgrade():
+ debug('Error during the upgrade of %s' % M.get('identifier'))
+ debug('')
+
+debug('Done.')