# Path: mdk/command.py
# class Command(object):
#     """Represents a command"""
# 
#     _arguments = [
#             (
#                 ['foo'],
#                 {
#                     'help': 'I\'m an argument'
#                 }
#             ),
#             (
#                 ['-b', '--bar'],
#                 {
#                     'action': 'store_true',
#                     'help': 'I\'m a flag'
#                 }
#             )
#         ]
#     _description = 'Undocumented command'
# 
#     __C = None
#     __Wp = None
# 
#     def __init__(self, config):
#         self.__C = config
# 
#     def argumentError(self, message):
#         raise CommandArgumentError(message)
# 
#     @property
#     def arguments(self):
#         return self._arguments
# 
#     @property
#     def C(self):
#         return self.__C
# 
#     @property
#     def description(self):
#         return self._description
# 
#     def run(self, args):
#         return True
# 
#     @property
#     def Wp(self):
#         if not self.__Wp:
#             from .workplace import Workplace
#             self.__Wp = Workplace()
#         return self.__Wp
# 
# Path: mdk/tools.py
# def question(q, default=None, options=None, password=False):
#     """Asks the user a question, and return the answer"""
#     text = q
#     if default != None:
#         text = text + ' [%s]' % str(default)
# 
#     if password:
#         i = getpass.getpass('%s\n   ' % text)
#     else:
#         i = input('%s\n  ' % text)
# 
#     if i.strip() == '':
#         return default
#     else:
#         if options != None and i not in options:
#             return question(q, default, options)
#         return i
# 
# def get_current_user():
#     """Attempt to get the currently logged in user"""
#     username = 'root'
#     try:
#         username = os.getlogin()
#     except OSError:
#         import getpass
#         try:
#             username = getpass.getuser()
#         except:
#             pass
#     return username
# 
# def mkdir(path, perms=0o755):
#     """Creates a directory ignoring the OS umask"""
#     oldumask = os.umask(0000)
#     os.mkdir(path, perms)
#     os.umask(oldumask)


import os
import grp
import re
import pwd
import subprocess
import logging
from ..command import Command
from ..tools import question, get_current_user, mkdir
        from ..config import Conf as Config
            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)
                mkdir(mdkdir, 0o775)
                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')))

# Path: mdk/command.py
# class Command(object):
#     """Represents a command"""
# 
#     _arguments = [
#             (
#                 ['foo'],
#                 {
#                     'help': 'I\'m an argument'
#                 }
#             ),
#             (
#                 ['-b', '--bar'],
#                 {
#                     'action': 'store_true',
#                     'help': 'I\'m a flag'
#                 }
#             )
#         ]
#     _description = 'Undocumented command'
# 
#     __C = None
#     __Wp = None
# 
#     def __init__(self, config):
#         self.__C = config
# 
#     def argumentError(self, message):
#         raise CommandArgumentError(message)
# 
#     @property
#     def arguments(self):
#         return self._arguments
# 
#     @property
#     def C(self):
#         return self.__C
# 
#     @property
#     def description(self):
#         return self._description
# 
#     def run(self, args):
#         return True
# 
#     @property
#     def Wp(self):
#         if not self.__Wp:
#             from .workplace import Workplace
#             self.__Wp = Workplace()
#         return self.__Wp
# 
# Path: mdk/tools.py
# def question(q, default=None, options=None, password=False):
#     """Asks the user a question, and return the answer"""
#     text = q
#     if default != None:
#         text = text + ' [%s]' % str(default)
# 
#     if password:
#         i = getpass.getpass('%s\n   ' % text)
#     else:
#         i = input('%s\n  ' % text)
# 
#     if i.strip() == '':
#         return default
#     else:
#         if options != None and i not in options:
#             return question(q, default, options)
#         return i
# 
# def get_current_user():
#     """Attempt to get the currently logged in user"""
#     username = 'root'
#     try:
#         username = os.getlogin()
#     except OSError:
#         import getpass
#         try:
#             username = getpass.getuser()
#         except:
#             pass
#     return username
# 
# def mkdir(path, perms=0o755):
#     """Creates a directory ignoring the OS umask"""
#     oldumask = os.umask(0000)
#     os.mkdir(path, perms)
#     os.umask(oldumask)


# Path: mdk/commands/init.py
import os
import grp
import re
import pwd
import subprocess
import logging
from ..command import Command
from ..tools import question, get_current_user, mkdir
        from ..config import Conf as Config

            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)
                mkdir(mdkdir, 0o775)
                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?', 'root', password=True))