# 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
        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)
            mkdir(userdir, 0o755)
            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)

        # Loading the configuration.
        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):

# 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

        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)
            mkdir(userdir, 0o755)
            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)

        # Loading the configuration.
        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):

                    mkdir(www, 0o775)