# 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/dirutil.py
# def working_directory(path='.'):
#     """Change current working directory.
# 
#     >>> import tempfile
#     >>> import os.path
#     >>> base = os.getcwd()
#     >>> temp = tempfile.mkdtemp()
#     >>> with working_directory(temp):
#     ...     assert os.path.samefile(os.getcwd(), temp)
#     ...
#     >>> assert os.path.samefile(os.getcwd(), base)
#     """
#     return CurrentDirectory(path)
# 
# Path: googkit/lib/i18n.py



import glob
import logging
import os
import shutil
import googkit.compat.urllib.request
import googkit.lib.path
import googkit.lib.strutil
from googkit.commands.command import Command
from googkit.lib.dirutil import working_directory
from googkit.lib.i18n import _
        """Set-up a main scripts as an entry point for the user application.
        This script will be generated automatically under the rule:

        #. Search HTML-like documents into development/.
        #. Generate the namespace path from a filename of the document.
        #. Search scripts that are named ``{namespace}.js`` into js_dev/
        #. If some scripts are not found, generate the scripts.
        """
        config = self.config
        devel_dir = config.development_dir()

        html_list = []
        for ext in self.HTML_LIKE_EXT:
            html_list += glob.glob(os.path.join(devel_dir, '*' + ext))

        for html_path in html_list:
            if os.path.abspath(html_path) == os.path.abspath(config.testrunner()):
                continue

            basename = self.namespace_by_html(html_path) + '.js'
            script_path = os.path.join(config.js_dev_dir(), basename)

            if os.path.exists(script_path):
                logging.debug(_('Skip generating the entry point: {path}').format(path=script_path))
                continue

            main_script_template = os.path.join(
                googkit.lib.path.template(), 'development', 'js_dev', 'googkit_index.js')

            shutil.copyfile(main_script_template, script_path)

# 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/dirutil.py
# def working_directory(path='.'):
#     """Change current working directory.
# 
#     >>> import tempfile
#     >>> import os.path
#     >>> base = os.getcwd()
#     >>> temp = tempfile.mkdtemp()
#     >>> with working_directory(temp):
#     ...     assert os.path.samefile(os.getcwd(), temp)
#     ...
#     >>> assert os.path.samefile(os.getcwd(), base)
#     """
#     return CurrentDirectory(path)
# 
# Path: googkit/lib/i18n.py



# Path: googkit/commands/apply_config.py
import glob
import logging
import os
import shutil
import googkit.compat.urllib.request
import googkit.lib.path
import googkit.lib.strutil
from googkit.commands.command import Command
from googkit.lib.dirutil import working_directory
from googkit.lib.i18n import _

        """Set-up a main scripts as an entry point for the user application.
        This script will be generated automatically under the rule:

        #. Search HTML-like documents into development/.
        #. Generate the namespace path from a filename of the document.
        #. Search scripts that are named ``{namespace}.js`` into js_dev/
        #. If some scripts are not found, generate the scripts.
        """
        config = self.config
        devel_dir = config.development_dir()

        html_list = []
        for ext in self.HTML_LIKE_EXT:
            html_list += glob.glob(os.path.join(devel_dir, '*' + ext))

        for html_path in html_list:
            if os.path.abspath(html_path) == os.path.abspath(config.testrunner()):
                continue

            basename = self.namespace_by_html(html_path) + '.js'
            script_path = os.path.join(config.js_dev_dir(), basename)

            if os.path.exists(script_path):
                logging.debug(_('Skip generating the entry point: {path}').format(path=script_path))
                continue

            main_script_template = os.path.join(
                googkit.lib.path.template(), 'development', 'js_dev', 'googkit_index.js')

            shutil.copyfile(main_script_template, script_path)

            logging.debug(_('Generate the entry point: {path}').format(path=script_path))