Skip to content
Browse files

Small refactoring of to allow a custom argv to…

… be passed into execute_manager(). This makes custom manage scripts with extra options possible

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 643c7b2 commit 55b6559b0e4a611f52814ef3c2c7e5329dbb4aff @jacobian jacobian committed
Showing with 9 additions and 5 deletions.
  1. +9 −5 django/core/
14 django/core/
@@ -1139,7 +1139,11 @@ def print_error(msg, cmd):
sys.stderr.write(style.ERROR('Error: %s' % msg) + '\nRun "%s --help" for help.\n' % cmd)
-def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING):
+def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
+ # Use sys.argv if we've not passed in a custom argv
+ if argv is None:
+ argv = sys.argv
# Parse the command-line arguments. optparse handles the dirty work.
parser = DjangoOptionParser(usage=get_usage(action_mapping), version=get_version())
@@ -1148,7 +1152,7 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING):
help='Lets you manually add a directory the Python path, e.g. "/home/djangoprojects/myproject".')
parser.add_option('--plain', action='store_true', dest='plain',
help='Tells Django to use plain Python, not IPython, for "shell" command.')
- options, args = parser.parse_args()
+ options, args = parser.parse_args(argv)
# Take care of options.
if options.settings:
@@ -1163,7 +1167,7 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING):
except IndexError:
if not action_mapping.has_key(action):
- print_error("Your action, %r, was invalid." % action, sys.argv[0])
+ print_error("Your action, %r, was invalid." % action, argv[0])
# Switch to English, because creates database content
# like permissions, and those shouldn't contain any translations.
@@ -1222,7 +1226,7 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING):
if action not in NO_SQL_TRANSACTION:
print style.SQL_KEYWORD("COMMIT;")
-def execute_manager(settings_mod):
+def execute_manager(settings_mod, argv=None):
# Add this project to sys.path so that it's importable in the conventional
# way. For example, if this file ( lives in a directory
# "myproject", this code would add "/path/to/myproject" to sys.path.
@@ -1249,4 +1253,4 @@ def execute_manager(settings_mod):
action_mapping['startapp'].args = startapp.args
# Run the command.
- execute_from_command_line(action_mapping)
+ execute_from_command_line(action_mapping, argv)

0 comments on commit 55b6559

Please sign in to comment.
Something went wrong with that request. Please try again.