コード例 #1
0
ファイル: moodle-rebase.py プロジェクト: danpoltawski/mdk
import sys
import argparse
import re
from lib import workplace, moodle, tools
from lib.tools import debug
from lib.config import Conf

Wp = workplace.Workplace()
C = Conf()

# Arguments
parser = argparse.ArgumentParser(description="Rebases branches")
parser.add_argument('-i', '--issues', metavar='issues', required=True, nargs='+', help='issues to be rebased')
parser.add_argument('-s', '--suffix', metavar='suffix', help='the suffix of the branch of those issues')
parser.add_argument('-v', '--versions', metavar='version', nargs='+', choices=[ str(x) for x in range(13, int(C.get('masterBranch'))) ] + ['master'], help='versions to rebase the issues on. Ignored if names is set.')
parser.add_argument('-p', '--push', action='store_true', help='push the branch after successful rebase')
parser.add_argument('-r', '--remote', metavar='remote', help='the remote to push the branch to. Default is %s.' % C.get('myRemote'))
parser.add_argument('-f', '--force-push', action='store_true', help='Force the push', dest='forcepush')
parser.add_argument('names', metavar='names', default=None, nargs='*', help='name of the instances to rebase')
args = parser.parse_args()

names = args.names
issues = args.issues
versions = args.versions

# If we don't have a version, we need an instance
if not names and not versions:
    debug('This is not a Moodle instance')
    sys.exit(1)
コード例 #2
0
ファイル: moodle-phpunit.py プロジェクト: danpoltawski/mdk
import sys
import argparse
from lib import workplace
from lib.tools import debug, process
from lib.config import Conf

C = Conf()

# Arguments
parser = argparse.ArgumentParser(description='Initialize PHPUnit')
parser.add_argument('-f', '--force', action='store_true', help='force the initialisation')
parser.add_argument('-r', '--run', action='store_true', help='also run the tests')
parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance')
args = parser.parse_args()

Wp = workplace.Workplace(C.get('dirs.storage'))

# Loading instance
M = Wp.resolve(args.name)
if not M:
    debug('This is not a Moodle instance')
    sys.exit(1)

# Check if installed
if not M.get('installed'):
    debug('This instance needs to be installed first')
    sys.exit(1)

# Run cli
try:
    M.initPHPUnit(force=args.force)
コード例 #3
0
                    dest='forcestable')
parser.add_argument('name',
                    metavar='name',
                    default=None,
                    nargs='?',
                    help='name of the instance to work on')
args = parser.parse_args()

M = Wp.resolve(args.name)
if not M:
    debug('This is not a Moodle instance')
    sys.exit(1)

# Setting remote
if args.remote == None:
    remote = C.get('myRemote')
else:
    remote = args.remote

# Setting branch
if args.branch == None:
    branch = M.currentBranch()
    if branch == 'HEAD':
        debug('Cannot push HEAD branch')
        sys.exit(1)
else:
    branch = args.branch

# Pushing current branch
debug('Pushing branch %s to remote %s...' % (branch, remote))
result = M.git().push(remote, branch, force=args.force)
コード例 #4
0
ファイル: moodle-backport.py プロジェクト: danpoltawski/mdk
http://github.com/FMCorz/mdk
"""

import sys
import argparse
from lib import workplace, tools, jira
from lib.tools import debug
from lib.config import Conf

Wp = workplace.Workplace()
C = Conf()

# Arguments
parser = argparse.ArgumentParser(description="Backports a branch")
parser.add_argument('-b', '--branch', metavar='branch', help='the branch to backport if not the current one. If omitted, guessed from instance name.')
parser.add_argument('-r', '--remote', metavar='remote', help='the remote to fetch from. Default is %s.' % C.get('myRemote'))
parser.add_argument('-i', '--integration', action='store_true', help='backport to integration instances.', dest='integration')
parser.add_argument('-d', '--dont-push', action='store_true', help='if name is specified, the branch is pushed to the remote (-p) before backporting. This disables this behaviour.', dest='dontpush')
parser.add_argument('-e', '--dont-fetch', action='store_true', help='By default the upstream branch is fetched. This disables this behaviour.', dest='dontfetch')
parser.add_argument('-p', '--push', action='store_true', help='push the branch after successful backport')
parser.add_argument('-t', '--push-to', metavar='remote', help='the remote to push the branch to. Default is %s.' % C.get('myRemote'), dest='pushremote')
parser.add_argument('-f', '--force-push', action='store_true', help='Force the push', dest='forcepush')
parser.add_argument('-j', '--update-jira', action='store_true', help='also add the github links to the jira issue.', dest='updatejira')
parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance to backport from. Can be omitted if branch is specified.')
parser.add_argument('-v', '--versions', metavar='version', required=True, nargs='+', choices=[str(x) for x in range(13, int(C.get('masterBranch')))] + ['master'], help='versions to backport to')
args = parser.parse_args()

M = None
branch = args.branch
versions = args.versions
remote = args.remote
コード例 #5
0
ファイル: moodle-rebase.py プロジェクト: danpoltawski/mdk
                    '--issues',
                    metavar='issues',
                    required=True,
                    nargs='+',
                    help='issues to be rebased')
parser.add_argument('-s',
                    '--suffix',
                    metavar='suffix',
                    help='the suffix of the branch of those issues')
parser.add_argument(
    '-v',
    '--versions',
    metavar='version',
    nargs='+',
    choices=[str(x)
             for x in range(13, int(C.get('masterBranch')))] + ['master'],
    help='versions to rebase the issues on. Ignored if names is set.')
parser.add_argument('-p',
                    '--push',
                    action='store_true',
                    help='push the branch after successful rebase')
parser.add_argument('-r',
                    '--remote',
                    metavar='remote',
                    help='the remote to push the branch to. Default is %s.' %
                    C.get('myRemote'))
parser.add_argument('-f',
                    '--force-push',
                    action='store_true',
                    help='Force the push',
                    dest='forcepush')
コード例 #6
0
ファイル: moodle-check.py プロジェクト: danpoltawski/mdk
parser.add_argument('-s',
                    '--stable',
                    action='store_true',
                    help='runs the script on the stable instances',
                    dest='stable')
parser.add_argument('names',
                    metavar='names',
                    default=None,
                    nargs='*',
                    help='name of the instances')
args = parser.parse_args()

# Check configuration file
debug('[Config file]')
distSettings = Conf(os.path.dirname(__file__), 'config-dist.json').get()
allSettings = C.get()

errors = []


def dictCompare(orig, mine, path=''):
    for k in orig:
        currentpath = path + '.' + k
        currentpath = currentpath.strip('.')
        if k not in mine:
            errors.append(currentpath)
        elif type(orig[k]) in (dict, list):
            dictCompare(orig[k], mine[k], currentpath)


dictCompare(distSettings, allSettings)
コード例 #7
0
args = parser.parse_args()

M = Wp.resolve()
if not M:
    debug('This is not a Moodle instance')
    sys.exit(1)

if args.testing and args.integration:
    debug('You cannot combine --integration and --testing')
    sys.exit(1)

# Tracker issue number.
issuenb = args.issue
if not issuenb:
    parsedbranch = tools.parseBranch(M.currentBranch(),
                                     C.get('wording.branchRegex'))
    if not parsedbranch:
        debug('Could not extract issue number from %s' % M.currentBranch())
        sys.exit(1)
    issuenb = parsedbranch['issue']

issue = re.sub(r'(MDL|mdl)(-|_)?', '', issuenb)
mdl = 'MDL-' + issue

# Reading the information about the current instance.
branch = M.get('branch')

# Get information from Tracker
debug('Retrieving information about %s from Moodle Tracker' % (mdl))
J = jira.Jira()
issueInfo = J.getIssue(mdl)
コード例 #8
0
ファイル: init.py プロジェクト: canocampus/mdk
    def run(self, args):

        # Check root.
        if os.getuid() != 0:
            raise Exception('You must execute this as root.\n  sudo mdk init')

        # Check what user we want to initialise for.
        while True:
            username = question('What user are you initialising MDK for?', get_current_user())
            try:
                user = pwd.getpwnam(username)
            except:
                logging.warning('Error while getting information for user %s' % (username))
                continue

            try:
                usergroup = grp.getgrgid(user.pw_gid)
            except:
                logging.warning('Error while getting the group of user %s' % (username))
                continue

            break

        # Default directories.
        userdir = self.resolve_directory('~/.moodle-sdk', username)
        scriptdir = os.path.dirname(os.path.realpath(__file__))

        # Create the main MDK folder.
        if not os.path.isdir(userdir):
            logging.info('Creating directory %s.' % userdir)
            os.mkdir(userdir, 0755)
            os.chown(userdir, user.pw_uid, usergroup.gr_gid)

        # Checking if the config file exists.
        userconfigfile = os.path.join(userdir, 'config.json')
        if os.path.isfile(userconfigfile):
            logging.info('Config file %s already in place.' % userconfigfile)
            if not args.force:
                raise Exception('Aborting. Use --force to continue.')

        elif not os.path.isfile(userconfigfile):
            logging.info('Creating user config file in %s.' % userconfigfile)
            open(userconfigfile, 'w')
            os.chown(userconfigfile, user.pw_uid, usergroup.gr_gid)

        # If the group moodle-sdk exists, then we want to add the user to it.
        try:
            group = grp.getgrnam('moodle-sdk')
            if not username in group.gr_mem:
                logging.info('Adding user %s to group %s.' % (username, group.gr_name))
                # This command does not work for some reason...
                # os.initgroups(username, group.gr_gid)
                chgrp = subprocess.Popen(['usermod', '-a', '-G', 'moodle-sdk', username])
                chgrp.wait()
        except KeyError:
            # Raised when the group has not been found.
            group = None
            pass

        # Loading the configuration.
        from lib.config import Conf as Config
        C = Config(userfile=userconfigfile)

        # Asks the user what needs to be asked.
        while True:
            www = question('What is the DocumentRoot of your virtual host?', C.get('dirs.www'))
            www = self.resolve_directory(www, username)
            try:
                if not os.path.isdir(www):
                    os.mkdir(www, 0775)
                    os.chown(www, user.pw_uid, usergroup.gr_gid)
            except:
                logging.error('Error while creating directory %s' % www)
                continue
            else:
                C.set('dirs.www', www)
                break

        while True:
            storage = question('Where do you want to store your Moodle instances?', C.get('dirs.storage'))
            storage = self.resolve_directory(storage, username)
            try:
                if not os.path.isdir(storage):
                    if storage != www:
                        os.mkdir(storage, 0775)
                        os.chown(storage, user.pw_uid, usergroup.gr_gid)
                    else:
                        logging.error('Error! dirs.www and dirs.storage must be different!')
                        continue
            except:
                logging.error('Error while creating directory %s' % storage)
                continue
            else:
                C.set('dirs.storage', storage)
                break

        # The default configuration file should point to the right directory for dirs.mdk,
        # we will just ensure that it exists.
        mdkdir = C.get('dirs.mdk')
        mdkdir = self.resolve_directory(mdkdir, username)
        if not os.path.isdir(mdkdir):
            try:
                logging.info('Creating MDK directory %s' % mdkdir)
                os.mkdir(mdkdir, 0775)
                os.chown(mdkdir, user.pw_uid, usergroup.gr_gid)
            except:
                logging.error('Error while creating %s, please fix manually.' % mdkdir)

        # Git repository.
        github = question('What is your Github username? (Leave blank if not using Github)')
        if github != None:
            C.set('remotes.mine', C.get('remotes.mine').replace('YourGitHub', github))
            C.set('repositoryUrl', C.get('repositoryUrl').replace('YourGitHub', github))
            C.set('diffUrlTemplate', C.get('diffUrlTemplate').replace('YourGitHub', github))
            C.set('myRemote', 'github')
            C.set('upstreamRemote', 'origin')
        else:
            C.set('remotes.mine', question('What is your remote?', C.get('remotes.mine')))
            C.set('myRemote', question('What to call your remote?', C.get('myRemote')))
            C.set('upstreamRemote', question('What to call the upsream remote (official Moodle remote)?', C.get('upstreamRemote')))

        # Database settings.
        C.set('db.mysqli.user', question('What is your MySQL user?', C.get('db.mysqli.user')))
        C.set('db.mysqli.passwd', question('What is your MySQL password?', C.get('db.mysqli.passwd'), password=True))
        C.set('db.pgsql.user', question('What is your PostgreSQL user?', C.get('db.pgsql.user')))
        C.set('db.pgsql.passwd', question('What is your PostgreSQL password?', C.get('db.pgsql.passwd'), password=True))

        print ''
        print 'MDK has been initialised with minimal configuration.'
        print 'For more settings, edit your config file: %s.' % userconfigfile
        print 'Use %s as documentation.' % os.path.join(scriptdir, 'config-dist.json')
        print ''
        print 'Type the following command to create your first instance:'
        print '  mdk create'
        print '(This will take some time, but don\'t worry, that\'s because the cache is still empty)'
        print ''
        print '/!\ Please logout/login before to avoid permission issues: sudo su `whoami`'
コード例 #9
0
ファイル: moodle-backport.py プロジェクト: danpoltawski/mdk
C = Conf()

# Arguments
parser = argparse.ArgumentParser(description="Backports a branch")
parser.add_argument(
    '-b',
    '--branch',
    metavar='branch',
    help=
    'the branch to backport if not the current one. If omitted, guessed from instance name.'
)
parser.add_argument('-r',
                    '--remote',
                    metavar='remote',
                    help='the remote to fetch from. Default is %s.' %
                    C.get('myRemote'))
parser.add_argument('-i',
                    '--integration',
                    action='store_true',
                    help='backport to integration instances.',
                    dest='integration')
parser.add_argument(
    '-d',
    '--dont-push',
    action='store_true',
    help=
    'if name is specified, the branch is pushed to the remote (-p) before backporting. This disables this behaviour.',
    dest='dontpush')
parser.add_argument(
    '-e',
    '--dont-fetch',
コード例 #10
0
ファイル: moodle-check.py プロジェクト: danpoltawski/mdk
Wp = workplace.Workplace()
C = Conf()

# Arguments
parser = argparse.ArgumentParser(description='Perform several checks on your current installation')
# parser.add_argument('-f', '--fix', dest='fix', action='store_true', help='Fix the problems where possible')
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('names', metavar='names', default=None, nargs='*', help='name of the instances')
args = parser.parse_args()

# Check configuration file
debug('[Config file]')
distSettings = Conf(os.path.dirname(__file__), 'config-dist.json').get()
allSettings = C.get()

errors = []
def dictCompare(orig, mine, path = ''):
    for k in orig:
        currentpath = path + '.' + k
        currentpath = currentpath.strip('.')
        if k not in mine:
            errors.append(currentpath)
        elif type(orig[k]) in (dict, list):
            dictCompare(orig[k], mine[k], currentpath)
dictCompare(distSettings, allSettings)

if len(errors) > 0:
    for err in errors:
        debug(u'Missing setting %s' % err)
コード例 #11
0
ファイル: moodle-behat.py プロジェクト: danpoltawski/mdk
    metavar="jarfile",
    nargs="?",
    default=None,
    help="path to the selenium standalone server to use",
    dest="selenium",
)
parser.add_argument(
    "--selenium-verbose",
    action="store_true",
    help="outputs the output from selenium in the same window",
    dest="seleniumverbose",
)
parser.add_argument("name", metavar="name", default=None, nargs="?", help="name of the instance")
args = parser.parse_args()

Wp = workplace.Workplace(C.get("dirs.storage"))

# Loading instance
M = Wp.resolve(args.name)
if not M:
    debug("This is not a Moodle instance")
    sys.exit(1)

# Check if installed
if not M.get("installed"):
    debug("This instance needs to be installed first")
    sys.exit(1)

# No Javascript
nojavascript = args.nojavascript
if not nojavascript and not C.get("java") or not os.path.isfile(os.path.abspath(C.get("java"))):
コード例 #12
0
ファイル: moodle-behat.py プロジェクト: danpoltawski/mdk
                    nargs='?',
                    default=None,
                    help='path to the selenium standalone server to use',
                    dest='selenium')
parser.add_argument('--selenium-verbose',
                    action='store_true',
                    help='outputs the output from selenium in the same window',
                    dest='seleniumverbose')
parser.add_argument('name',
                    metavar='name',
                    default=None,
                    nargs='?',
                    help='name of the instance')
args = parser.parse_args()

Wp = workplace.Workplace(C.get('dirs.storage'))

# Loading instance
M = Wp.resolve(args.name)
if not M:
    debug('This is not a Moodle instance')
    sys.exit(1)

# Check if installed
if not M.get('installed'):
    debug('This instance needs to be installed first')
    sys.exit(1)

# No Javascript
nojavascript = args.nojavascript
if not nojavascript and not C.get('java') or not os.path.isfile(
コード例 #13
0
parser.add_argument('-n', '--name', metavar='name', default=None, help='name of the instance')
args = parser.parse_args()

Wp = workplace.Workplace()

# Loading instance
M = Wp.resolve(args.name)
if not M:
    debug('This is not a Moodle instance')
    sys.exit(1)

# Branch name
branch = M.generateBranchName(args.issue, suffix=args.suffix)

# Track
track = '%s/%s' % (C.get('upstreamRemote'), M.get('stablebranch'))

# Git repo
repo = M.git()

# Creating and checking out the new branch
if not repo.hasBranch(branch):
	if not repo.createBranch(branch, track):
		debug('Could not create branch %s' % branch)
		sys.exit(1)
if not repo.checkout(branch):
	debug('Error while checkout out branch %s' % branch)
	sys.exit(1)

debug('Branch %s checked out' % branch)
コード例 #14
0
ファイル: moodle-config.py プロジェクト: danpoltawski/mdk
    "command", metavar="command", choices=["flatlist", "list", "show", "set"], help="the action to perform"
)
parser.add_argument("arguments", metavar="arguments", default=None, nargs="*", help="arguments for the command")
args = parser.parse_args()

if args.command == "list":

    def show_list(settings, ident):
        for name, setting in settings.items():
            if type(setting) != dict:
                print u"{0:<20}: {1}".format(u" " * ident + name, setting)
            else:
                print u" " * ident + "[%s]" % name
                show_list(setting, ident + 2)

    show_list(C.get(), 0)

elif args.command == "flatlist":

    def show_list(settings, parent=""):
        for name, setting in settings.items():
            if type(setting) != dict:
                print u"%s: %s" % (parent + name, setting)
            else:
                show_list(setting, parent + name + u".")

    show_list(C.get())

elif args.command == "show":
    if len(args.arguments) != 1:
        debug("Too few/many arguments. One needed: moodle config show settingName")
コード例 #15
0
    '--install',
    action='store_true',
    help='launch the installation script after creating the instance',
    dest='install')
parser.add_argument('-r',
                    '--run',
                    action='store',
                    nargs='*',
                    help='scripts to run after installation',
                    metavar='run')
parser.add_argument(
    '-v',
    '--version',
    action='store',
    choices=[str(x)
             for x in range(13, int(C.get('masterBranch')))] + ['master'],
    default='master',
    help='version of Moodle',
    metavar='version')
parser.add_argument('-s',
                    '--suffix',
                    action='store',
                    help='suffix for the instance name',
                    metavar='suffix')
parser.add_argument('-e',
                    '--engine',
                    action='store',
                    choices=['mysqli', 'pgsql'],
                    default=C.get('defaultEngine'),
                    help='database engine to use',
                    metavar='engine')
コード例 #16
0
ファイル: moodle-push.py プロジェクト: danpoltawski/mdk
parser.add_argument('-r', '--remote', metavar='remote', help='remote to push to. Default is your remote.')
parser.add_argument('-f', '--force', action='store_true', help='force the push (does not apply on the stable branch).')
parser.add_argument('-t', '--update-tracker', action='store_true', help='also add the diff information to the tracker issue.', dest='updatetracker')
parser.add_argument('-s', '--include-stable', action='store_true', help='also push the stable branch (MOODLE_xx_STABLE, master)', dest='includestable')
parser.add_argument('-k', '--force-stable', action='store_true', help='force the push on the stable branch', dest='forcestable')
parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance to work on')
args = parser.parse_args()

M = Wp.resolve(args.name)
if not M:
    debug('This is not a Moodle instance')
    sys.exit(1)

# Setting remote
if args.remote == None:
    remote = C.get('myRemote')
else:
    remote = args.remote

# Setting branch
if args.branch == None:
    branch = M.currentBranch()
    if branch == 'HEAD':
        debug('Cannot push HEAD branch')
        sys.exit(1)
else:
    branch = args.branch

# Pushing current branch
debug('Pushing branch %s to remote %s...' % (branch, remote))
result = M.git().push(remote, branch, force=args.force)
コード例 #17
0
ファイル: moodle-install.py プロジェクト: danpoltawski/mdk
"""
import sys
import os
import argparse

from lib import db, moodle, workplace
from lib.tools import debug
from lib.config import Conf

DB = db.DB
Wp = workplace.Workplace()
C = Conf()

# Arguments
parser = argparse.ArgumentParser(description='Install a Moodle instance')
parser.add_argument('-e', '--engine', action='store', choices=['mysqli', 'pgsql'], default=C.get('defaultEngine'), help='database engine to use', metavar='engine')
parser.add_argument('-f', '--fullname', action='store', help='full name of the instance', metavar='fullname')
parser.add_argument('-r', '--run', action='store', nargs='*', help='scripts to run after installation', metavar='run')
parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance')
args = parser.parse_args()

name = args.name
engine = args.engine
fullname = args.fullname

M = Wp.resolve(name)
if not M:
    debug('This is not a Moodle instance')
    sys.exit(1)

name = M.get('identifier')
コード例 #18
0
ファイル: moodle-alias.py プロジェクト: danpoltawski/mdk
# Arguments
parser = argparse.ArgumentParser(description='Manage your aliases')
parser.add_argument('command',
                    metavar='command',
                    choices=['list', 'show', 'add', 'remove'],
                    help='the action to perform')
parser.add_argument('arguments',
                    type=str,
                    metavar='arguments',
                    default=None,
                    nargs=argparse.REMAINDER,
                    help='arguments for the command')
args = parser.parse_args()

if args.command == 'list':
    aliases = C.get('aliases')
    for alias, command in aliases.items():
        print '{0:<20}: {1}'.format(alias, command)

elif args.command == 'show':
    if len(args.arguments) != 1:
        debug(
            'Too few/many arguments. One needed: moodle alias show aliasName')
        sys.exit(1)
    alias = C.get('aliases.%s' % args.arguments[0])
    if alias != None:
        debug(alias)

elif args.command == 'add':
    if len(args.arguments) < 2:
        debug(
コード例 #19
0
parser.add_argument('-f',
                    '--force',
                    action='store_true',
                    help='force the initialisation')
parser.add_argument('-r',
                    '--run',
                    action='store_true',
                    help='also run the tests')
parser.add_argument('name',
                    metavar='name',
                    default=None,
                    nargs='?',
                    help='name of the instance')
args = parser.parse_args()

Wp = workplace.Workplace(C.get('dirs.storage'))

# Loading instance
M = Wp.resolve(args.name)
if not M:
    debug('This is not a Moodle instance')
    sys.exit(1)

# Check if installed
if not M.get('installed'):
    debug('This instance needs to be installed first')
    sys.exit(1)

# Run cli
try:
    M.initPHPUnit(force=args.force)
コード例 #20
0
                    default=None,
                    nargs='*',
                    help='arguments for the command')
args = parser.parse_args()

if args.command == 'list':

    def show_list(settings, ident):
        for name, setting in settings.items():
            if type(setting) != dict:
                print u'{0:<20}: {1}'.format(u' ' * ident + name, setting)
            else:
                print u' ' * ident + '[%s]' % name
                show_list(setting, ident + 2)

    show_list(C.get(), 0)

elif args.command == 'flatlist':

    def show_list(settings, parent=''):
        for name, setting in settings.items():
            if type(setting) != dict:
                print u'%s: %s' % (parent + name, setting)
            else:
                show_list(setting, parent + name + u'.')

    show_list(C.get())

elif args.command == 'show':
    if len(args.arguments) != 1:
        debug(
コード例 #21
0
ファイル: moodle-alias.py プロジェクト: danpoltawski/mdk
except:
    # Quietly die here. The main reason would be that the config file could not
    # be loaded for some reason, which means that the environment has not been
    # set yet. Therefore we exit quietly. This is a very specific case for
    # moodle-alias as it is used in the Moodle bash script which does not know
    # if the environment is properly set or not.
    sys.exit()

# Arguments
parser = argparse.ArgumentParser(description='Manage your aliases')
parser.add_argument('command', metavar='command', choices=['list', 'show', 'add', 'remove'], help='the action to perform')
parser.add_argument('arguments', type=str, metavar='arguments', default=None, nargs=argparse.REMAINDER, help='arguments for the command')
args = parser.parse_args()

if args.command == 'list':
    aliases = C.get('aliases')
    for alias, command in aliases.items():
        print '{0:<20}: {1}'.format(alias, command)

elif args.command == 'show':
    if len(args.arguments) != 1:
        debug('Too few/many arguments. One needed: moodle alias show aliasName')
        sys.exit(1)
    alias = C.get('aliases.%s' % args.arguments[0])
    if alias != None:
        debug(alias)

elif args.command == 'add':
    if len(args.arguments) < 2:
        debug('Too few/many arguments. Two needed: moodle alias add aliasName Command To Perform')
        sys.exit(1)
コード例 #22
0
ファイル: moodle-create.py プロジェクト: danpoltawski/mdk
import re

from lib import db, moodle, workplace
from lib.tools import debug, yesOrNo
from lib.config import Conf

DB = db.DB
Wp = workplace.Workplace()
C = Conf()

# Arguments
parser = argparse.ArgumentParser(description='Creates a new instance of Moodle')
parser.add_argument('-t', '--integration', action='store_true', help='create an instance from integration')
parser.add_argument('-i', '--install', action='store_true', help='launch the installation script after creating the instance', dest='install')
parser.add_argument('-r', '--run', action='store', nargs='*', help='scripts to run after installation', metavar='run')
parser.add_argument('-v', '--version', action='store', choices=[str(x) for x in range(13, int(C.get('masterBranch')))] + ['master'], default='master', help='version of Moodle', metavar='version')
parser.add_argument('-s', '--suffix', action='store', help='suffix for the instance name', metavar='suffix')
parser.add_argument('-e', '--engine', action='store', choices=['mysqli', 'pgsql'], default=C.get('defaultEngine'), help='database engine to use', metavar='engine')
args = parser.parse_args()

engine = args.engine
version = args.version
name = Wp.generateInstanceName(version, integration=args.integration, suffix=args.suffix)

# Wording version
versionNice = version
if version == 'master':
    versionNice = C.get('wording.master')

# Generating names
if args.integration:
コード例 #23
0
ファイル: moodle-pull.py プロジェクト: danpoltawski/mdk
parser.add_argument('issue', metavar='issue', default=None, nargs='?', help='tracker issue to pull from (MDL-12345, 12345). If not specified, read from current branch.')
args = parser.parse_args()

M = Wp.resolve()
if not M:
    debug('This is not a Moodle instance')
    sys.exit(1)

if args.testing and args.integration:
    debug('You cannot combine --integration and --testing')
    sys.exit(1)

# Tracker issue number.
issuenb = args.issue
if not issuenb:
    parsedbranch = tools.parseBranch(M.currentBranch(), C.get('wording.branchRegex'))
    if not parsedbranch:
        debug('Could not extract issue number from %s' % M.currentBranch())
        sys.exit(1)
    issuenb = parsedbranch['issue']

issue = re.sub(r'(MDL|mdl)(-|_)?', '', issuenb)
mdl = 'MDL-' + issue

# Reading the information about the current instance.
branch = M.get('branch')

# Get information from Tracker
debug('Retrieving information about %s from Moodle Tracker' % (mdl))
J = jira.Jira()
issueInfo = J.getIssue(mdl)
コード例 #24
0
ファイル: moodle-init.py プロジェクト: danpoltawski/mdk
        chgrp = subprocess.Popen(
            ['usermod', '-a', '-G', 'moodle-sdk', username])
        chgrp.wait()
except KeyError:
    # Raised when the group has not been found.
    group = None
    pass

# Loading the configuration.
from lib.config import Conf as Config
C = Config(userfile=userconfigfile)

# Asks the user what needs to be asked.
while True:
    www = question('What is the DocumentRoot of your virtual host?',
                   C.get('dirs.www'))
    www = resolve_directory(www, username)
    try:
        if not os.path.isdir(www):
            os.mkdir(www, 0775)
            os.chown(www, user.pw_uid, usergroup.gr_gid)
    except:
        debug('Error while creating directory %s' % www)
        continue
    else:
        C.set('dirs.www', www)
        break

while True:
    storage = question('Where do you want to store your Moodle instances?',
                       C.get('dirs.storage'))
コード例 #25
0
from lib import db, moodle, workplace
from lib.tools import debug
from lib.config import Conf

DB = db.DB
Wp = workplace.Workplace()
C = Conf()

# Arguments
parser = argparse.ArgumentParser(description='Install a Moodle instance')
parser.add_argument('-e',
                    '--engine',
                    action='store',
                    choices=['mysqli', 'pgsql'],
                    default=C.get('defaultEngine'),
                    help='database engine to use',
                    metavar='engine')
parser.add_argument('-f',
                    '--fullname',
                    action='store',
                    help='full name of the instance',
                    metavar='fullname')
parser.add_argument('-r',
                    '--run',
                    action='store',
                    nargs='*',
                    help='scripts to run after installation',
                    metavar='run')
parser.add_argument('name',
                    metavar='name',
コード例 #26
0
ファイル: mdk.py プロジェクト: andrewnicols/mdk
import sys
import argparse
import os
import re
import logging
from lib.command import CommandRunner
from lib.commands import getCommand, commandsList
from lib.config import Conf
from lib.tools import process
from version import __version__

C = Conf()

try:
    debuglevel = getattr(logging, C.get('debug').upper())
except AttributeError:
    debuglevel = logging.WARNING

logging.basicConfig(format='%(message)s', level=debuglevel)

availaliases = [str(x) for x in C.get('aliases').keys()]
choices = sorted(commandsList + availaliases)

parser = argparse.ArgumentParser(description='Moodle Development Kit', add_help=False)
parser.add_argument('-h', '--help', action='store_true', help='show this help message and exit')
parser.add_argument('-l', '--list', action='store_true', help='list the available commands')
parser.add_argument('-v', '--version', action='store_true', help='display the current version')
parser.add_argument('command', metavar='command', nargs='?', help='command to call', choices=choices)
parser.add_argument('args', metavar='arguments', nargs=argparse.REMAINDER, help='arguments of the command')
parsedargs = parser.parse_args()
コード例 #27
0
ファイル: moodle-init.py プロジェクト: danpoltawski/mdk
        # This command does not work for some reason...
        # os.initgroups(username, group.gr_gid)
        chgrp = subprocess.Popen(['usermod', '-a', '-G', 'moodle-sdk', username])
        chgrp.wait()
except KeyError:
    # Raised when the group has not been found.
    group = None
    pass

# Loading the configuration.
from lib.config import Conf as Config
C = Config(userfile=userconfigfile)

# Asks the user what needs to be asked.
while True:
    www = question('What is the DocumentRoot of your virtual host?', C.get('dirs.www'))
    www = resolve_directory(www, username)
    try:
        if not os.path.isdir(www):
            os.mkdir(www, 0775)
            os.chown(www, user.pw_uid, usergroup.gr_gid)
    except:
        debug('Error while creating directory %s' % www)
        continue
    else:
        C.set('dirs.www', www)
        break

while True:
    storage = question('Where do you want to store your Moodle instances?', C.get('dirs.storage'))
    storage = resolve_directory(storage, username)