Changeset 6095
- Timestamp:
- 09/11/07 06:46:34 (1 year ago)
- Files:
-
- django/branches/newforms-admin (modified) (1 prop)
- django/branches/newforms-admin/django/core/management/base.py (modified) (3 diffs)
- django/branches/newforms-admin/django/core/management/commands/runfcgi.py (modified) (1 diff)
- django/branches/newforms-admin/django/core/management/__init__.py (modified) (8 diffs)
- django/branches/newforms-admin/django/db/models/loading.py (modified) (1 diff)
- django/branches/newforms-admin/docs/contributing.txt (modified) (1 diff)
- django/branches/newforms-admin/tests/regressiontests/forms/regressions.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/newforms-admin
- Property svnmerge-integrated changed from /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6081 to /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6094
django/branches/newforms-admin/django/core/management/base.py
r6082 r6095 6 6 import sys 7 7 import os 8 from traceback import print_exc9 8 10 9 class CommandError(Exception): … … 37 36 return django.get_version() 38 37 39 def usage(self ):40 usage = '% prog [options] ' + self.args38 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) … … 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(arg s[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): django/branches/newforms-admin/django/core/management/commands/runfcgi.py
r6082 r6095 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 django/branches/newforms-admin/django/core/management/__init__.py
r6082 r6095 3 3 import os 4 4 import sys 5 import textwrap6 5 7 6 # For backwards compatibility: get_version() used to be in this module. … … 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 … … 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() … … 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 … … 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 parser85 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.argv89 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 s elf.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): … … 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 … … 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): … … 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() django/branches/newforms-admin/django/db/models/loading.py
r5984 r6095 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: django/branches/newforms-admin/docs/contributing.txt
r6082 r6095 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 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. 419 457 420 458 Guidelines for ReST files django/branches/newforms-admin/tests/regressiontests/forms/regressions.py
r5918 r6095 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 that82 doesn't come back.83 >>> class DataForm(Form):84 ... data = CharField(max_length=10)85 >>> f = DataForm({'data': 'xyzzy'})86 >>> f.is_valid()87 True88 >>> f.cleaned_data89 {'data': u'xyzzy'}90 76 """
