Django

Code

Changeset 8768

Show
Ignore:
Timestamp:
08/31/08 13:21:06 (4 months ago)
Author:
mtredinnick
Message:

Fixed #8703 -- Allow deeply nested import paths for DJANGO_SETTINGS_MODULE when
running django-admin.py. Also adds a parameter to setup_environ() for others to
use as well.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management/__init__.py

    r8425 r8768  
    4040    part = parts.pop() 
    4141    path = None 
    42      
     42 
    4343    # When using manage.py, the project module is added to the path, 
    44     # loaded, then removed from the path. This means that  
     44    # loaded, then removed from the path. This means that 
    4545    # testproject.testapp.models can be loaded in future, even if 
    4646    # testproject isn't in the path. When looking for the management 
     
    5252        if os.path.basename(os.getcwd()) != part: 
    5353            raise e 
    54          
     54 
    5555    while parts: 
    5656        part = parts.pop() 
     
    107107            project_directory = setup_environ( 
    108108                __import__( 
    109                     settings.SETTINGS_MODULE, {}, {},  
     109                    settings.SETTINGS_MODULE, {}, {}, 
    110110                    (settings.SETTINGS_MODULE.split(".")[-1],) 
    111                 ) 
     111                ), settings.SETTINGS_MODULE 
    112112            ) 
    113113        except (AttributeError, EnvironmentError, ImportError): 
     
    167167    def error(self, msg): 
    168168        pass 
    169      
     169 
    170170    def print_help(self): 
    171171        """Output nothing. 
    172          
     172 
    173173        The lax options are included in the normal option parser, so under 
    174174        normal usage, we don't need to print the lax options. 
    175175        """ 
    176176        pass 
    177      
     177 
    178178    def print_lax_help(self): 
    179179        """Output the basic options available to every command. 
    180          
     180 
    181181        This just redirects to the default print_help() behaviour. 
    182182        """ 
    183183        OptionParser.print_help(self) 
    184          
     184 
    185185    def _process_args(self, largs, rargs, values): 
    186186        """ 
    187187        Overrides OptionParser._process_args to exclusively handle default 
    188         options and ignore args and other options.  
    189          
    190         This overrides the behavior of the super class, which stop parsing  
     188        options and ignore args and other options. 
     189 
     190        This overrides the behavior of the super class, which stop parsing 
    191191        at the first unrecognized option. 
    192192        """ 
     
    263263        # must be processed early. 
    264264        parser = LaxOptionParser(usage="%prog subcommand [options] [args]", 
    265                                  version=get_version(),  
     265                                 version=get_version(), 
    266266                                 option_list=BaseCommand.option_list) 
    267267        try: 
     
    295295            self.fetch_command(subcommand).run_from_argv(self.argv) 
    296296 
    297 def setup_environ(settings_mod): 
     297def setup_environ(settings_mod, original_settings_path=None): 
    298298    """ 
    299299    Configures the runtime environment. This can also be used by external 
     
    301301    Returns the project directory (assuming the passed settings module is 
    302302    directly in the project directory). 
     303 
     304    The "original_settings_path" parameter is optional, but recommended, since 
     305    trying to work out the original path from the module can be problematic. 
    303306    """ 
    304307    # Add this project to sys.path so that it's importable in the conventional 
     
    315318 
    316319    # Set DJANGO_SETTINGS_MODULE appropriately. 
    317     os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name) 
     320    if original_settings_path: 
     321        os.environ['DJANGO_SETTINGS_MODULE'] = original_settings_path 
     322    else: 
     323        os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name) 
    318324    return project_directory 
    319325