def handle(self, *args, **options): if len(args) != 1: raise CommandError('Indicate the folder name for the app.') no_prompt = options.get('no_prompt', False) app_dir = options['template_dir'] project_folder = args[0] # 1. Copy the <name>/apps into apps/<name> copy_from = os.path.join(app_dir, 'apps') copy_to = os.path.join('apps', project_folder) copytree(copy_from, copy_to) # 1. Copy the <name>/templates into templates/<name> copy_from = os.path.join(app_dir, 'templates') copy_to = os.path.join('templates', project_folder) copytree(copy_from, copy_to) # 2. If template has a settings file, run its after_copy method settings_path = os.path.join(app_dir, 'django_start_settings.py') if os.path.exists(settings_path): sys.path.append(app_dir) import django_start_settings reload(django_start_settings) if callable(getattr(django_start_settings, 'after_copy', None)): # Don't change current directory (there are two in this case) django_start_settings.after_copy(project_folder=project_folder, no_prompt=no_prompt) sys.path.remove(app_dir)
def handle(self, *args, **options): if len(args) != 1: raise CommandError('Indicate the folder name for the project.') # 1. Copy the template folder copy_from = options['template_dir'] copy_to = args[0] copytree(copy_from, copy_to, ignore=ignore_patterns('django_start*',)) # 2. If template has a settings file, run its after_copy method settings_path = os.path.join(copy_from, 'django_start_settings.py') if os.path.exists(settings_path): sys.path.append(copy_from) import django_start_settings if callable(getattr(django_start_settings, 'after_copy', None)): # First change current directory to copy_to os.chdir(copy_to) no_prompt = options.get('no_prompt', False) django_start_settings.after_copy(no_prompt=no_prompt)