| | 963 | |
|---|
| | 964 | def execute_manager(settings_mod): |
|---|
| | 965 | # Add this project to sys.path so that it's importable in the conventional |
|---|
| | 966 | # way. For example, if this file (manage.py) lives in a directory |
|---|
| | 967 | # "myproject", this code would add "/path/to/myproject" to sys.path. |
|---|
| | 968 | project_directory = os.path.dirname(settings_mod.__file__) |
|---|
| | 969 | project_name = os.path.basename(project_directory) |
|---|
| | 970 | sys.path.append(os.path.join(project_directory, '..')) |
|---|
| | 971 | project_module = __import__(project_name, '', '', ['']) |
|---|
| | 972 | sys.path.pop() |
|---|
| | 973 | |
|---|
| | 974 | # Set DJANGO_SETTINGS_MODULE appropriately. |
|---|
| | 975 | os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % project_name |
|---|
| | 976 | |
|---|
| | 977 | # Remove the "startproject" command from the action_mapping, because that's |
|---|
| | 978 | # a django-admin.py command, not a manage.py command. |
|---|
| | 979 | action_mapping = DEFAULT_ACTION_MAPPING.copy() |
|---|
| | 980 | del action_mapping['startproject'] |
|---|
| | 981 | |
|---|
| | 982 | # Run the django-admin.py command. |
|---|
| | 983 | execute_from_command_line(action_mapping) |
|---|