# Path: googkit/commands/command.py
# class Command(object):
#     """A base class for commands.
#     """
# 
#     def __init__(self, env):
#         """Create a command that depend the specified environment.
#         """
#         self.env = env
#         self.config = None
# 
#     @classmethod
#     def needs_project_config(cls):
#         """Whether this command depend to a project config file.
#         You should override to return True if this command use a project
#         config.
#         """
#         return False
# 
#     @classmethod
#     def supported_options(cls):
#         """Returns a set has supported options by this command.
#         In default, all command should support a --verbose option to display
#         verbose messages.
#         """
#         return set(['--verbose'])
# 
#     def _validate_options(self):
#         opts = set(self.env.argument.options.keys())
#         unsupported_opts = opts - self.__class__.supported_options()
# 
#         if len(unsupported_opts) > 0:
#             raise InvalidOptionError(unsupported_opts)
# 
#     def _load_config(self):
#         default_config = googkit.lib.path.default_config()
#         user_config = googkit.lib.path.user_config()
#         project_config = googkit.lib.path.project_config(self.env.cwd)
# 
#         if project_config is None:
#             raise GoogkitError(_('No config file found.'))
# 
#         config = Config()
#         config.load(project_config, user_config, default_config)
#         return config
# 
#     def _setup(self):
#         if self.__class__.needs_project_config():
#             if self.config is None:
#                 self.config = self._load_config()
# 
#         os.chdir(self.env.cwd)
# 
#     def run(self):
#         """Runs this command.
#         Override run_internal instead of run if you want to implement a new
#         command.
#         """
#         level = logging.DEBUG if self.env.argument.option('--verbose') else None
#         with log_level(level):
#             self._validate_options()
#             self._setup()
#             self.run_internal()
# 
#     def run_internal(self):
#         """Internal method for running command.
#         You can change a command behavior by overriding this method.
#         """
#         pass
# 
# Path: googkit/lib/error.py
# class GoogkitError(Exception):
#     """Base class for error in Googkit."""
# 
#     def __init__(self, message):
#         """Creates a local error of googkit by the specified message.
#         """
#         self._message = message
# 
#     @property
#     def message(self):
#         return self._message
# 
#     def __str__(self):
#         return self.message
# 
# Path: googkit/lib/i18n.py



import distutils.core
import logging
import os
import googkit.lib.path
from googkit.commands.command import Command
from googkit.lib.error import GoogkitError
from googkit.lib.i18n import _


class InitCommand(Command):
    def copy_template(self, dst_dir):
        """Copy template files (include default googkit.cfg, demonstration files) to the specified directory.
        """
        template_dir = googkit.lib.path.template()

        conflicted = set(os.listdir(dst_dir)) & set(os.listdir(template_dir))
        if conflicted:
            raise GoogkitError(_('Conflicted files: {files}').format(
                files=', '.join(conflicted)))

        distutils.dir_util.copy_tree(template_dir, dst_dir)

    def run_internal(self):
        cwd = self.env.cwd
        self.copy_template(cwd)

# Path: googkit/commands/command.py
# class Command(object):
#     """A base class for commands.
#     """
# 
#     def __init__(self, env):
#         """Create a command that depend the specified environment.
#         """
#         self.env = env
#         self.config = None
# 
#     @classmethod
#     def needs_project_config(cls):
#         """Whether this command depend to a project config file.
#         You should override to return True if this command use a project
#         config.
#         """
#         return False
# 
#     @classmethod
#     def supported_options(cls):
#         """Returns a set has supported options by this command.
#         In default, all command should support a --verbose option to display
#         verbose messages.
#         """
#         return set(['--verbose'])
# 
#     def _validate_options(self):
#         opts = set(self.env.argument.options.keys())
#         unsupported_opts = opts - self.__class__.supported_options()
# 
#         if len(unsupported_opts) > 0:
#             raise InvalidOptionError(unsupported_opts)
# 
#     def _load_config(self):
#         default_config = googkit.lib.path.default_config()
#         user_config = googkit.lib.path.user_config()
#         project_config = googkit.lib.path.project_config(self.env.cwd)
# 
#         if project_config is None:
#             raise GoogkitError(_('No config file found.'))
# 
#         config = Config()
#         config.load(project_config, user_config, default_config)
#         return config
# 
#     def _setup(self):
#         if self.__class__.needs_project_config():
#             if self.config is None:
#                 self.config = self._load_config()
# 
#         os.chdir(self.env.cwd)
# 
#     def run(self):
#         """Runs this command.
#         Override run_internal instead of run if you want to implement a new
#         command.
#         """
#         level = logging.DEBUG if self.env.argument.option('--verbose') else None
#         with log_level(level):
#             self._validate_options()
#             self._setup()
#             self.run_internal()
# 
#     def run_internal(self):
#         """Internal method for running command.
#         You can change a command behavior by overriding this method.
#         """
#         pass
# 
# Path: googkit/lib/error.py
# class GoogkitError(Exception):
#     """Base class for error in Googkit."""
# 
#     def __init__(self, message):
#         """Creates a local error of googkit by the specified message.
#         """
#         self._message = message
# 
#     @property
#     def message(self):
#         return self._message
# 
#     def __str__(self):
#         return self.message
# 
# Path: googkit/lib/i18n.py



# Path: googkit/commands/init.py
import distutils.core
import logging
import os
import googkit.lib.path
from googkit.commands.command import Command
from googkit.lib.error import GoogkitError
from googkit.lib.i18n import _



class InitCommand(Command):
    def copy_template(self, dst_dir):
        """Copy template files (include default googkit.cfg, demonstration files) to the specified directory.
        """
        template_dir = googkit.lib.path.template()

        conflicted = set(os.listdir(dst_dir)) & set(os.listdir(template_dir))
        if conflicted:
            raise GoogkitError(_('Conflicted files: {files}').format(
                files=', '.join(conflicted)))

        distutils.dir_util.copy_tree(template_dir, dst_dir)

    def run_internal(self):
        cwd = self.env.cwd
        self.copy_template(cwd)

        logging.info(_('Initialized googkit project in {path}').format(