Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

newforms-admin: Merged to [6094]

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6095 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f892464d58c4029e71f4ee0b4df08a724004d4eb 1 parent 52578a1
Russell Keith-Magee authored September 11, 2007
61  django/core/management/__init__.py
@@ -2,7 +2,6 @@
2 2
 from optparse import OptionParser
3 3
 import os
4 4
 import sys
5  
-import textwrap
6 5
 
7 6
 # For backwards compatibility: get_version() used to be in this module.
8 7
 get_version = django.get_version
@@ -36,7 +35,9 @@ class ManagementUtility(object):
36 35
     A ManagementUtility has a number of commands, which can be manipulated
37 36
     by editing the self.commands dictionary.
38 37
     """
39  
-    def __init__(self):
  38
+    def __init__(self, argv=None):
  39
+        self.argv = argv or sys.argv[:]
  40
+        self.prog_name = os.path.basename(self.argv[0])
40 41
         self.commands = self.default_commands()
41 42
 
42 43
     def default_commands(self):
@@ -52,22 +53,21 @@ def default_commands(self):
52 53
         names = [f[:-3] for f in os.listdir(command_dir) if not f.startswith('_') and f.endswith('.py')]
53 54
         return dict([(name, load_command_class(name)) for name in names])
54 55
 
55  
-    def print_help(self, argv):
  56
+    def main_help_text(self):
56 57
         """
57  
-        Returns the help message, as a string.
  58
+        Returns the script's main help text, as a string.
58 59
         """
59  
-        prog_name = os.path.basename(argv[0])
60  
-        usage = ['%s <subcommand> [options] [args]' % prog_name]
  60
+        usage = ['%s <subcommand> [options] [args]' % self.prog_name]
61 61
         usage.append('Django command line tool, version %s' % django.get_version())
62  
-        usage.append("Type '%s help <subcommand>' for help on a specific subcommand." % prog_name)
  62
+        usage.append("Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name)
63 63
         usage.append('Available subcommands:')
64 64
         commands = self.commands.keys()
65 65
         commands.sort()
66 66
         for cmd in commands:
67 67
             usage.append('  %s' % cmd)
68  
-        print '\n'.join(usage)
  68
+        return '\n'.join(usage)
69 69
 
70  
-    def fetch_command(self, subcommand, command_name):
  70
+    def fetch_command(self, subcommand):
71 71
         """
72 72
         Tries to fetch the given subcommand, printing a message with the
73 73
         appropriate command called from the command line (usually
@@ -76,35 +76,34 @@ def fetch_command(self, subcommand, command_name):
76 76
         try:
77 77
             return self.commands[subcommand]
78 78
         except KeyError:
79  
-            sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" % (subcommand, command_name))
  79
+            sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" % (subcommand, self.prog_name))
80 80
             sys.exit(1)
81 81
 
82  
-    def execute(self, argv=None):
  82
+    def execute(self):
83 83
         """
84  
-        Figures out which command is being run (the first arg), creates a parser
85  
-        appropriate to that command, and runs it.
  84
+        Given the command-line arguments, this figures out which subcommand is
  85
+        being run, creates a parser appropriate to that command, and runs it.
86 86
         """
87  
-        if argv is None:
88  
-            argv = sys.argv
89 87
         try:
90  
-            command_name = argv[1]
  88
+            subcommand = self.argv[1]
91 89
         except IndexError:
92  
-            sys.stderr.write("Type '%s help' for usage.\n" % os.path.basename(argv[0]))
  90
+            sys.stderr.write("Type '%s help' for usage.\n" % self.prog_name)
93 91
             sys.exit(1)
94 92
 
95  
-        if command_name == 'help':
96  
-            if len(argv) > 2:
97  
-                self.fetch_command(argv[2], argv[0]).print_help(argv[2:])
  93
+        if subcommand == 'help':
  94
+            if len(self.argv) > 2:
  95
+                self.fetch_command(self.argv[2]).print_help(self.prog_name, self.argv[2])
98 96
             else:
99  
-                self.print_help(argv)
  97
+                sys.stderr.write(self.main_help_text() + '\n')
  98
+                sys.exit(1)
100 99
         # Special-cases: We want 'django-admin.py --version' and
101 100
         # 'django-admin.py --help' to work, for backwards compatibility.
102  
-        elif argv[1:] == ['--version']:
  101
+        elif self.argv[1:] == ['--version']:
103 102
             print django.get_version()
104  
-        elif argv[1:] == ['--help']:
105  
-            self.print_help(argv)
  103
+        elif self.argv[1:] == ['--help']:
  104
+            sys.stderr.write(self.main_help_text() + '\n')
106 105
         else:
107  
-            self.fetch_command(command_name, argv[0]).run(argv[1:])
  106
+            self.fetch_command(subcommand).run_from_argv(self.argv)
108 107
 
109 108
 class ProjectManagementUtility(ManagementUtility):
110 109
     """
@@ -115,8 +114,8 @@ class ProjectManagementUtility(ManagementUtility):
115 114
     In practice, this class represents manage.py, whereas ManagementUtility
116 115
     represents django-admin.py.
117 116
     """
118  
-    def __init__(self, project_directory):
119  
-        super(ProjectManagementUtility, self).__init__()
  117
+    def __init__(self, argv, project_directory):
  118
+        super(ProjectManagementUtility, self).__init__(argv)
120 119
 
121 120
         # Remove the "startproject" command from self.commands, because
122 121
         # that's a django-admin.py command, not a manage.py command.
@@ -150,8 +149,8 @@ def execute_from_command_line(argv=None):
150 149
     """
151 150
     A simple method that runs a ManagementUtility.
152 151
     """
153  
-    utility = ManagementUtility()
154  
-    utility.execute(argv)
  152
+    utility = ManagementUtility(argv)
  153
+    utility.execute()
155 154
 
156 155
 def execute_manager(settings_mod, argv=None):
157 156
     """
@@ -159,5 +158,5 @@ def execute_manager(settings_mod, argv=None):
159 158
     project-specific django-admin.py utility.
160 159
     """
161 160
     project_directory = setup_environ(settings_mod)
162  
-    utility = ProjectManagementUtility(project_directory)
163  
-    utility.execute(argv)
  161
+    utility = ProjectManagementUtility(argv, project_directory)
  162
+    utility.execute()
25  django/core/management/base.py
@@ -5,7 +5,6 @@
5 5
 from optparse import make_option, OptionParser
6 6
 import sys
7 7
 import os
8  
-from traceback import print_exc
9 8
 
10 9
 class CommandError(Exception):
11 10
     pass
@@ -36,35 +35,31 @@ def get_version(self):
36 35
         """
37 36
         return django.get_version()
38 37
 
39  
-    def usage(self):
40  
-        usage = '%prog [options] ' + self.args
  38
+    def usage(self, subcommand):
  39
+        usage = '%%prog %s [options] %s' % (subcommand, self.args)
41 40
         if self.help:
42 41
             return '%s\n\n%s' % (usage, self.help)
43 42
         else:
44 43
             return usage
45 44
 
46  
-    def create_parser(self, prog_name):
  45
+    def create_parser(self, prog_name, subcommand):
47 46
         return OptionParser(prog=prog_name,
48  
-                            usage=self.usage(),
  47
+                            usage=self.usage(subcommand),
49 48
                             version=self.get_version(),
50 49
                             option_list=self.option_list)
51 50
 
52  
-    def print_help(self, args):
53  
-        parser = self.create_parser(args[0])
  51
+    def print_help(self, prog_name, subcommand):
  52
+        parser = self.create_parser(prog_name, subcommand)
54 53
         parser.print_help()
55 54
 
56  
-    def run(self, args):
57  
-        parser = self.create_parser(args[0])
58  
-        (options, args) = parser.parse_args(args[1:])
  55
+    def run_from_argv(self, argv):
  56
+        parser = self.create_parser(argv[0], argv[1])
  57
+        options, args = parser.parse_args(argv[2:])
59 58
         if options.settings:
60 59
             os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
61 60
         if options.pythonpath:
62 61
             sys.path.insert(0, options.pythonpath)
63  
-        try:
64  
-            self.execute(*args, **options.__dict__)
65  
-        except Exception, e:
66  
-            print_exc()
67  
-            parser.print_usage()
  62
+        self.execute(*args, **options.__dict__)
68 63
 
69 64
     def execute(self, *args, **options):
70 65
         # Switch to English, because django-admin.py creates database content
2  django/core/management/commands/runfcgi.py
@@ -15,6 +15,6 @@ def handle(self, *args, **options):
15 15
         from django.core.servers.fastcgi import runfastcgi
16 16
         runfastcgi(args)
17 17
         
18  
-    def usage(self):
  18
+    def usage(self, subcommand):
19 19
         from django.core.servers.fastcgi import FASTCGI_HELP
20 20
         return FASTCGI_HELP
6  django/db/models/loading.py
@@ -52,11 +52,7 @@ def _populate(self):
52 52
             for app_name in settings.INSTALLED_APPS:
53 53
                 if app_name in self.handled:
54 54
                     continue
55  
-                try:
56  
-                    self.load_app(app_name, True)
57  
-                except Exception, e:
58  
-                    # Problem importing the app
59  
-                    self.app_errors[app_name] = e
  55
+                self.load_app(app_name, True)
60 56
             if not self.nesting_level:
61 57
                 for app_name in self.postponed:
62 58
                     self.load_app(app_name)
38  docs/contributing.txt
@@ -417,6 +417,44 @@ Documentation style
417 417
 We place a high importance on consistency and readability of documentation.
418 418
 (After all, Django was created in a journalism environment!)
419 419
 
  420
+How to document new features
  421
+----------------------------
  422
+
  423
+We treat our documentation like we treat our code: we aim to improve it as
  424
+often as possible. This section explains how writers can craft their
  425
+documentation changes in the most useful and least error-prone ways.
  426
+
  427
+Documentation changes come in two forms:
  428
+
  429
+    * General improvements -- Typo corrections, error fixes and better
  430
+      explanations through clearer writing and more examples.
  431
+
  432
+    * New features -- Documentation of features that have been added to the
  433
+      framework since the last release.
  434
+
  435
+Our philosophy is that "general improvements" are something that *all* current
  436
+Django users should benefit from, including users of trunk *and* users of the
  437
+latest release. Hence, the documentation section on djangoproject.com points
  438
+people by default to the newest versions of the docs, because they have the
  439
+latest and greatest content. (In fact, the Web site pulls directly from the
  440
+Subversion repository, converting to HTML on the fly.)
  441
+
  442
+But this decision to feature bleeding-edge documentation has one large caveat:
  443
+any documentation of *new* features will be seen by Django users who don't
  444
+necessarily have access to those features yet, because they're only using the
  445
+latest release. Thus, our policy is:
  446
+
  447
+    **All documentation of new features should be written in a way that clearly
  448
+    designates the features are only available in the Django development
  449
+    version. Assume documentation readers are using the latest release, not the
  450
+    development version.**
  451
+
  452
+Our traditional way of marking new features is by prefacing the features'
  453
+documentation with: "New in Django development version." Changes aren't
  454
+*required* to include this exact text, but all documentation of new features
  455
+should include the phrase "development version," so we can find and remove
  456
+those phrases for the next release.
  457
+
420 458
 Guidelines for ReST files
421 459
 -------------------------
422 460
 
14  tests/regressiontests/forms/regressions.py
@@ -73,18 +73,4 @@
73 73
 True
74 74
 >>> f.cleaned_data
75 75
 {'data': u'xyzzy'}
76  
-
77  
-#######################
78  
-# Miscellaneous Tests #
79  
-#######################
80  
-
81  
-There once was a problem with Form fields called "data". Let's make sure that
82  
-doesn't come back.
83  
->>> class DataForm(Form):
84  
-...     data = CharField(max_length=10)
85  
->>> f = DataForm({'data': 'xyzzy'})
86  
->>> f.is_valid()
87  
-True
88  
->>> f.cleaned_data
89  
-{'data': u'xyzzy'}
90 76
 """

0 notes on commit f892464

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