Adding support for MariaDB. Fixes #90
authorFrederic Massart <fred@moodle.com>
Mon, 21 Jul 2014 01:50:47 +0000 (09:50 +0800)
committerFrederic Massart <fred@moodle.com>
Mon, 21 Jul 2014 01:50:47 +0000 (09:50 +0800)
README.md
config-dist.json
extra/bash_completion
lib/backup.py
lib/commands/create.py
lib/commands/install.py
lib/db.py

index 0348522..d70cc0a 100644 (file)
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ Requirements
 
 - Linux or Mac OS
 - Python 2.7
-- MySQL or PostgreSQL
+- MySQL, MariaDB or PostgreSQL
 - Git v1.7.7 or greater
 
 Most of the tools work on Moodle 1.9 onwards, but some CLI scripts required by MDK might not be available in all versions.
index 99ad039..d5092cf 100644 (file)
 
     // Database access
     "db": {
+        "mariadb": {
+            "host": "localhost",
+            "port": "3306",
+            "user": "root",
+            "passwd": "root"
+        },
         "mysqli": {
             "host": "localhost",
             "port": "3306",
@@ -67,6 +73,7 @@
         "integration": "Integration",
         "master": "Master",
         "stable": "Stable",
+        "mariadb": "MariaDB",
         "mysqli": "MySQL",
         "pgsql": "PostgreSQL"
     },
index 558be82..49312f0 100644 (file)
@@ -99,7 +99,7 @@ function _mdk() {
             create)
                 OPTS="--identifier --integration --install --run --version --suffix --engine"
                 if [[ "$PREV" == "--engine" ]]; then
-                    OPTS='mysqli pgsql'
+                    OPTS='mariadb mysqli pgsql'
                 elif [[ "$PREV" == "--run" ]]; then
                     OPTS="$(_list_scripts)"
                 fi
@@ -129,7 +129,7 @@ function _mdk() {
                 OPTS="--engine --fullname --run"
                 case "$PREV" in
                     -e|--engine)
-                        OPTS="mysqli pgsql"
+                        OPTS="mariadb mysqli pgsql"
                         ;;
                     -r|--run)
                         OPTS="$(_list_scripts)"
index 987f1d8..ad3b493 100644 (file)
@@ -47,7 +47,7 @@ class BackupManager(object):
     def create(self, M):
         """Creates a new backup of M"""
 
-        if M.isInstalled() and M.get('dbtype') != 'mysqli':
+        if M.isInstalled() and M.get('dbtype') not in ('mysqli', 'mariadb'):
             raise BackupDBEngineNotSupported('Cannot backup database engine %s' % M.get('dbtype'))
 
         name = M.get('identifier')
index ec668fd..f85de71 100644 (file)
@@ -50,7 +50,7 @@ class CreateCommand(Command):
                 ['-e', '--engine'],
                 {
                     'action': 'store',
-                    'choices': ['mysqli', 'pgsql'],
+                    'choices': ['mariadb', 'mysqli', 'pgsql'],
                     'default': self.C.get('defaultEngine'),
                     'help': 'database engine to install the instance on, use with --install',
                     'metavar': 'engine'
index 8a36c4e..99f539e 100644 (file)
@@ -42,7 +42,7 @@ class InstallCommand(Command):
                 ['-e', '--engine'],
                 {
                 'action': 'store',
-                  'choices': ['mysqli', 'pgsql'],
+                  'choices': ['mariadb', 'mysqli', 'pgsql'],
                   'default': self.C.get('defaultEngine'),
                   'help': 'database engine to use',
                   'metavar': 'engine'
index b8984bf..86eb4db 100644 (file)
--- a/lib/db.py
+++ b/lib/db.py
@@ -53,7 +53,7 @@ class DB(object):
         self.engine = engine
         self.options = options
 
-        if engine == 'mysqli':
+        if engine in ('mysqli', 'mariadb'):
 
             if 'fuckfred' in options['passwd']:
                 raise Exception('Could not establish connexion with MySQL, bad language used!')
@@ -102,7 +102,7 @@ class DB(object):
 
         columns = []
 
-        if self.engine == 'mysqli':
+        if self.engine in ('mysqli', 'mariadb'):
             logging.debug('DESCRIBE %s' % table)
             self.cur.execute('DESCRIBE %s' % table)
             for column in self.cur.fetchall():
@@ -119,7 +119,7 @@ class DB(object):
         except:
             pass
 
-        if self.engine == 'mysqli':
+        if self.engine in ('mysqli', 'mariadb'):
             sql = 'CREATE DATABASE `%s` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci' % db
         elif self.engine == 'pgsql':
             sql = 'CREATE DATABASE "%s" WITH ENCODING \'UNICODE\'' % db
@@ -135,7 +135,7 @@ class DB(object):
     def dbexists(self, db):
 
         count = None
-        if self.engine == 'mysqli':
+        if self.engine in ('mysqli', 'mariadb'):
             sql = "SELECT COUNT('*') FROM information_schema.SCHEMATA WHERE SCHEMA_NAME LIKE '%s'" % db
 
         elif self.engine == 'pgsql':
@@ -156,7 +156,7 @@ class DB(object):
         except:
             pass
 
-        if self.engine == 'mysqli':
+        if self.engine in ('mysqli', 'mariadb'):
             sql = 'DROP DATABASE `%s`' % db
         elif self.engine == 'pgsql':
             sql = 'DROP DATABASE "%s"' % db
@@ -172,7 +172,7 @@ class DB(object):
     def dump(self, fd, prefix=''):
         """Dump a database to the file descriptor passed"""
 
-        if self.engine != 'mysqli':
+        if self.engine not in ('mysqli', 'mariadb'):
             raise Exception('Function dump not supported by %s' % self.engine)
         if not type(fd) == file:
             raise Exception('Passed parameter is not a file object')
@@ -209,7 +209,7 @@ class DB(object):
 
     def selectdb(self, db):
 
-        if self.engine == 'mysqli':
+        if self.engine in ('mysqli', 'mariadb'):
             self.cur.execute('USE %s' % db)
 
         elif self.engine == 'pgsql':
@@ -243,7 +243,7 @@ class DB(object):
 
         tables = []
 
-        if self.engine == 'mysqli':
+        if self.engine in ('mysqli', 'mariadb'):
             self.cur.execute('SHOW TABLES')
             for row in self.cur.fetchall():
                 tables.append(row[0])