Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
9996158d
Kaydet (Commit)
9996158d
authored
Haz 17, 2014
tarafından
Maxime Turcotte
Kaydeden (comit)
Tim Graham
Haz 19, 2014
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #22835 -- Deprecated NoArgsCommand.
üst
63670a47
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
94 additions
and
69 deletions
+94
-69
clearsessions.py
django/contrib/sessions/management/commands/clearsessions.py
+3
-3
collectstatic.py
.../contrib/staticfiles/management/commands/collectstatic.py
+7
-5
base.py
django/core/management/base.py
+8
-0
diffsettings.py
django/core/management/commands/diffsettings.py
+3
-3
flush.py
django/core/management/commands/flush.py
+3
-3
inspectdb.py
django/core/management/commands/inspectdb.py
+3
-3
makemessages.py
django/core/management/commands/makemessages.py
+3
-3
shell.py
django/core/management/commands/shell.py
+3
-3
sqlflush.py
django/core/management/commands/sqlflush.py
+3
-3
syncdb.py
django/core/management/commands/syncdb.py
+3
-3
validate.py
django/core/management/commands/validate.py
+2
-2
custom-management-commands.txt
docs/howto/custom-management-commands.txt
+6
-2
deprecation.txt
docs/internals/deprecation.txt
+4
-0
1.8.txt
docs/releases/1.8.txt
+7
-0
duplicate.py
...dmin_scripts/complex_app/management/commands/duplicate.py
+3
-3
color_command.py
tests/admin_scripts/management/commands/color_command.py
+3
-3
noargs_command.py
tests/admin_scripts/management/commands/noargs_command.py
+4
-4
validation_command.py
...s/admin_scripts/management/commands/validation_command.py
+3
-3
duplicate.py
...admin_scripts/simple_app/management/commands/duplicate.py
+3
-3
tests.py
tests/admin_scripts/tests.py
+20
-20
No files found.
django/contrib/sessions/management/commands/clearsessions.py
Dosyayı görüntüle @
9996158d
from
importlib
import
import_module
from
importlib
import
import_module
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.management.base
import
NoArgs
Command
from
django.core.management.base
import
Base
Command
class
Command
(
NoArgs
Command
):
class
Command
(
Base
Command
):
help
=
"Can be run as a cronjob or directly to clean out expired sessions (only with the database backend at the moment)."
help
=
"Can be run as a cronjob or directly to clean out expired sessions (only with the database backend at the moment)."
def
handle
_noargs
(
self
,
**
options
):
def
handle
(
self
,
**
options
):
engine
=
import_module
(
settings
.
SESSION_ENGINE
)
engine
=
import_module
(
settings
.
SESSION_ENGINE
)
try
:
try
:
engine
.
SessionStore
.
clear_expired
()
engine
.
SessionStore
.
clear_expired
()
...
...
django/contrib/staticfiles/management/commands/collectstatic.py
Dosyayı görüntüle @
9996158d
...
@@ -4,7 +4,8 @@ import os
...
@@ -4,7 +4,8 @@ import os
from
collections
import
OrderedDict
from
collections
import
OrderedDict
from
django.core.files.storage
import
FileSystemStorage
from
django.core.files.storage
import
FileSystemStorage
from
django.core.management.base
import
CommandError
,
NoArgsCommand
from
django.core.management.base
import
CommandError
,
BaseCommand
from
django.core.management.color
import
no_style
from
django.utils.encoding
import
smart_text
from
django.utils.encoding
import
smart_text
from
django.utils.six.moves
import
input
from
django.utils.six.moves
import
input
...
@@ -12,7 +13,7 @@ from django.contrib.staticfiles.finders import get_finders
...
@@ -12,7 +13,7 @@ from django.contrib.staticfiles.finders import get_finders
from
django.contrib.staticfiles.storage
import
staticfiles_storage
from
django.contrib.staticfiles.storage
import
staticfiles_storage
class
Command
(
NoArgs
Command
):
class
Command
(
Base
Command
):
"""
"""
Command that allows to copy or symlink static files from different
Command that allows to copy or symlink static files from different
locations to the settings.STATIC_ROOT.
locations to the settings.STATIC_ROOT.
...
@@ -21,12 +22,13 @@ class Command(NoArgsCommand):
...
@@ -21,12 +22,13 @@ class Command(NoArgsCommand):
requires_system_checks
=
False
requires_system_checks
=
False
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
NoArgs
Command
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
Base
Command
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
copied_files
=
[]
self
.
copied_files
=
[]
self
.
symlinked_files
=
[]
self
.
symlinked_files
=
[]
self
.
unmodified_files
=
[]
self
.
unmodified_files
=
[]
self
.
post_processed_files
=
[]
self
.
post_processed_files
=
[]
self
.
storage
=
staticfiles_storage
self
.
storage
=
staticfiles_storage
self
.
style
=
no_style
()
try
:
try
:
self
.
storage
.
path
(
''
)
self
.
storage
.
path
(
''
)
except
NotImplementedError
:
except
NotImplementedError
:
...
@@ -79,7 +81,7 @@ class Command(NoArgsCommand):
...
@@ -79,7 +81,7 @@ class Command(NoArgsCommand):
"""
"""
Perform the bulk of the work of collectstatic.
Perform the bulk of the work of collectstatic.
Split off from handle
_noargs
() to facilitate testing.
Split off from handle() to facilitate testing.
"""
"""
if
self
.
symlink
and
not
self
.
local
:
if
self
.
symlink
and
not
self
.
local
:
raise
CommandError
(
"Can't symlink to a remote destination."
)
raise
CommandError
(
"Can't symlink to a remote destination."
)
...
@@ -130,7 +132,7 @@ class Command(NoArgsCommand):
...
@@ -130,7 +132,7 @@ class Command(NoArgsCommand):
'post_processed'
:
self
.
post_processed_files
,
'post_processed'
:
self
.
post_processed_files
,
}
}
def
handle
_noargs
(
self
,
**
options
):
def
handle
(
self
,
**
options
):
self
.
set_options
(
**
options
)
self
.
set_options
(
**
options
)
message
=
[
'
\n
'
]
message
=
[
'
\n
'
]
...
...
django/core/management/base.py
Dosyayı görüntüle @
9996158d
...
@@ -603,6 +603,14 @@ class NoArgsCommand(BaseCommand):
...
@@ -603,6 +603,14 @@ class NoArgsCommand(BaseCommand):
"""
"""
args
=
''
args
=
''
def
__init__
(
self
):
warnings
.
warn
(
"NoArgsCommand class is deprecated and will be removed in Django 2.0. "
"Use BaseCommand instead, which takes no arguments by default."
,
RemovedInDjango20Warning
)
super
(
NoArgsCommand
,
self
)
.
__init__
()
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
if
args
:
if
args
:
raise
CommandError
(
"Command doesn't accept any arguments"
)
raise
CommandError
(
"Command doesn't accept any arguments"
)
...
...
django/core/management/commands/diffsettings.py
Dosyayı görüntüle @
9996158d
from
django.core.management.base
import
NoArgs
Command
from
django.core.management.base
import
Base
Command
def
module_to_dict
(
module
,
omittable
=
lambda
k
:
k
.
startswith
(
'_'
)):
def
module_to_dict
(
module
,
omittable
=
lambda
k
:
k
.
startswith
(
'_'
)):
...
@@ -6,7 +6,7 @@ def module_to_dict(module, omittable=lambda k: k.startswith('_')):
...
@@ -6,7 +6,7 @@ def module_to_dict(module, omittable=lambda k: k.startswith('_')):
return
dict
((
k
,
repr
(
v
))
for
k
,
v
in
module
.
__dict__
.
items
()
if
not
omittable
(
k
))
return
dict
((
k
,
repr
(
v
))
for
k
,
v
in
module
.
__dict__
.
items
()
if
not
omittable
(
k
))
class
Command
(
NoArgs
Command
):
class
Command
(
Base
Command
):
help
=
"""Displays differences between the current settings.py and Django's
help
=
"""Displays differences between the current settings.py and Django's
default settings. Settings that don't appear in the defaults are
default settings. Settings that don't appear in the defaults are
followed by "###"."""
followed by "###"."""
...
@@ -18,7 +18,7 @@ class Command(NoArgsCommand):
...
@@ -18,7 +18,7 @@ class Command(NoArgsCommand):
help
=
'Display all settings, regardless of their value. '
help
=
'Display all settings, regardless of their value. '
'Default values are prefixed by "###".'
)
'Default values are prefixed by "###".'
)
def
handle
_noargs
(
self
,
**
options
):
def
handle
(
self
,
**
options
):
# Inspired by Postfix's "postconf -n".
# Inspired by Postfix's "postconf -n".
from
django.conf
import
settings
,
global_settings
from
django.conf
import
settings
,
global_settings
...
...
django/core/management/commands/flush.py
Dosyayı görüntüle @
9996158d
...
@@ -4,14 +4,14 @@ from importlib import import_module
...
@@ -4,14 +4,14 @@ from importlib import import_module
from
django.apps
import
apps
from
django.apps
import
apps
from
django.db
import
connections
,
router
,
transaction
,
DEFAULT_DB_ALIAS
from
django.db
import
connections
,
router
,
transaction
,
DEFAULT_DB_ALIAS
from
django.core.management
import
call_command
from
django.core.management
import
call_command
from
django.core.management.base
import
NoArgs
Command
,
CommandError
from
django.core.management.base
import
Base
Command
,
CommandError
from
django.core.management.color
import
no_style
from
django.core.management.color
import
no_style
from
django.core.management.sql
import
sql_flush
,
emit_post_migrate_signal
from
django.core.management.sql
import
sql_flush
,
emit_post_migrate_signal
from
django.utils.six.moves
import
input
from
django.utils.six.moves
import
input
from
django.utils
import
six
from
django.utils
import
six
class
Command
(
NoArgs
Command
):
class
Command
(
Base
Command
):
help
=
(
'Removes ALL DATA from the database, including data added during '
help
=
(
'Removes ALL DATA from the database, including data added during '
'migrations. Unmigrated apps will also have their initial_data '
'migrations. Unmigrated apps will also have their initial_data '
'fixture reloaded. Does not achieve a "fresh install" state.'
)
'fixture reloaded. Does not achieve a "fresh install" state.'
)
...
@@ -26,7 +26,7 @@ class Command(NoArgsCommand):
...
@@ -26,7 +26,7 @@ class Command(NoArgsCommand):
dest
=
'load_initial_data'
,
default
=
True
,
dest
=
'load_initial_data'
,
default
=
True
,
help
=
'Tells Django not to load any initial data after database synchronization.'
)
help
=
'Tells Django not to load any initial data after database synchronization.'
)
def
handle
_noargs
(
self
,
**
options
):
def
handle
(
self
,
**
options
):
database
=
options
.
get
(
'database'
)
database
=
options
.
get
(
'database'
)
connection
=
connections
[
database
]
connection
=
connections
[
database
]
verbosity
=
options
.
get
(
'verbosity'
)
verbosity
=
options
.
get
(
'verbosity'
)
...
...
django/core/management/commands/inspectdb.py
Dosyayı görüntüle @
9996158d
...
@@ -4,11 +4,11 @@ from collections import OrderedDict
...
@@ -4,11 +4,11 @@ from collections import OrderedDict
import
keyword
import
keyword
import
re
import
re
from
django.core.management.base
import
NoArgs
Command
,
CommandError
from
django.core.management.base
import
Base
Command
,
CommandError
from
django.db
import
connections
,
DEFAULT_DB_ALIAS
from
django.db
import
connections
,
DEFAULT_DB_ALIAS
class
Command
(
NoArgs
Command
):
class
Command
(
Base
Command
):
help
=
"Introspects the database tables in the given database and outputs a Django model module."
help
=
"Introspects the database tables in the given database and outputs a Django model module."
requires_system_checks
=
False
requires_system_checks
=
False
...
@@ -20,7 +20,7 @@ class Command(NoArgsCommand):
...
@@ -20,7 +20,7 @@ class Command(NoArgsCommand):
default
=
DEFAULT_DB_ALIAS
,
help
=
'Nominates a database to '
default
=
DEFAULT_DB_ALIAS
,
help
=
'Nominates a database to '
'introspect. Defaults to using the "default" database.'
)
'introspect. Defaults to using the "default" database.'
)
def
handle
_noargs
(
self
,
**
options
):
def
handle
(
self
,
**
options
):
try
:
try
:
for
line
in
self
.
handle_inspection
(
options
):
for
line
in
self
.
handle_inspection
(
options
):
self
.
stdout
.
write
(
"
%
s
\n
"
%
line
)
self
.
stdout
.
write
(
"
%
s
\n
"
%
line
)
...
...
django/core/management/commands/makemessages.py
Dosyayı görüntüle @
9996158d
...
@@ -9,7 +9,7 @@ import sys
...
@@ -9,7 +9,7 @@ import sys
from
itertools
import
dropwhile
from
itertools
import
dropwhile
import
django
import
django
from
django.core.management.base
import
CommandError
,
NoArgs
Command
from
django.core.management.base
import
CommandError
,
Base
Command
from
django.core.management.utils
import
(
handle_extensions
,
find_command
,
from
django.core.management.utils
import
(
handle_extensions
,
find_command
,
popen_wrapper
)
popen_wrapper
)
from
django.utils.encoding
import
force_str
from
django.utils.encoding
import
force_str
...
@@ -162,7 +162,7 @@ def write_pot_file(potfile, msgs):
...
@@ -162,7 +162,7 @@ def write_pot_file(potfile, msgs):
fp
.
write
(
msgs
)
fp
.
write
(
msgs
)
class
Command
(
NoArgs
Command
):
class
Command
(
Base
Command
):
help
=
(
"Runs over the entire source tree of the current directory and "
help
=
(
"Runs over the entire source tree of the current directory and "
"pulls out all strings marked for translation. It creates (or updates) a message "
"pulls out all strings marked for translation. It creates (or updates) a message "
"file in the conf/locale (in the django tree) or locale (for projects and "
"file in the conf/locale (in the django tree) or locale (for projects and "
...
@@ -210,7 +210,7 @@ class Command(NoArgsCommand):
...
@@ -210,7 +210,7 @@ class Command(NoArgsCommand):
parser
.
add_argument
(
'--keep-pot'
,
action
=
'store_true'
,
dest
=
'keep_pot'
,
parser
.
add_argument
(
'--keep-pot'
,
action
=
'store_true'
,
dest
=
'keep_pot'
,
default
=
False
,
help
=
"Keep .pot file after making messages. Useful when debugging."
)
default
=
False
,
help
=
"Keep .pot file after making messages. Useful when debugging."
)
def
handle
_noargs
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
locale
=
options
.
get
(
'locale'
)
locale
=
options
.
get
(
'locale'
)
exclude
=
options
.
get
(
'exclude'
)
exclude
=
options
.
get
(
'exclude'
)
self
.
domain
=
options
.
get
(
'domain'
)
self
.
domain
=
options
.
get
(
'domain'
)
...
...
django/core/management/commands/shell.py
Dosyayı görüntüle @
9996158d
import
os
import
os
from
django.core.management.base
import
NoArgs
Command
from
django.core.management.base
import
Base
Command
class
Command
(
NoArgs
Command
):
class
Command
(
Base
Command
):
help
=
"Runs a Python interactive interpreter. Tries to use IPython or bpython, if one of them is available."
help
=
"Runs a Python interactive interpreter. Tries to use IPython or bpython, if one of them is available."
requires_system_checks
=
False
requires_system_checks
=
False
shells
=
[
'ipython'
,
'bpython'
]
shells
=
[
'ipython'
,
'bpython'
]
...
@@ -60,7 +60,7 @@ class Command(NoArgsCommand):
...
@@ -60,7 +60,7 @@ class Command(NoArgsCommand):
pass
pass
raise
ImportError
raise
ImportError
def
handle
_noargs
(
self
,
**
options
):
def
handle
(
self
,
**
options
):
try
:
try
:
if
options
[
'plain'
]:
if
options
[
'plain'
]:
# Don't bother loading IPython, because the user wants plain Python.
# Don't bother loading IPython, because the user wants plain Python.
...
...
django/core/management/commands/sqlflush.py
Dosyayı görüntüle @
9996158d
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.core.management.base
import
NoArgs
Command
from
django.core.management.base
import
Base
Command
from
django.core.management.sql
import
sql_flush
from
django.core.management.sql
import
sql_flush
from
django.db
import
connections
,
DEFAULT_DB_ALIAS
from
django.db
import
connections
,
DEFAULT_DB_ALIAS
class
Command
(
NoArgs
Command
):
class
Command
(
Base
Command
):
help
=
"Returns a list of the SQL statements required to return all tables in the database to the state they were in just after they were installed."
help
=
"Returns a list of the SQL statements required to return all tables in the database to the state they were in just after they were installed."
output_transaction
=
True
output_transaction
=
True
...
@@ -16,5 +16,5 @@ class Command(NoArgsCommand):
...
@@ -16,5 +16,5 @@ class Command(NoArgsCommand):
help
=
'Nominates a database to print the SQL for. Defaults to the '
help
=
'Nominates a database to print the SQL for. Defaults to the '
'"default" database.'
)
'"default" database.'
)
def
handle
_noargs
(
self
,
**
options
):
def
handle
(
self
,
**
options
):
return
'
\n
'
.
join
(
sql_flush
(
self
.
style
,
connections
[
options
[
'database'
]],
only_django
=
True
))
return
'
\n
'
.
join
(
sql_flush
(
self
.
style
,
connections
[
options
[
'database'
]],
only_django
=
True
))
django/core/management/commands/syncdb.py
Dosyayı görüntüle @
9996158d
...
@@ -4,12 +4,12 @@ from django.apps import apps
...
@@ -4,12 +4,12 @@ from django.apps import apps
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth
import
get_user_model
from
django.db
import
DEFAULT_DB_ALIAS
from
django.db
import
DEFAULT_DB_ALIAS
from
django.core.management
import
call_command
from
django.core.management
import
call_command
from
django.core.management.base
import
NoArgs
Command
from
django.core.management.base
import
Base
Command
from
django.utils.deprecation
import
RemovedInDjango19Warning
from
django.utils.deprecation
import
RemovedInDjango19Warning
from
django.utils.six.moves
import
input
from
django.utils.six.moves
import
input
class
Command
(
NoArgs
Command
):
class
Command
(
Base
Command
):
help
=
"Deprecated - use 'migrate' instead."
help
=
"Deprecated - use 'migrate' instead."
def
add_arguments
(
self
,
parser
):
def
add_arguments
(
self
,
parser
):
...
@@ -20,7 +20,7 @@ class Command(NoArgsCommand):
...
@@ -20,7 +20,7 @@ class Command(NoArgsCommand):
parser
.
add_argument
(
'--database'
,
default
=
DEFAULT_DB_ALIAS
,
parser
.
add_argument
(
'--database'
,
default
=
DEFAULT_DB_ALIAS
,
help
=
'Nominates a database to synchronize. Defaults to the "default" database.'
)
help
=
'Nominates a database to synchronize. Defaults to the "default" database.'
)
def
handle
_noargs
(
self
,
**
options
):
def
handle
(
self
,
**
options
):
warnings
.
warn
(
"The syncdb command will be removed in Django 1.9"
,
RemovedInDjango19Warning
)
warnings
.
warn
(
"The syncdb command will be removed in Django 1.9"
,
RemovedInDjango19Warning
)
call_command
(
"migrate"
,
**
options
)
call_command
(
"migrate"
,
**
options
)
...
...
django/core/management/commands/validate.py
Dosyayı görüntüle @
9996158d
...
@@ -10,7 +10,7 @@ from django.utils.deprecation import RemovedInDjango19Warning
...
@@ -10,7 +10,7 @@ from django.utils.deprecation import RemovedInDjango19Warning
class
Command
(
CheckCommand
):
class
Command
(
CheckCommand
):
help
=
'Deprecated. Use "check" command instead. '
+
CheckCommand
.
help
help
=
'Deprecated. Use "check" command instead. '
+
CheckCommand
.
help
def
handle
_noargs
(
self
,
**
options
):
def
handle
(
self
,
**
options
):
warnings
.
warn
(
'"validate" has been deprecated in favor of "check".'
,
warnings
.
warn
(
'"validate" has been deprecated in favor of "check".'
,
RemovedInDjango19Warning
)
RemovedInDjango19Warning
)
super
(
Command
,
self
)
.
handle
_noargs
(
**
options
)
super
(
Command
,
self
)
.
handle
(
**
options
)
docs/howto/custom-management-commands.txt
Dosyayı görüntüle @
9996158d
...
@@ -152,8 +152,8 @@ require a system-neutral string language (for which we use 'en-us').
...
@@ -152,8 +152,8 @@ require a system-neutral string language (for which we use 'en-us').
If, for some reason, your custom management command needs to use a fixed locale
If, for some reason, your custom management command needs to use a fixed locale
different from 'en-us', you should manually activate and deactivate it in your
different from 'en-us', you should manually activate and deactivate it in your
:meth:`~BaseCommand.handle`
or :meth:`~NoArgsCommand.handle_noargs` method using
:meth:`~BaseCommand.handle`
method using the functions provided by the I18N
the functions provided by the I18N
support code:
support code:
.. code-block:: python
.. code-block:: python
...
@@ -431,6 +431,10 @@ Rather than implementing :meth:`~BaseCommand.handle`, subclasses must implement
...
@@ -431,6 +431,10 @@ Rather than implementing :meth:`~BaseCommand.handle`, subclasses must implement
.. class:: NoArgsCommand
.. class:: NoArgsCommand
.. deprecated:: 1.8
Use :class:`BaseCommand` instead, which takes no arguments by default.
A command which takes no arguments on the command line.
A command which takes no arguments on the command line.
Rather than implementing :meth:`~BaseCommand.handle`, subclasses must implement
Rather than implementing :meth:`~BaseCommand.handle`, subclasses must implement
...
...
docs/internals/deprecation.txt
Dosyayı görüntüle @
9996158d
...
@@ -38,6 +38,10 @@ about each item can often be found in the release notes of two versions prior.
...
@@ -38,6 +38,10 @@ about each item can often be found in the release notes of two versions prior.
* Support for :py:mod:`optparse` will be dropped for custom management commands
* Support for :py:mod:`optparse` will be dropped for custom management commands
(replaced by :py:mod:`argparse`).
(replaced by :py:mod:`argparse`).
* The class :class:`~django.core.management.NoArgsCommand` will be removed. Use
:class:`~django.core.management.BaseCommand` instead, which takes no arguments
by default.
.. _deprecation-removed-in-1.9:
.. _deprecation-removed-in-1.9:
1.9
1.9
...
...
docs/releases/1.8.txt
Dosyayı görüntüle @
9996158d
...
@@ -471,3 +471,10 @@ to add custom arguments to commands has changed: instead of extending the
...
@@ -471,3 +471,10 @@ to add custom arguments to commands has changed: instead of extending the
:meth:`~django.core.management.BaseCommand.add_arguments` method and add
:meth:`~django.core.management.BaseCommand.add_arguments` method and add
arguments through ``argparse.add_argument()``. See
arguments through ``argparse.add_argument()``. See
:ref:`this example <custom-commands-options>` for more details.
:ref:`this example <custom-commands-options>` for more details.
``django.core.management.NoArgsCommand``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The class :class:`~django.core.management.NoArgsCommand` is now deprecated and
will be removed in Django 2.0. Use :class:`~django.core.management.BaseCommand`
instead, which takes no arguments by default.
tests/admin_scripts/complex_app/management/commands/duplicate.py
Dosyayı görüntüle @
9996158d
from
django.core.management.base
import
NoArgs
Command
from
django.core.management.base
import
Base
Command
class
Command
(
NoArgs
Command
):
class
Command
(
Base
Command
):
def
handle
_noargs
(
self
,
**
options
):
def
handle
(
self
,
**
options
):
self
.
stdout
.
write
(
'complex_app'
)
self
.
stdout
.
write
(
'complex_app'
)
tests/admin_scripts/management/commands/color_command.py
Dosyayı görüntüle @
9996158d
from
django.core.management.base
import
NoArgs
Command
from
django.core.management.base
import
Base
Command
class
Command
(
NoArgs
Command
):
class
Command
(
Base
Command
):
help
=
"Test color output"
help
=
"Test color output"
requires_system_checks
=
False
requires_system_checks
=
False
def
handle
_noargs
(
self
,
**
options
):
def
handle
(
self
,
**
options
):
return
self
.
style
.
SQL_KEYWORD
(
'BEGIN'
)
return
self
.
style
.
SQL_KEYWORD
(
'BEGIN'
)
tests/admin_scripts/management/commands/noargs_command.py
Dosyayı görüntüle @
9996158d
from
django.core.management.base
import
NoArgs
Command
from
django.core.management.base
import
Base
Command
class
Command
(
NoArgs
Command
):
class
Command
(
Base
Command
):
help
=
"Test No-args commands"
help
=
"Test No-args commands"
requires_system_checks
=
False
requires_system_checks
=
False
def
handle
_noargs
(
self
,
**
options
):
def
handle
(
self
,
**
options
):
print
(
'EXECUTE:
NoArgsC
ommand options=
%
s'
%
sorted
(
options
.
items
()))
print
(
'EXECUTE:
noargs_c
ommand options=
%
s'
%
sorted
(
options
.
items
()))
tests/admin_scripts/management/commands/validation_command.py
Dosyayı görüntüle @
9996158d
from
django.core.management.base
import
NoArgs
Command
from
django.core.management.base
import
Base
Command
class
InvalidCommand
(
NoArgs
Command
):
class
InvalidCommand
(
Base
Command
):
help
=
(
"Test raising an error if both requires_system_checks "
help
=
(
"Test raising an error if both requires_system_checks "
"and requires_model_validation are defined."
)
"and requires_model_validation are defined."
)
requires_system_checks
=
True
requires_system_checks
=
True
requires_model_validation
=
True
requires_model_validation
=
True
def
handle
_noargs
(
self
,
**
options
):
def
handle
(
self
,
**
options
):
pass
pass
tests/admin_scripts/simple_app/management/commands/duplicate.py
Dosyayı görüntüle @
9996158d
from
django.core.management.base
import
NoArgs
Command
from
django.core.management.base
import
Base
Command
class
Command
(
NoArgs
Command
):
class
Command
(
Base
Command
):
def
handle
_noargs
(
self
,
**
options
):
def
handle
(
self
,
**
options
):
self
.
stdout
.
write
(
'simple_app'
)
self
.
stdout
.
write
(
'simple_app'
)
tests/admin_scripts/tests.py
Dosyayı görüntüle @
9996158d
...
@@ -282,14 +282,14 @@ class DjangoAdminDefaultSettings(AdminScriptTestCase):
...
@@ -282,14 +282,14 @@ class DjangoAdminDefaultSettings(AdminScriptTestCase):
args
=
[
'noargs_command'
,
'--settings=test_project.settings'
]
args
=
[
'noargs_command'
,
'--settings=test_project.settings'
]
out
,
err
=
self
.
run_django_admin
(
args
)
out
,
err
=
self
.
run_django_admin
(
args
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
def
test_custom_command_with_environment
(
self
):
def
test_custom_command_with_environment
(
self
):
"default: django-admin can execute user commands if settings are provided in environment"
"default: django-admin can execute user commands if settings are provided in environment"
args
=
[
'noargs_command'
]
args
=
[
'noargs_command'
]
out
,
err
=
self
.
run_django_admin
(
args
,
'test_project.settings'
)
out
,
err
=
self
.
run_django_admin
(
args
,
'test_project.settings'
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
class
DjangoAdminFullPathDefaultSettings
(
AdminScriptTestCase
):
class
DjangoAdminFullPathDefaultSettings
(
AdminScriptTestCase
):
...
@@ -349,14 +349,14 @@ class DjangoAdminFullPathDefaultSettings(AdminScriptTestCase):
...
@@ -349,14 +349,14 @@ class DjangoAdminFullPathDefaultSettings(AdminScriptTestCase):
args
=
[
'noargs_command'
,
'--settings=test_project.settings'
]
args
=
[
'noargs_command'
,
'--settings=test_project.settings'
]
out
,
err
=
self
.
run_django_admin
(
args
)
out
,
err
=
self
.
run_django_admin
(
args
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
def
test_custom_command_with_environment
(
self
):
def
test_custom_command_with_environment
(
self
):
"fulldefault: django-admin can execute user commands if settings are provided in environment"
"fulldefault: django-admin can execute user commands if settings are provided in environment"
args
=
[
'noargs_command'
]
args
=
[
'noargs_command'
]
out
,
err
=
self
.
run_django_admin
(
args
,
'test_project.settings'
)
out
,
err
=
self
.
run_django_admin
(
args
,
'test_project.settings'
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
class
DjangoAdminMinimalSettings
(
AdminScriptTestCase
):
class
DjangoAdminMinimalSettings
(
AdminScriptTestCase
):
...
@@ -483,14 +483,14 @@ class DjangoAdminAlternateSettings(AdminScriptTestCase):
...
@@ -483,14 +483,14 @@ class DjangoAdminAlternateSettings(AdminScriptTestCase):
args
=
[
'noargs_command'
,
'--settings=test_project.alternate_settings'
]
args
=
[
'noargs_command'
,
'--settings=test_project.alternate_settings'
]
out
,
err
=
self
.
run_django_admin
(
args
)
out
,
err
=
self
.
run_django_admin
(
args
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
def
test_custom_command_with_environment
(
self
):
def
test_custom_command_with_environment
(
self
):
"alternate: django-admin can execute user commands if settings are provided in environment"
"alternate: django-admin can execute user commands if settings are provided in environment"
args
=
[
'noargs_command'
]
args
=
[
'noargs_command'
]
out
,
err
=
self
.
run_django_admin
(
args
,
'test_project.alternate_settings'
)
out
,
err
=
self
.
run_django_admin
(
args
,
'test_project.alternate_settings'
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
class
DjangoAdminMultipleSettings
(
AdminScriptTestCase
):
class
DjangoAdminMultipleSettings
(
AdminScriptTestCase
):
...
@@ -553,14 +553,14 @@ class DjangoAdminMultipleSettings(AdminScriptTestCase):
...
@@ -553,14 +553,14 @@ class DjangoAdminMultipleSettings(AdminScriptTestCase):
args
=
[
'noargs_command'
,
'--settings=test_project.alternate_settings'
]
args
=
[
'noargs_command'
,
'--settings=test_project.alternate_settings'
]
out
,
err
=
self
.
run_django_admin
(
args
)
out
,
err
=
self
.
run_django_admin
(
args
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
def
test_custom_command_with_environment
(
self
):
def
test_custom_command_with_environment
(
self
):
"alternate: django-admin can execute user commands if settings are provided in environment"
"alternate: django-admin can execute user commands if settings are provided in environment"
args
=
[
'noargs_command'
]
args
=
[
'noargs_command'
]
out
,
err
=
self
.
run_django_admin
(
args
,
'test_project.alternate_settings'
)
out
,
err
=
self
.
run_django_admin
(
args
,
'test_project.alternate_settings'
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
class
DjangoAdminSettingsDirectory
(
AdminScriptTestCase
):
class
DjangoAdminSettingsDirectory
(
AdminScriptTestCase
):
...
@@ -718,21 +718,21 @@ class ManageDefaultSettings(AdminScriptTestCase):
...
@@ -718,21 +718,21 @@ class ManageDefaultSettings(AdminScriptTestCase):
args
=
[
'noargs_command'
]
args
=
[
'noargs_command'
]
out
,
err
=
self
.
run_manage
(
args
)
out
,
err
=
self
.
run_manage
(
args
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
def
test_custom_command_with_settings
(
self
):
def
test_custom_command_with_settings
(
self
):
"default: manage.py can execute user commands when settings are provided as argument"
"default: manage.py can execute user commands when settings are provided as argument"
args
=
[
'noargs_command'
,
'--settings=test_project.settings'
]
args
=
[
'noargs_command'
,
'--settings=test_project.settings'
]
out
,
err
=
self
.
run_manage
(
args
)
out
,
err
=
self
.
run_manage
(
args
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
def
test_custom_command_with_environment
(
self
):
def
test_custom_command_with_environment
(
self
):
"default: manage.py can execute user commands when settings are provided in environment"
"default: manage.py can execute user commands when settings are provided in environment"
args
=
[
'noargs_command'
]
args
=
[
'noargs_command'
]
out
,
err
=
self
.
run_manage
(
args
,
'test_project.settings'
)
out
,
err
=
self
.
run_manage
(
args
,
'test_project.settings'
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
class
ManageFullPathDefaultSettings
(
AdminScriptTestCase
):
class
ManageFullPathDefaultSettings
(
AdminScriptTestCase
):
...
@@ -785,21 +785,21 @@ class ManageFullPathDefaultSettings(AdminScriptTestCase):
...
@@ -785,21 +785,21 @@ class ManageFullPathDefaultSettings(AdminScriptTestCase):
args
=
[
'noargs_command'
]
args
=
[
'noargs_command'
]
out
,
err
=
self
.
run_manage
(
args
)
out
,
err
=
self
.
run_manage
(
args
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
def
test_custom_command_with_settings
(
self
):
def
test_custom_command_with_settings
(
self
):
"fulldefault: manage.py can execute user commands when settings are provided as argument"
"fulldefault: manage.py can execute user commands when settings are provided as argument"
args
=
[
'noargs_command'
,
'--settings=test_project.settings'
]
args
=
[
'noargs_command'
,
'--settings=test_project.settings'
]
out
,
err
=
self
.
run_manage
(
args
)
out
,
err
=
self
.
run_manage
(
args
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
def
test_custom_command_with_environment
(
self
):
def
test_custom_command_with_environment
(
self
):
"fulldefault: manage.py can execute user commands when settings are provided in environment"
"fulldefault: manage.py can execute user commands when settings are provided in environment"
args
=
[
'noargs_command'
]
args
=
[
'noargs_command'
]
out
,
err
=
self
.
run_manage
(
args
,
'test_project.settings'
)
out
,
err
=
self
.
run_manage
(
args
,
'test_project.settings'
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
class
ManageMinimalSettings
(
AdminScriptTestCase
):
class
ManageMinimalSettings
(
AdminScriptTestCase
):
...
@@ -929,21 +929,21 @@ class ManageAlternateSettings(AdminScriptTestCase):
...
@@ -929,21 +929,21 @@ class ManageAlternateSettings(AdminScriptTestCase):
"alternate: manage.py can execute user commands if settings are provided as argument"
"alternate: manage.py can execute user commands if settings are provided as argument"
args
=
[
'noargs_command'
,
'--settings=alternate_settings'
]
args
=
[
'noargs_command'
,
'--settings=alternate_settings'
]
out
,
err
=
self
.
run_manage
(
args
)
out
,
err
=
self
.
run_manage
(
args
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand options=[('no_color', False), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', False), ('verbosity', 1)]"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand options=[('no_color', False), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', False), ('verbosity', 1)]"
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
def
test_custom_command_with_environment
(
self
):
def
test_custom_command_with_environment
(
self
):
"alternate: manage.py can execute user commands if settings are provided in environment"
"alternate: manage.py can execute user commands if settings are provided in environment"
args
=
[
'noargs_command'
]
args
=
[
'noargs_command'
]
out
,
err
=
self
.
run_manage
(
args
,
'alternate_settings'
)
out
,
err
=
self
.
run_manage
(
args
,
'alternate_settings'
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand options=[('no_color', False), ('pythonpath', None), ('settings', None), ('traceback', False), ('verbosity', 1)]"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand options=[('no_color', False), ('pythonpath', None), ('settings', None), ('traceback', False), ('verbosity', 1)]"
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
def
test_custom_command_output_color
(
self
):
def
test_custom_command_output_color
(
self
):
"alternate: manage.py output syntax color can be deactivated with the `--no-color` option"
"alternate: manage.py output syntax color can be deactivated with the `--no-color` option"
args
=
[
'noargs_command'
,
'--no-color'
,
'--settings=alternate_settings'
]
args
=
[
'noargs_command'
,
'--no-color'
,
'--settings=alternate_settings'
]
out
,
err
=
self
.
run_manage
(
args
)
out
,
err
=
self
.
run_manage
(
args
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand options=[('no_color', True), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', False), ('verbosity', 1)]"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand options=[('no_color', True), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', False), ('verbosity', 1)]"
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
...
@@ -1008,14 +1008,14 @@ class ManageMultipleSettings(AdminScriptTestCase):
...
@@ -1008,14 +1008,14 @@ class ManageMultipleSettings(AdminScriptTestCase):
args
=
[
'noargs_command'
,
'--settings=alternate_settings'
]
args
=
[
'noargs_command'
,
'--settings=alternate_settings'
]
out
,
err
=
self
.
run_manage
(
args
)
out
,
err
=
self
.
run_manage
(
args
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
def
test_custom_command_with_environment
(
self
):
def
test_custom_command_with_environment
(
self
):
"multiple: manage.py can execute user commands if settings are provided in environment"
"multiple: manage.py can execute user commands if settings are provided in environment"
args
=
[
'noargs_command'
]
args
=
[
'noargs_command'
]
out
,
err
=
self
.
run_manage
(
args
,
'alternate_settings'
)
out
,
err
=
self
.
run_manage
(
args
,
'alternate_settings'
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand"
)
class
ManageSettingsWithSettingsErrors
(
AdminScriptTestCase
):
class
ManageSettingsWithSettingsErrors
(
AdminScriptTestCase
):
...
@@ -1496,7 +1496,7 @@ class CommandTypes(AdminScriptTestCase):
...
@@ -1496,7 +1496,7 @@ class CommandTypes(AdminScriptTestCase):
args
=
[
'noargs_command'
]
args
=
[
'noargs_command'
]
out
,
err
=
self
.
run_manage
(
args
)
out
,
err
=
self
.
run_manage
(
args
)
self
.
assertNoOutput
(
err
)
self
.
assertNoOutput
(
err
)
self
.
assertOutput
(
out
,
"EXECUTE:
NoArgsC
ommand options=[('no_color', False), ('pythonpath', None), ('settings', None), ('traceback', False), ('verbosity', 1)]"
)
self
.
assertOutput
(
out
,
"EXECUTE:
noargs_c
ommand options=[('no_color', False), ('pythonpath', None), ('settings', None), ('traceback', False), ('verbosity', 1)]"
)
def
test_noargs_with_args
(
self
):
def
test_noargs_with_args
(
self
):
"NoArg Commands raise an error if an argument is provided"
"NoArg Commands raise an error if an argument is provided"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment