summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorsage <laymonage@gmail.com>2021-07-24 07:09:03 +0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-09-01 12:08:02 +0200
commit84c7c4a477eae5de394d036d7ba1e58a37e18b69 (patch)
tree226181586fa7134a6674517105c0699e0314615f /django
parent3686077d463685d383e14b4695eaaa2658919a42 (diff)
Fixed #32309 -- Added --exclude option to startapp/startproject management commands.
Diffstat (limited to 'django')
-rw-r--r--django/core/management/templates.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/django/core/management/templates.py b/django/core/management/templates.py
index 8607ca8542..976442021e 100644
--- a/django/core/management/templates.py
+++ b/django/core/management/templates.py
@@ -1,3 +1,4 @@
+import argparse
import cgi
import mimetypes
import os
@@ -54,6 +55,14 @@ class TemplateCommand(BaseCommand):
help='The file name(s) to render. Separate multiple file names '
'with commas, or use -n multiple times.'
)
+ parser.add_argument(
+ '--exclude', '-x',
+ action='append', default=argparse.SUPPRESS, nargs='?', const='',
+ help=(
+ 'The directory name(s) to exclude, in addition to .git and '
+ '__pycache__. Can be used multiple times.'
+ ),
+ )
def handle(self, app_or_project, name, target=None, **options):
self.app_or_project = app_or_project
@@ -82,8 +91,12 @@ class TemplateCommand(BaseCommand):
extensions = tuple(handle_extensions(options['extensions']))
extra_files = []
+ excluded_directories = ['.git', '__pycache__']
for file in options['files']:
extra_files.extend(map(lambda x: x.strip(), file.split(',')))
+ if exclude := options.get('exclude'):
+ for directory in exclude:
+ excluded_directories.append(directory.strip())
if self.verbosity >= 2:
self.stdout.write(
'Rendering %s template files with extensions: %s'
@@ -126,7 +139,10 @@ class TemplateCommand(BaseCommand):
os.makedirs(target_dir, exist_ok=True)
for dirname in dirs[:]:
- if dirname.startswith('.') or dirname == '__pycache__':
+ if 'exclude' not in options:
+ if dirname.startswith('.') or dirname == '__pycache__':
+ dirs.remove(dirname)
+ elif dirname in excluded_directories:
dirs.remove(dirname)
for filename in files: