# Path: starterpyth/cliforms.py
# class BaseForm(object):
# 
#     def __init__(self, initial=None, extra_env=None):
#         super(BaseForm, self).__init__()
#         self.extra_env = {} if extra_env is None else extra_env
#         self.initial = {} if initial is None else initial
# 
#     def read(self, interactive=True):
#         fields = []
#         for key, field in self.__class__.__dict__.items():
#             if isinstance(field, Input):
#                 fields.append((key, field))
#         fields.sort(key=lambda f_: f_[1].order)
#         values = {}
#         extra_env = {}
#         extra_env.update(self.extra_env)
#         for key, field in fields:
#             kwargs = {}
#             show = field.show
#             init_value = self.initial.get(key, field.initial)
#             extra_env.update(values)
#             if hasattr(init_value, '__call__') and not isinstance(init_value, type):
#                 init_value = init_value(**extra_env)
#             if show is not None:
#                 if hasattr(show, '__call__'):
#                     show = show(**extra_env)
#                 if not show:
#                     values[key] = init_value
#                     continue
#             kwargs['initial'] = init_value
#             if interactive:
#                 values[key] = field.read(**kwargs)
#             else:
#                 values[key] = kwargs.get('initial', field.initial)
#         return values
# 
# Path: starterpyth/utils.py
# def binary_path(binary):
#     p = subprocess.Popen(['which', binary], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
#     stdout, __ = p.communicate()
#     x = stdout.decode('utf-8').strip().splitlines()
#     return x[0] if x else None
# 
# def walk(module_name, dirname, topdown=True):
#     """
#     Copy of :func:`os.walk`. Please refer to its doc. The only difference is that we walk in a package_resource
#     instead of a plain directory.
#     :type module_name: basestring
#     :param module_name: module to search in
#     :type dirname: basestring
#     :param dirname: base directory
#     :type topdown: bool
#     :param topdown: if True, perform a topdown search.
#     """
#     def rec_walk(root):
#         """
#         Recursively list subdirectories and filenames from the root.
#         :param root: the root path
#         :type root: basestring
#         """
#         dirnames = []
#         filenames = []
#         for name in pkg_resources.resource_listdir(module_name, root):
#             fullname = root + '/' + name
#             isdir = pkg_resources.resource_isdir(module_name, fullname)
#             if isdir:
#                 dirnames.append(name)
#                 if not topdown:
#                     rec_walk(fullname)
#             else:
#                 filenames.append(name)
#         yield root, dirnames, filenames
#         if topdown:
#             for name in dirnames:
#                 for values in rec_walk(root + '/' + name):
#                     yield values
#     return rec_walk(dirname)
# 
# Path: starterpyth/log.py
# def display(text, color=None, bold=False, newline=True):
#     if not isinstance(text, text_type):
#         text = text.decode('utf-8')
#     if bold and color:
#         text = u("\033[1;{0}m{1}\033[0m").format(color, text)
#     text = u("\033[{0}m{1}\033[0m").format(color, text)
#     if newline:
#         text += u('\n')
#     end = u('')
#     if __encode_stdout:
#         text = text.encode('utf-8')
#         end = b('')
#     print_(text, end=end)
# 
# GREEN = '32'
# 
# CYAN = '36'
# 
# RED = '31'
# 
# Path: starterpyth/translation.py
# def __find(domain, locale_module, localedir='locale', languages=None):
# def translation(domain, locale_module, localedir='locale', languages=None, class_=None, fallback=False):
# __TRANS = translation(parent_package, parent_package, fallback=True)


import datetime
import os
import shutil
import subprocess
import pkg_resources
    import doctest
from jinja2 import ChoiceLoader
from six import u
from starterpyth.cliforms import BaseForm
from starterpyth.utils import binary_path, walk
from starterpyth.log import display, GREEN, CYAN, RED
from starterpyth.translation import ugettext as _
        from jinja2 import Environment, PackageLoader
        from jinja2 import Template
        """

        project_root = self.global_context['project_root']
        # creation of the project directory if needed
        if not os.path.isdir(project_root):
            os.makedirs(project_root)
            display(_('Directory %(f)s created.') % {'f': project_root}, color=GREEN)
        # noinspection PyTypeChecker
        prefix_len = len(dirname) + 1

        def get_path(root_, name):
            """return relative source path (to template dir) and absolute destination path"""
            src_path_ = (root_ + '/' + name)[prefix_len:]
            dst_path_ = src_path_
            if os.sep != '/':
                dst_path_ = dst_path_.replace('/', os.sep)
            if dst_path_.find('{') > -1:  # the name of the file is templated
                dst_path_ = Template(dst_path_).render(**self.global_context)
            if dst_path_[-len(self.template_suffix):] == self.template_suffix:
                dst_path_ = dst_path_[:-len(self.template_suffix)]
            return src_path_, os.path.join(project_root, dst_path_)

        # walk through all files (raw and templates) in modname/dirname and write them to destination
        for root, dirnames, filenames in walk(modname, dirname):
            for dirname in dirnames:
                src_path, dst_path = get_path(root, dirname)
                if not self.process_directory_or_file(src_path, dst_path, dirname, True):
                    continue
                if not os.path.isdir(dst_path):
                    os.makedirs(dst_path)

# Path: starterpyth/cliforms.py
# class BaseForm(object):
# 
#     def __init__(self, initial=None, extra_env=None):
#         super(BaseForm, self).__init__()
#         self.extra_env = {} if extra_env is None else extra_env
#         self.initial = {} if initial is None else initial
# 
#     def read(self, interactive=True):
#         fields = []
#         for key, field in self.__class__.__dict__.items():
#             if isinstance(field, Input):
#                 fields.append((key, field))
#         fields.sort(key=lambda f_: f_[1].order)
#         values = {}
#         extra_env = {}
#         extra_env.update(self.extra_env)
#         for key, field in fields:
#             kwargs = {}
#             show = field.show
#             init_value = self.initial.get(key, field.initial)
#             extra_env.update(values)
#             if hasattr(init_value, '__call__') and not isinstance(init_value, type):
#                 init_value = init_value(**extra_env)
#             if show is not None:
#                 if hasattr(show, '__call__'):
#                     show = show(**extra_env)
#                 if not show:
#                     values[key] = init_value
#                     continue
#             kwargs['initial'] = init_value
#             if interactive:
#                 values[key] = field.read(**kwargs)
#             else:
#                 values[key] = kwargs.get('initial', field.initial)
#         return values
# 
# Path: starterpyth/utils.py
# def binary_path(binary):
#     p = subprocess.Popen(['which', binary], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
#     stdout, __ = p.communicate()
#     x = stdout.decode('utf-8').strip().splitlines()
#     return x[0] if x else None
# 
# def walk(module_name, dirname, topdown=True):
#     """
#     Copy of :func:`os.walk`. Please refer to its doc. The only difference is that we walk in a package_resource
#     instead of a plain directory.
#     :type module_name: basestring
#     :param module_name: module to search in
#     :type dirname: basestring
#     :param dirname: base directory
#     :type topdown: bool
#     :param topdown: if True, perform a topdown search.
#     """
#     def rec_walk(root):
#         """
#         Recursively list subdirectories and filenames from the root.
#         :param root: the root path
#         :type root: basestring
#         """
#         dirnames = []
#         filenames = []
#         for name in pkg_resources.resource_listdir(module_name, root):
#             fullname = root + '/' + name
#             isdir = pkg_resources.resource_isdir(module_name, fullname)
#             if isdir:
#                 dirnames.append(name)
#                 if not topdown:
#                     rec_walk(fullname)
#             else:
#                 filenames.append(name)
#         yield root, dirnames, filenames
#         if topdown:
#             for name in dirnames:
#                 for values in rec_walk(root + '/' + name):
#                     yield values
#     return rec_walk(dirname)
# 
# Path: starterpyth/log.py
# def display(text, color=None, bold=False, newline=True):
#     if not isinstance(text, text_type):
#         text = text.decode('utf-8')
#     if bold and color:
#         text = u("\033[1;{0}m{1}\033[0m").format(color, text)
#     text = u("\033[{0}m{1}\033[0m").format(color, text)
#     if newline:
#         text += u('\n')
#     end = u('')
#     if __encode_stdout:
#         text = text.encode('utf-8')
#         end = b('')
#     print_(text, end=end)
# 
# GREEN = '32'
# 
# CYAN = '36'
# 
# RED = '31'
# 
# Path: starterpyth/translation.py
# def __find(domain, locale_module, localedir='locale', languages=None):
# def translation(domain, locale_module, localedir='locale', languages=None, class_=None, fallback=False):
# __TRANS = translation(parent_package, parent_package, fallback=True)


# Path: starterpyth/model.py
import datetime
import os
import shutil
import subprocess
import pkg_resources
    import doctest
from jinja2 import ChoiceLoader
from six import u
from starterpyth.cliforms import BaseForm
from starterpyth.utils import binary_path, walk
from starterpyth.log import display, GREEN, CYAN, RED
from starterpyth.translation import ugettext as _
        from jinja2 import Environment, PackageLoader
        from jinja2 import Template

        """

        project_root = self.global_context['project_root']
        # creation of the project directory if needed
        if not os.path.isdir(project_root):
            os.makedirs(project_root)
            display(_('Directory %(f)s created.') % {'f': project_root}, color=GREEN)
        # noinspection PyTypeChecker
        prefix_len = len(dirname) + 1

        def get_path(root_, name):
            """return relative source path (to template dir) and absolute destination path"""
            src_path_ = (root_ + '/' + name)[prefix_len:]
            dst_path_ = src_path_
            if os.sep != '/':
                dst_path_ = dst_path_.replace('/', os.sep)
            if dst_path_.find('{') > -1:  # the name of the file is templated
                dst_path_ = Template(dst_path_).render(**self.global_context)
            if dst_path_[-len(self.template_suffix):] == self.template_suffix:
                dst_path_ = dst_path_[:-len(self.template_suffix)]
            return src_path_, os.path.join(project_root, dst_path_)

        # walk through all files (raw and templates) in modname/dirname and write them to destination
        for root, dirnames, filenames in walk(modname, dirname):
            for dirname in dirnames:
                src_path, dst_path = get_path(root, dirname)
                if not self.process_directory_or_file(src_path, dst_path, dirname, True):
                    continue
                if not os.path.isdir(dst_path):
                    os.makedirs(dst_path)

                    display(_('Directory %(f)s created.') % {'f': dst_path}, color=GREEN)