c1c401f1f55c5d6ffef6287a34c1e2e4bb2e72f8
5 from django
.core
import management
8 def main(settings_file
):
10 mod
= __import__(settings_file
)
11 components
= settings_file
.split('.')
12 for comp
in components
[1:]:
13 mod
= getattr(mod
, comp
)
15 except ImportError, e
:
17 sys
.stderr
.write("Error loading the settings module '%s': %s"
21 management
.execute_manager(mod
)
23 # Fix pour le ticket Django #14087 (https://code.djangoproject.com/ticket/14087)
24 # On applique le patch https://code.djangoproject.com/attachment/ticket/14087/namespace_package_pth.diff
25 # par monkey patching.
27 def find_modules(name
, path
=None):
28 """Find all modules with name 'name'
30 Unlike find_module in the imp package this returns a list of all
34 if path
is None: path
= sys
.path
36 importer
= sys
.path_importer_cache
.get(p
, None)
38 find_module
= imp
.find_module
40 find_module
= importer
.find_module
43 result
= find_module(name
, [p
])
44 if result
is not None:
45 results
.append(result
)
49 raise ImportError("No module named %.200s" % name
)
52 def find_management_module(app_name
):
54 Determines the path to the management module for the given app_name,
55 without actually importing the application or the management module.
57 Raises ImportError if the management module cannot be found for any reason.
59 parts
= app_name
.split('.')
61 for i
in range(len(parts
), 0, -1):
63 paths
= sys
.modules
['.'.join(parts
[:i
])].__path__
67 parts
= parts
[i
:] + ['management']
71 parts
.append('management')
76 # When using manage.py, the project module is added to the path,
77 # loaded, then removed from the path. This means that
78 # testproject.testapp.models can be loaded in future, even if
79 # testproject isn't in the path. When looking for the management
80 # module, we need look for the case where the project name is part
81 # of the app_name but the project directory itself isn't on the path.
83 modules
= find_modules(part
, paths
)
84 paths
= [m
[1] for m
in modules
if isinstance(m
, tuple)]
86 if os
.path
.basename(os
.getcwd()) != part
:
91 modules
= find_modules(part
, paths
)
92 paths
= [m
[1] for m
in modules
]
96 management
.find_management_module
= find_management_module