mirror of
https://github.com/django/django.git
synced 2025-10-27 15:46:10 +00:00
Converted remaining management commands to argparse
This commit is contained in:
@@ -2,7 +2,6 @@ from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
from collections import OrderedDict
|
||||
from optparse import make_option
|
||||
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.core.management.base import CommandError, NoArgsCommand
|
||||
@@ -18,32 +17,6 @@ class Command(NoArgsCommand):
|
||||
Command that allows to copy or symlink static files from different
|
||||
locations to the settings.STATIC_ROOT.
|
||||
"""
|
||||
option_list = NoArgsCommand.option_list + (
|
||||
make_option('--noinput',
|
||||
action='store_false', dest='interactive', default=True,
|
||||
help="Do NOT prompt the user for input of any kind."),
|
||||
make_option('--no-post-process',
|
||||
action='store_false', dest='post_process', default=True,
|
||||
help="Do NOT post process collected files."),
|
||||
make_option('-i', '--ignore', action='append', default=[],
|
||||
dest='ignore_patterns', metavar='PATTERN',
|
||||
help="Ignore files or directories matching this glob-style "
|
||||
"pattern. Use multiple times to ignore more."),
|
||||
make_option('-n', '--dry-run',
|
||||
action='store_true', dest='dry_run', default=False,
|
||||
help="Do everything except modify the filesystem."),
|
||||
make_option('-c', '--clear',
|
||||
action='store_true', dest='clear', default=False,
|
||||
help="Clear the existing files using the storage "
|
||||
"before trying to copy or link the original file."),
|
||||
make_option('-l', '--link',
|
||||
action='store_true', dest='link', default=False,
|
||||
help="Create a symbolic link to each file instead of copying."),
|
||||
make_option('--no-default-ignore', action='store_false',
|
||||
dest='use_default_ignore_patterns', default=True,
|
||||
help="Don't ignore the common private glob-style patterns 'CVS', "
|
||||
"'.*' and '*~'."),
|
||||
)
|
||||
help = "Collect static files in a single location."
|
||||
requires_system_checks = False
|
||||
|
||||
@@ -61,12 +34,38 @@ class Command(NoArgsCommand):
|
||||
else:
|
||||
self.local = True
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--noinput',
|
||||
action='store_false', dest='interactive', default=True,
|
||||
help="Do NOT prompt the user for input of any kind.")
|
||||
parser.add_argument('--no-post-process',
|
||||
action='store_false', dest='post_process', default=True,
|
||||
help="Do NOT post process collected files.")
|
||||
parser.add_argument('-i', '--ignore', action='append', default=[],
|
||||
dest='ignore_patterns', metavar='PATTERN',
|
||||
help="Ignore files or directories matching this glob-style "
|
||||
"pattern. Use multiple times to ignore more.")
|
||||
parser.add_argument('-n', '--dry-run',
|
||||
action='store_true', dest='dry_run', default=False,
|
||||
help="Do everything except modify the filesystem.")
|
||||
parser.add_argument('-c', '--clear',
|
||||
action='store_true', dest='clear', default=False,
|
||||
help="Clear the existing files using the storage "
|
||||
"before trying to copy or link the original file.")
|
||||
parser.add_argument('-l', '--link',
|
||||
action='store_true', dest='link', default=False,
|
||||
help="Create a symbolic link to each file instead of copying.")
|
||||
parser.add_argument('--no-default-ignore', action='store_false',
|
||||
dest='use_default_ignore_patterns', default=True,
|
||||
help="Don't ignore the common private glob-style patterns 'CVS', "
|
||||
"'.*' and '*~'.")
|
||||
|
||||
def set_options(self, **options):
|
||||
"""
|
||||
Set instance variables based on an options dict
|
||||
"""
|
||||
self.interactive = options['interactive']
|
||||
self.verbosity = int(options.get('verbosity', 1))
|
||||
self.verbosity = options['verbosity']
|
||||
self.symlink = options['link']
|
||||
self.clear = options['clear']
|
||||
self.dry_run = options['dry_run']
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
from optparse import make_option
|
||||
from django.core.management.base import LabelCommand
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
@@ -10,15 +9,16 @@ from django.contrib.staticfiles import finders
|
||||
|
||||
class Command(LabelCommand):
|
||||
help = "Finds the absolute paths for the given static file(s)."
|
||||
args = "[file ...]"
|
||||
label = 'static file'
|
||||
option_list = LabelCommand.option_list + (
|
||||
make_option('--first', action='store_false', dest='all', default=True,
|
||||
help="Only return the first match for each static file."),
|
||||
)
|
||||
|
||||
def add_arguments(self, parser):
|
||||
super(Command, self).add_arguments(parser)
|
||||
parser.add_argument('--first', action='store_false', dest='all',
|
||||
default=True,
|
||||
help="Only return the first match for each static file.")
|
||||
|
||||
def handle_label(self, path, **options):
|
||||
verbosity = int(options.get('verbosity', 1))
|
||||
verbosity = options['verbosity']
|
||||
result = finders.find(path, all=options['all'])
|
||||
path = force_text(path)
|
||||
if verbosity >= 2:
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from optparse import make_option
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management.commands.runserver import Command as RunserverCommand
|
||||
|
||||
@@ -7,14 +5,15 @@ from django.contrib.staticfiles.handlers import StaticFilesHandler
|
||||
|
||||
|
||||
class Command(RunserverCommand):
|
||||
option_list = RunserverCommand.option_list + (
|
||||
make_option('--nostatic', action="store_false", dest='use_static_handler', default=True,
|
||||
help='Tells Django to NOT automatically serve static files at STATIC_URL.'),
|
||||
make_option('--insecure', action="store_true", dest='insecure_serving', default=False,
|
||||
help='Allows serving static files even if DEBUG is False.'),
|
||||
)
|
||||
help = "Starts a lightweight Web server for development and also serves static files."
|
||||
|
||||
def add_arguments(self, parser):
|
||||
super(Command, self).add_arguments(parser)
|
||||
parser.add_argument('--nostatic', action="store_false", dest='use_static_handler', default=True,
|
||||
help='Tells Django to NOT automatically serve static files at STATIC_URL.')
|
||||
parser.add_argument('--insecure', action="store_true", dest='insecure_serving', default=False,
|
||||
help='Allows serving static files even if DEBUG is False.')
|
||||
|
||||
def get_handler(self, *args, **options):
|
||||
"""
|
||||
Returns the static files serving handler wrapping the default handler,
|
||||
|
||||
Reference in New Issue
Block a user