| 1 | #!/usr/bin/env python
|
|---|
| 2 |
|
|---|
| 3 | # Import things we need because we duplicated execute_manager
|
|---|
| 4 | from django.core.management import stuff...
|
|---|
| 5 |
|
|---|
| 6 | try:
|
|---|
| 7 | import settings # Assumed to be in the same directory.
|
|---|
| 8 | except ImportError:
|
|---|
| 9 | import sys
|
|---|
| 10 | sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
|
|---|
| 11 | sys.exit(1)
|
|---|
| 12 |
|
|---|
| 13 | # inline because this is dpaste
|
|---|
| 14 | def twiddle(app):
|
|---|
| 15 | print 'Twiddle the frotz!'
|
|---|
| 16 |
|
|---|
| 17 | def execute_manager(settings_mod, argv=None):
|
|---|
| 18 | project_directory = setup_environ(settings_mod)
|
|---|
| 19 | action_mapping = DEFAULT_ACTION_MAPPING.copy()
|
|---|
| 20 |
|
|---|
| 21 | # Remove the "startproject" command from the action_mapping, because that's
|
|---|
| 22 | # a django-admin.py command, not a manage.py command.
|
|---|
| 23 | del action_mapping['startproject']
|
|---|
| 24 |
|
|---|
| 25 | # Override the startapp handler so that it always uses the
|
|---|
| 26 | # project_directory, not the current working directory (which is default).
|
|---|
| 27 | action_mapping['startapp'] = lambda app_name, directory: startapp(app_name, project_directory)
|
|---|
| 28 | action_mapping['startapp'].__doc__ = startapp.__doc__
|
|---|
| 29 | action_mapping['startapp'].help_doc = startapp.help_doc
|
|---|
| 30 | action_mapping['startapp'].args = startapp.args
|
|---|
| 31 |
|
|---|
| 32 | # CUSTOM ACTION MAPPINGS
|
|---|
| 33 | action_mapping['twiddle'] = twiddle
|
|---|
| 34 |
|
|---|
| 35 | # Run the django-admin.py command.
|
|---|
| 36 | execute_from_command_line(action_mapping, argv)
|
|---|
| 37 |
|
|---|
| 38 | if __name__ == "__main__":
|
|---|
| 39 | execute_manager(settings)
|
|---|