Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Factored out django.core.management ACTION_MAPPING into DEFAULT_ACTIO…

…N_MAPPING, so execute_from_command_line now takes an action_mapping parameter (DEFAULT_ACTION_MAPPING by default)

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1554 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 50cac9d276471abc330efdba5d101c78d44928bc 1 parent 6d210ef
Adrian Holovaty authored December 06, 2005

Showing 1 changed file with 15 additions and 15 deletions. Show diff stats Hide diff stats

  1. 30  django/core/management.py
30  django/core/management.py
@@ -816,7 +816,7 @@ def createcachetable(tablename):
816 816
 
817 817
 # Utilities for command-line script
818 818
 
819  
-ACTION_MAPPING = {
  819
+DEFAULT_ACTION_MAPPING = {
820 820
     'adminindex': get_admin_index,
821 821
     'createsuperuser': createsuperuser,
822 822
     'createcachetable' : createcachetable,
@@ -845,16 +845,16 @@ def print_usage_and_exit(self):
845 845
         self.print_help(sys.stderr)
846 846
         sys.exit(1)
847 847
 
848  
-def get_usage():
  848
+def get_usage(action_mapping):
849 849
     """
850 850
     Returns a usage string. Doesn't do the options stuff, because optparse
851 851
     takes care of that.
852 852
     """
853 853
     usage = ["usage: %prog action [options]\nactions:"]
854  
-    available_actions = ACTION_MAPPING.keys()
  854
+    available_actions = action_mapping.keys()
855 855
     available_actions.sort()
856 856
     for a in available_actions:
857  
-        func = ACTION_MAPPING[a]
  857
+        func = action_mapping[a]
858 858
         usage.append("  %s %s" % (a, func.args))
859 859
         usage.extend(textwrap.wrap(getattr(func, 'help_doc', func.__doc__), initial_indent='    ', subsequent_indent='    '))
860 860
         usage.append("")
@@ -864,9 +864,9 @@ def print_error(msg, cmd):
864 864
     sys.stderr.write('Error: %s\nRun "%s --help" for help.\n' % (msg, cmd))
865 865
     sys.exit(1)
866 866
 
867  
-def execute_from_command_line():
  867
+def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING):
868 868
     # Parse the command-line arguments. optparse handles the dirty work.
869  
-    parser = DjangoOptionParser(get_usage())
  869
+    parser = DjangoOptionParser(get_usage(action_mapping))
870 870
     parser.add_option('--settings',
871 871
         help='Python path to settings module, e.g. "myproject.settings.main". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.')
872 872
     parser.add_option('--pythonpath',
@@ -885,7 +885,7 @@ def execute_from_command_line():
885 885
         action = args[0]
886 886
     except IndexError:
887 887
         parser.print_usage_and_exit()
888  
-    if not ACTION_MAPPING.has_key(action):
  888
+    if not action_mapping.has_key(action):
889 889
         print_error("Your action, %r, was invalid." % action, sys.argv[0])
890 890
 
891 891
     # switch to english, because django-admin creates database content
@@ -900,28 +900,28 @@ def execute_from_command_line():
900 900
             username, email, password = args[1], args[2], args[3]
901 901
         except IndexError:
902 902
             if len(args) == 1: # We got no arguments, just the action.
903  
-                ACTION_MAPPING[action]()
  903
+                action_mapping[action]()
904 904
             else:
905 905
                 sys.stderr.write("Error: %r requires arguments of 'username email password' or no argument at all.\n")
906 906
                 sys.exit(1)
907 907
         else:
908  
-            ACTION_MAPPING[action](username, email, password)
  908
+            action_mapping[action](username, email, password)
909 909
     elif action in ('init', 'validate'):
910  
-        ACTION_MAPPING[action]()
  910
+        action_mapping[action]()
911 911
     elif action == 'inspectdb':
912 912
         try:
913 913
             param = args[1]
914 914
         except IndexError:
915 915
             parser.print_usage_and_exit()
916 916
         try:
917  
-            for line in ACTION_MAPPING[action](param):
  917
+            for line in action_mapping[action](param):
918 918
                 print line
919 919
         except NotImplementedError:
920 920
             sys.stderr.write("Error: %r isn't supported for the currently selected database backend.\n" % action)
921 921
             sys.exit(1)
922 922
     elif action == 'createcachetable':
923 923
         try:
924  
-            ACTION_MAPPING[action](args[1])
  924
+            action_mapping[action](args[1])
925 925
         except IndexError:
926 926
             parser.print_usage_and_exit()
927 927
     elif action in ('startapp', 'startproject'):
@@ -929,7 +929,7 @@ def execute_from_command_line():
929 929
             name = args[1]
930 930
         except IndexError:
931 931
             parser.print_usage_and_exit()
932  
-        ACTION_MAPPING[action](name, os.getcwd())
  932
+        action_mapping[action](name, os.getcwd())
933 933
     elif action == 'runserver':
934 934
         if len(args) < 2:
935 935
             addr = ''
@@ -939,7 +939,7 @@ def execute_from_command_line():
939 939
                 addr, port = args[1].split(':')
940 940
             except ValueError:
941 941
                 addr, port = '', args[1]
942  
-        ACTION_MAPPING[action](addr, port)
  942
+        action_mapping[action](addr, port)
943 943
     else:
944 944
         from django.core import meta
945 945
         if action == 'dbcheck':
@@ -955,7 +955,7 @@ def execute_from_command_line():
955 955
         if action not in NO_SQL_TRANSACTION:
956 956
             print "BEGIN;"
957 957
         for mod in mod_list:
958  
-            output = ACTION_MAPPING[action](mod)
  958
+            output = action_mapping[action](mod)
959 959
             if output:
960 960
                 print '\n'.join(output)
961 961
         if action not in NO_SQL_TRANSACTION:

0 notes on commit 50cac9d

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