From: Frederic Massart Date: Mon, 21 Jul 2014 01:50:47 +0000 (+0800) Subject: Adding support for MariaDB. Fixes #90 X-Git-Tag: v1.3~27 X-Git-Url: https://git.cameron1729.xyz/?a=commitdiff_plain;h=5a501404cc4ccb648bbef328b5e89c8f03279cd6;p=mdk.git Adding support for MariaDB. Fixes #90 --- diff --git a/README.md b/README.md index 0348522..d70cc0a 100644 --- 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. diff --git a/config-dist.json b/config-dist.json index 99ad039..d5092cf 100644 --- a/config-dist.json +++ b/config-dist.json @@ -33,6 +33,12 @@ // 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" }, diff --git a/extra/bash_completion b/extra/bash_completion index 558be82..49312f0 100644 --- a/extra/bash_completion +++ b/extra/bash_completion @@ -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)" diff --git a/lib/backup.py b/lib/backup.py index 987f1d8..ad3b493 100644 --- a/lib/backup.py +++ b/lib/backup.py @@ -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') diff --git a/lib/commands/create.py b/lib/commands/create.py index ec668fd..f85de71 100644 --- a/lib/commands/create.py +++ b/lib/commands/create.py @@ -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' diff --git a/lib/commands/install.py b/lib/commands/install.py index 8a36c4e..99f539e 100644 --- a/lib/commands/install.py +++ b/lib/commands/install.py @@ -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' diff --git a/lib/db.py b/lib/db.py index b8984bf..86eb4db 100644 --- 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])