# Path: percept/management/commands.py
# class BaseCommand(object):
#     """
#     All commands inherit from this class
#     """
#     #Allowed options
#     option_list = (
#         make_option('--settings',
#                     help='The Python path to a settings module, e.g. "myproject.settings.main".'),
#         make_option('--pythonpath',
#                     help='A directory to add to the Python path'),
#     )
#     command_help = ''
#     args = ''
# 
#     def usage(self, subcommand):
#         """
#         Print the usage for a given subcommand
#         """
#         usage = '%%prog %s [options] %s' % (subcommand, self.args)
#         return usage
# 
#     def create_parser(self, prog_name, subcommand):
#         """
#         Create an OptionParser
#         prog_name - Name of a command
#         subcommand - Name of a subcommand
#         """
#         parser = OptionParser(prog=prog_name,
#                               usage=self.usage(subcommand),
#                               option_list=self.option_list)
#         return parser
# 
#     def print_help(self, prog_name, subcommand):
#         """
#         Print the help that the parser generates
#         prog_name - Name of a command
#         subcommand - Name of a subcommand
#         """
#         parser = self.create_parser(prog_name, subcommand)
#         parser.print_help()
# 
#     def run_from_argv(self, argv):
#         """
#         Given certain command line arguments, run the basecommand
#         argv - command line arguments
#         """
#         parser = self.create_parser(argv[0], argv[1])
#         options, args = parser.parse_args(argv[2:])
#         options = handle_default_options(options)
#         self.execute(*args, **options.__dict__)
# 
#     def execute(self, *args, **options):
#         from percept.conf.base import settings
#         self.command(*args, **options)
# 
#     def command(self, *args, **options):
#         """
#         Overridden by the class that inherits from this.  Contains logic to run the command.
#         """
#         raise NotImplementedError()
# 
# Path: percept/conf/base.py
# class Settings(object):
#     def _initialize(self, settings_module):
#     def _setup(self):
#     def __getattr__(self, name):
#     def _configure_logging(self):
#     def configured(self):


from percept.management.commands import BaseCommand
from importlib import import_module
from percept.conf.base import settings
import os
import re

        #Try to create the directory
        project_dir = os.path.join(os.getcwd(), name)
        try:
            os.makedirs(project_dir)
        except OSError:
            raise Exception("Could not make directory {0}".format(project_dir))

        project_template_dir = settings.PROJECT_TEMPLATE_DIR
        prefix_length = len(project_template_dir) + 1

        for root, dirs, files in os.walk(project_template_dir):
            path_end = root[prefix_length:]
            path_end = path_end.replace(settings.PROJECT_TEMPLATE_NAME, name)
            target_dir = os.path.join(project_dir, path_end)
            if not os.path.exists(target_dir):
                os.mkdir(target_dir)

            for dirname in dirs[:]:
                if dirname.startswith('.') or dirname == '__pycache__':
                    dirs.remove(dirname)

            for filename in files:
                if filename.endswith('.pyc'):
                    continue
                old_path = os.path.join(root, filename)
                new_path = os.path.join(project_dir, path_end, filename)

                with open(old_path, 'rb') as template_file:
                    content = template_file.read()

# Path: percept/management/commands.py
# class BaseCommand(object):
#     """
#     All commands inherit from this class
#     """
#     #Allowed options
#     option_list = (
#         make_option('--settings',
#                     help='The Python path to a settings module, e.g. "myproject.settings.main".'),
#         make_option('--pythonpath',
#                     help='A directory to add to the Python path'),
#     )
#     command_help = ''
#     args = ''
# 
#     def usage(self, subcommand):
#         """
#         Print the usage for a given subcommand
#         """
#         usage = '%%prog %s [options] %s' % (subcommand, self.args)
#         return usage
# 
#     def create_parser(self, prog_name, subcommand):
#         """
#         Create an OptionParser
#         prog_name - Name of a command
#         subcommand - Name of a subcommand
#         """
#         parser = OptionParser(prog=prog_name,
#                               usage=self.usage(subcommand),
#                               option_list=self.option_list)
#         return parser
# 
#     def print_help(self, prog_name, subcommand):
#         """
#         Print the help that the parser generates
#         prog_name - Name of a command
#         subcommand - Name of a subcommand
#         """
#         parser = self.create_parser(prog_name, subcommand)
#         parser.print_help()
# 
#     def run_from_argv(self, argv):
#         """
#         Given certain command line arguments, run the basecommand
#         argv - command line arguments
#         """
#         parser = self.create_parser(argv[0], argv[1])
#         options, args = parser.parse_args(argv[2:])
#         options = handle_default_options(options)
#         self.execute(*args, **options.__dict__)
# 
#     def execute(self, *args, **options):
#         from percept.conf.base import settings
#         self.command(*args, **options)
# 
#     def command(self, *args, **options):
#         """
#         Overridden by the class that inherits from this.  Contains logic to run the command.
#         """
#         raise NotImplementedError()
# 
# Path: percept/conf/base.py
# class Settings(object):
#     def _initialize(self, settings_module):
#     def _setup(self):
#     def __getattr__(self, name):
#     def _configure_logging(self):
#     def configured(self):


# Path: percept/workflows/commands/start_project.py
from percept.management.commands import BaseCommand
from importlib import import_module
from percept.conf.base import settings
import os
import re


        #Try to create the directory
        project_dir = os.path.join(os.getcwd(), name)
        try:
            os.makedirs(project_dir)
        except OSError:
            raise Exception("Could not make directory {0}".format(project_dir))

        project_template_dir = settings.PROJECT_TEMPLATE_DIR
        prefix_length = len(project_template_dir) + 1

        for root, dirs, files in os.walk(project_template_dir):
            path_end = root[prefix_length:]
            path_end = path_end.replace(settings.PROJECT_TEMPLATE_NAME, name)
            target_dir = os.path.join(project_dir, path_end)
            if not os.path.exists(target_dir):
                os.mkdir(target_dir)

            for dirname in dirs[:]:
                if dirname.startswith('.') or dirname == '__pycache__':
                    dirs.remove(dirname)

            for filename in files:
                if filename.endswith('.pyc'):
                    continue
                old_path = os.path.join(root, filename)
                new_path = os.path.join(project_dir, path_end, filename)

                with open(old_path, 'rb') as template_file:
                    content = template_file.read()

                    content = content.replace(settings.PROJECT_TEMPLATE_NAME, name)